.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * skl-pcm.c -ASoC HDA Platform driver file implementing PCM functionality |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * |
---|
7 | 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
8 | 9 | * |
---|
9 | | - * This program is free software; you can redistribute it and/or modify |
---|
10 | | - * it under the terms of the GNU General Public License as published by |
---|
11 | | - * the Free Software Foundation; version 2 of the License. |
---|
12 | | - * |
---|
13 | | - * This program is distributed in the hope that it will be useful, but |
---|
14 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | | - * General Public License for more details. |
---|
17 | | - * |
---|
18 | 10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
19 | | - * |
---|
20 | 11 | */ |
---|
21 | 12 | |
---|
22 | 13 | #include <linux/pci.h> |
---|
.. | .. |
---|
32 | 23 | #define HDA_MONO 1 |
---|
33 | 24 | #define HDA_STEREO 2 |
---|
34 | 25 | #define HDA_QUAD 4 |
---|
| 26 | +#define HDA_MAX 8 |
---|
35 | 27 | |
---|
36 | 28 | static const struct snd_pcm_hardware azx_pcm_hw = { |
---|
37 | 29 | .info = (SNDRV_PCM_INFO_MMAP | |
---|
.. | .. |
---|
85 | 77 | hdac_stream(stream)->period_bytes = 0; |
---|
86 | 78 | hdac_stream(stream)->format_val = 0; |
---|
87 | 79 | |
---|
88 | | - return snd_pcm_lib_malloc_pages(substream, size); |
---|
89 | | -} |
---|
90 | | - |
---|
91 | | -static int skl_substream_free_pages(struct hdac_bus *bus, |
---|
92 | | - struct snd_pcm_substream *substream) |
---|
93 | | -{ |
---|
94 | | - return snd_pcm_lib_free_pages(substream); |
---|
| 80 | + return 0; |
---|
95 | 81 | } |
---|
96 | 82 | |
---|
97 | 83 | static void skl_set_pcm_constrains(struct hdac_bus *bus, |
---|
.. | .. |
---|
124 | 110 | { |
---|
125 | 111 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
---|
126 | 112 | struct snd_soc_dapm_widget *w; |
---|
127 | | - struct skl *skl = bus_to_skl(bus); |
---|
| 113 | + struct skl_dev *skl = bus_to_skl(bus); |
---|
128 | 114 | |
---|
129 | | - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
---|
130 | | - w = dai->playback_widget; |
---|
131 | | - else |
---|
132 | | - w = dai->capture_widget; |
---|
| 115 | + w = snd_soc_dai_get_widget(dai, substream->stream); |
---|
133 | 116 | |
---|
134 | 117 | if (w->ignore_suspend && enable) |
---|
135 | 118 | skl->supend_active++; |
---|
.. | .. |
---|
140 | 123 | int skl_pcm_host_dma_prepare(struct device *dev, struct skl_pipe_params *params) |
---|
141 | 124 | { |
---|
142 | 125 | struct hdac_bus *bus = dev_get_drvdata(dev); |
---|
| 126 | + struct skl_dev *skl = bus_to_skl(bus); |
---|
143 | 127 | unsigned int format_val; |
---|
144 | 128 | struct hdac_stream *hstream; |
---|
145 | 129 | struct hdac_ext_stream *stream; |
---|
.. | .. |
---|
164 | 148 | if (err < 0) |
---|
165 | 149 | return err; |
---|
166 | 150 | |
---|
167 | | - err = snd_hdac_stream_setup(hdac_stream(stream)); |
---|
| 151 | + /* |
---|
| 152 | + * The recommended SDxFMT programming sequence for BXT |
---|
| 153 | + * platforms is to couple the stream before writing the format |
---|
| 154 | + */ |
---|
| 155 | + if (IS_BXT(skl->pci)) { |
---|
| 156 | + snd_hdac_ext_stream_decouple(bus, stream, false); |
---|
| 157 | + err = snd_hdac_stream_setup(hdac_stream(stream)); |
---|
| 158 | + snd_hdac_ext_stream_decouple(bus, stream, true); |
---|
| 159 | + } else { |
---|
| 160 | + err = snd_hdac_stream_setup(hdac_stream(stream)); |
---|
| 161 | + } |
---|
| 162 | + |
---|
168 | 163 | if (err < 0) |
---|
169 | 164 | return err; |
---|
170 | 165 | |
---|
.. | .. |
---|
220 | 215 | struct hdac_ext_stream *stream; |
---|
221 | 216 | struct snd_pcm_runtime *runtime = substream->runtime; |
---|
222 | 217 | struct skl_dma_params *dma_params; |
---|
223 | | - struct skl *skl = get_skl_ctx(dai->dev); |
---|
| 218 | + struct skl_dev *skl = get_skl_ctx(dai->dev); |
---|
224 | 219 | struct skl_module_cfg *mconfig; |
---|
225 | 220 | |
---|
226 | 221 | dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); |
---|
.. | .. |
---|
267 | 262 | static int skl_pcm_prepare(struct snd_pcm_substream *substream, |
---|
268 | 263 | struct snd_soc_dai *dai) |
---|
269 | 264 | { |
---|
270 | | - struct skl *skl = get_skl_ctx(dai->dev); |
---|
| 265 | + struct skl_dev *skl = get_skl_ctx(dai->dev); |
---|
271 | 266 | struct skl_module_cfg *mconfig; |
---|
272 | 267 | int ret; |
---|
273 | 268 | |
---|
.. | .. |
---|
284 | 279 | mconfig->pipe->state == SKL_PIPE_CREATED || |
---|
285 | 280 | mconfig->pipe->state == SKL_PIPE_PAUSED)) { |
---|
286 | 281 | |
---|
287 | | - ret = skl_reset_pipe(skl->skl_sst, mconfig->pipe); |
---|
| 282 | + ret = skl_reset_pipe(skl, mconfig->pipe); |
---|
288 | 283 | |
---|
289 | 284 | if (ret < 0) |
---|
290 | 285 | return ret; |
---|
.. | .. |
---|
346 | 341 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
---|
347 | 342 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
---|
348 | 343 | struct skl_dma_params *dma_params = NULL; |
---|
349 | | - struct skl *skl = bus_to_skl(bus); |
---|
| 344 | + struct skl_dev *skl = bus_to_skl(bus); |
---|
350 | 345 | struct skl_module_cfg *mconfig; |
---|
351 | 346 | |
---|
352 | 347 | dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); |
---|
.. | .. |
---|
366 | 361 | * CGCTL.MISCBDCGE if disabled by driver |
---|
367 | 362 | */ |
---|
368 | 363 | if (!strncmp(dai->name, "Reference Pin", 13) && |
---|
369 | | - skl->skl_sst->miscbdcg_disabled) { |
---|
370 | | - skl->skl_sst->enable_miscbdcge(dai->dev, true); |
---|
371 | | - skl->skl_sst->miscbdcg_disabled = false; |
---|
| 364 | + skl->miscbdcg_disabled) { |
---|
| 365 | + skl->enable_miscbdcge(dai->dev, true); |
---|
| 366 | + skl->miscbdcg_disabled = false; |
---|
372 | 367 | } |
---|
373 | 368 | |
---|
374 | 369 | mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream); |
---|
.. | .. |
---|
381 | 376 | static int skl_pcm_hw_free(struct snd_pcm_substream *substream, |
---|
382 | 377 | struct snd_soc_dai *dai) |
---|
383 | 378 | { |
---|
384 | | - struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
---|
385 | 379 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
---|
386 | | - struct skl *skl = get_skl_ctx(dai->dev); |
---|
| 380 | + struct skl_dev *skl = get_skl_ctx(dai->dev); |
---|
387 | 381 | struct skl_module_cfg *mconfig; |
---|
388 | 382 | int ret; |
---|
389 | 383 | |
---|
.. | .. |
---|
392 | 386 | mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream); |
---|
393 | 387 | |
---|
394 | 388 | if (mconfig) { |
---|
395 | | - ret = skl_reset_pipe(skl->skl_sst, mconfig->pipe); |
---|
| 389 | + ret = skl_reset_pipe(skl, mconfig->pipe); |
---|
396 | 390 | if (ret < 0) |
---|
397 | 391 | dev_err(dai->dev, "%s:Reset failed ret =%d", |
---|
398 | 392 | __func__, ret); |
---|
.. | .. |
---|
401 | 395 | snd_hdac_stream_cleanup(hdac_stream(stream)); |
---|
402 | 396 | hdac_stream(stream)->prepared = 0; |
---|
403 | 397 | |
---|
404 | | - return skl_substream_free_pages(bus, substream); |
---|
| 398 | + return 0; |
---|
405 | 399 | } |
---|
406 | 400 | |
---|
407 | 401 | static int skl_be_hw_params(struct snd_pcm_substream *substream, |
---|
.. | .. |
---|
467 | 461 | static int skl_pcm_trigger(struct snd_pcm_substream *substream, int cmd, |
---|
468 | 462 | struct snd_soc_dai *dai) |
---|
469 | 463 | { |
---|
470 | | - struct skl *skl = get_skl_ctx(dai->dev); |
---|
471 | | - struct skl_sst *ctx = skl->skl_sst; |
---|
| 464 | + struct skl_dev *skl = get_skl_ctx(dai->dev); |
---|
472 | 465 | struct skl_module_cfg *mconfig; |
---|
473 | 466 | struct hdac_bus *bus = get_bus_ctx(substream); |
---|
474 | 467 | struct hdac_ext_stream *stream = get_hdac_ext_stream(substream); |
---|
.. | .. |
---|
479 | 472 | if (!mconfig) |
---|
480 | 473 | return -EIO; |
---|
481 | 474 | |
---|
482 | | - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
---|
483 | | - w = dai->playback_widget; |
---|
484 | | - else |
---|
485 | | - w = dai->capture_widget; |
---|
| 475 | + w = snd_soc_dai_get_widget(dai, substream->stream); |
---|
486 | 476 | |
---|
487 | 477 | switch (cmd) { |
---|
488 | 478 | case SNDRV_PCM_TRIGGER_RESUME: |
---|
.. | .. |
---|
498 | 488 | stream->lpib); |
---|
499 | 489 | snd_hdac_ext_stream_set_lpib(stream, stream->lpib); |
---|
500 | 490 | } |
---|
| 491 | + fallthrough; |
---|
501 | 492 | |
---|
502 | 493 | case SNDRV_PCM_TRIGGER_START: |
---|
503 | 494 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
---|
.. | .. |
---|
510 | 501 | ret = skl_decoupled_trigger(substream, cmd); |
---|
511 | 502 | if (ret < 0) |
---|
512 | 503 | return ret; |
---|
513 | | - return skl_run_pipe(ctx, mconfig->pipe); |
---|
| 504 | + return skl_run_pipe(skl, mconfig->pipe); |
---|
514 | 505 | break; |
---|
515 | 506 | |
---|
516 | 507 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
---|
.. | .. |
---|
521 | 512 | * there are no underrun/overrun in the case if there is a delay |
---|
522 | 513 | * between the two operations. |
---|
523 | 514 | */ |
---|
524 | | - ret = skl_stop_pipe(ctx, mconfig->pipe); |
---|
| 515 | + ret = skl_stop_pipe(skl, mconfig->pipe); |
---|
525 | 516 | if (ret < 0) |
---|
526 | 517 | return ret; |
---|
527 | 518 | |
---|
.. | .. |
---|
553 | 544 | { |
---|
554 | 545 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
---|
555 | 546 | struct hdac_ext_stream *link_dev; |
---|
556 | | - struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); |
---|
557 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
---|
| 547 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
| 548 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
---|
558 | 549 | struct skl_pipe_params p_params = {0}; |
---|
559 | 550 | struct hdac_ext_link *link; |
---|
560 | 551 | int stream_tag; |
---|
.. | .. |
---|
573 | 564 | stream_tag = hdac_stream(link_dev)->stream_tag; |
---|
574 | 565 | |
---|
575 | 566 | /* set the stream tag in the codec dai dma params */ |
---|
576 | | - snd_soc_dai_set_tdm_slot(codec_dai, stream_tag, 0, 0, 0); |
---|
| 567 | + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
---|
| 568 | + snd_soc_dai_set_tdm_slot(codec_dai, stream_tag, 0, 0, 0); |
---|
| 569 | + else |
---|
| 570 | + snd_soc_dai_set_tdm_slot(codec_dai, 0, stream_tag, 0, 0); |
---|
577 | 571 | |
---|
578 | 572 | p_params.s_fmt = snd_pcm_format_width(params_format(params)); |
---|
579 | 573 | p_params.ch = params_channels(params); |
---|
.. | .. |
---|
594 | 588 | static int skl_link_pcm_prepare(struct snd_pcm_substream *substream, |
---|
595 | 589 | struct snd_soc_dai *dai) |
---|
596 | 590 | { |
---|
597 | | - struct skl *skl = get_skl_ctx(dai->dev); |
---|
| 591 | + struct skl_dev *skl = get_skl_ctx(dai->dev); |
---|
598 | 592 | struct skl_module_cfg *mconfig = NULL; |
---|
599 | 593 | |
---|
600 | 594 | /* In case of XRUN recovery, reset the FW pipe to clean state */ |
---|
601 | 595 | mconfig = skl_tplg_be_get_cpr_module(dai, substream->stream); |
---|
602 | 596 | if (mconfig && !mconfig->pipe->passthru && |
---|
603 | 597 | (substream->runtime->status->state == SNDRV_PCM_STATE_XRUN)) |
---|
604 | | - skl_reset_pipe(skl->skl_sst, mconfig->pipe); |
---|
| 598 | + skl_reset_pipe(skl, mconfig->pipe); |
---|
605 | 599 | |
---|
606 | 600 | return 0; |
---|
607 | 601 | } |
---|
.. | .. |
---|
640 | 634 | struct snd_soc_dai *dai) |
---|
641 | 635 | { |
---|
642 | 636 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
---|
643 | | - struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); |
---|
| 637 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
644 | 638 | struct hdac_ext_stream *link_dev = |
---|
645 | 639 | snd_soc_dai_get_dma_data(dai, substream); |
---|
646 | 640 | struct hdac_ext_link *link; |
---|
.. | .. |
---|
650 | 644 | |
---|
651 | 645 | link_dev->link_prepared = 0; |
---|
652 | 646 | |
---|
653 | | - link = snd_hdac_ext_bus_get_link(bus, rtd->codec_dai->component->name); |
---|
| 647 | + link = snd_hdac_ext_bus_get_link(bus, asoc_rtd_to_codec(rtd, 0)->component->name); |
---|
654 | 648 | if (!link) |
---|
655 | 649 | return -EINVAL; |
---|
656 | 650 | |
---|
.. | .. |
---|
1004 | 998 | }, |
---|
1005 | 999 | }, |
---|
1006 | 1000 | { |
---|
1007 | | - .name = "HD-Codec Pin", |
---|
| 1001 | + .name = "Analog CPU DAI", |
---|
1008 | 1002 | .ops = &skl_link_dai_ops, |
---|
1009 | 1003 | .playback = { |
---|
1010 | | - .stream_name = "HD-Codec Tx", |
---|
1011 | | - .channels_min = HDA_STEREO, |
---|
1012 | | - .channels_max = HDA_STEREO, |
---|
1013 | | - .rates = SNDRV_PCM_RATE_48000, |
---|
1014 | | - .formats = SNDRV_PCM_FMTBIT_S16_LE, |
---|
| 1004 | + .stream_name = "Analog CPU Playback", |
---|
| 1005 | + .channels_min = HDA_MONO, |
---|
| 1006 | + .channels_max = HDA_MAX, |
---|
| 1007 | + .rates = SNDRV_PCM_RATE_8000_192000, |
---|
| 1008 | + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
---|
| 1009 | + SNDRV_PCM_FMTBIT_S32_LE, |
---|
1015 | 1010 | }, |
---|
1016 | 1011 | .capture = { |
---|
1017 | | - .stream_name = "HD-Codec Rx", |
---|
1018 | | - .channels_min = HDA_STEREO, |
---|
1019 | | - .channels_max = HDA_STEREO, |
---|
1020 | | - .rates = SNDRV_PCM_RATE_48000, |
---|
1021 | | - .formats = SNDRV_PCM_FMTBIT_S16_LE, |
---|
| 1012 | + .stream_name = "Analog CPU Capture", |
---|
| 1013 | + .channels_min = HDA_MONO, |
---|
| 1014 | + .channels_max = HDA_MAX, |
---|
| 1015 | + .rates = SNDRV_PCM_RATE_8000_192000, |
---|
| 1016 | + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
---|
| 1017 | + SNDRV_PCM_FMTBIT_S32_LE, |
---|
| 1018 | + }, |
---|
| 1019 | +}, |
---|
| 1020 | +{ |
---|
| 1021 | + .name = "Alt Analog CPU DAI", |
---|
| 1022 | + .ops = &skl_link_dai_ops, |
---|
| 1023 | + .playback = { |
---|
| 1024 | + .stream_name = "Alt Analog CPU Playback", |
---|
| 1025 | + .channels_min = HDA_MONO, |
---|
| 1026 | + .channels_max = HDA_MAX, |
---|
| 1027 | + .rates = SNDRV_PCM_RATE_8000_192000, |
---|
| 1028 | + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
---|
| 1029 | + SNDRV_PCM_FMTBIT_S32_LE, |
---|
| 1030 | + }, |
---|
| 1031 | + .capture = { |
---|
| 1032 | + .stream_name = "Alt Analog CPU Capture", |
---|
| 1033 | + .channels_min = HDA_MONO, |
---|
| 1034 | + .channels_max = HDA_MAX, |
---|
| 1035 | + .rates = SNDRV_PCM_RATE_8000_192000, |
---|
| 1036 | + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
---|
| 1037 | + SNDRV_PCM_FMTBIT_S32_LE, |
---|
| 1038 | + }, |
---|
| 1039 | +}, |
---|
| 1040 | +{ |
---|
| 1041 | + .name = "Digital CPU DAI", |
---|
| 1042 | + .ops = &skl_link_dai_ops, |
---|
| 1043 | + .playback = { |
---|
| 1044 | + .stream_name = "Digital CPU Playback", |
---|
| 1045 | + .channels_min = HDA_MONO, |
---|
| 1046 | + .channels_max = HDA_MAX, |
---|
| 1047 | + .rates = SNDRV_PCM_RATE_8000_192000, |
---|
| 1048 | + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
---|
| 1049 | + SNDRV_PCM_FMTBIT_S32_LE, |
---|
| 1050 | + }, |
---|
| 1051 | + .capture = { |
---|
| 1052 | + .stream_name = "Digital CPU Capture", |
---|
| 1053 | + .channels_min = HDA_MONO, |
---|
| 1054 | + .channels_max = HDA_MAX, |
---|
| 1055 | + .rates = SNDRV_PCM_RATE_8000_192000, |
---|
| 1056 | + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | |
---|
| 1057 | + SNDRV_PCM_FMTBIT_S32_LE, |
---|
1022 | 1058 | }, |
---|
1023 | 1059 | }, |
---|
1024 | 1060 | }; |
---|
.. | .. |
---|
1032 | 1068 | return 0; |
---|
1033 | 1069 | } |
---|
1034 | 1070 | |
---|
1035 | | -static int skl_platform_open(struct snd_pcm_substream *substream) |
---|
| 1071 | +static int skl_platform_soc_open(struct snd_soc_component *component, |
---|
| 1072 | + struct snd_pcm_substream *substream) |
---|
1036 | 1073 | { |
---|
1037 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
---|
| 1074 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
1038 | 1075 | struct snd_soc_dai_link *dai_link = rtd->dai_link; |
---|
1039 | 1076 | |
---|
1040 | | - dev_dbg(rtd->cpu_dai->dev, "In %s:%s\n", __func__, |
---|
1041 | | - dai_link->cpu_dai_name); |
---|
| 1077 | + dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "In %s:%s\n", __func__, |
---|
| 1078 | + dai_link->cpus->dai_name); |
---|
1042 | 1079 | |
---|
1043 | 1080 | snd_soc_set_runtime_hwparams(substream, &azx_pcm_hw); |
---|
1044 | 1081 | |
---|
.. | .. |
---|
1118 | 1155 | return 0; |
---|
1119 | 1156 | } |
---|
1120 | 1157 | |
---|
1121 | | -static int skl_platform_pcm_trigger(struct snd_pcm_substream *substream, |
---|
1122 | | - int cmd) |
---|
| 1158 | +static int skl_platform_soc_trigger(struct snd_soc_component *component, |
---|
| 1159 | + struct snd_pcm_substream *substream, |
---|
| 1160 | + int cmd) |
---|
1123 | 1161 | { |
---|
1124 | 1162 | struct hdac_bus *bus = get_bus_ctx(substream); |
---|
1125 | 1163 | |
---|
.. | .. |
---|
1129 | 1167 | return 0; |
---|
1130 | 1168 | } |
---|
1131 | 1169 | |
---|
1132 | | -static snd_pcm_uframes_t skl_platform_pcm_pointer |
---|
1133 | | - (struct snd_pcm_substream *substream) |
---|
| 1170 | +static snd_pcm_uframes_t skl_platform_soc_pointer( |
---|
| 1171 | + struct snd_soc_component *component, |
---|
| 1172 | + struct snd_pcm_substream *substream) |
---|
1134 | 1173 | { |
---|
1135 | 1174 | struct hdac_ext_stream *hstream = get_hdac_ext_stream(substream); |
---|
1136 | 1175 | struct hdac_bus *bus = get_bus_ctx(substream); |
---|
.. | .. |
---|
1176 | 1215 | return bytes_to_frames(substream->runtime, pos); |
---|
1177 | 1216 | } |
---|
1178 | 1217 | |
---|
| 1218 | +static int skl_platform_soc_mmap(struct snd_soc_component *component, |
---|
| 1219 | + struct snd_pcm_substream *substream, |
---|
| 1220 | + struct vm_area_struct *area) |
---|
| 1221 | +{ |
---|
| 1222 | + return snd_pcm_lib_default_mmap(substream, area); |
---|
| 1223 | +} |
---|
| 1224 | + |
---|
1179 | 1225 | static u64 skl_adjust_codec_delay(struct snd_pcm_substream *substream, |
---|
1180 | 1226 | u64 nsec) |
---|
1181 | 1227 | { |
---|
1182 | | - struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream); |
---|
1183 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
---|
| 1228 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
| 1229 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
---|
1184 | 1230 | u64 codec_frames, codec_nsecs; |
---|
1185 | 1231 | |
---|
1186 | 1232 | if (!codec_dai->driver->ops->delay) |
---|
.. | .. |
---|
1196 | 1242 | return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0; |
---|
1197 | 1243 | } |
---|
1198 | 1244 | |
---|
1199 | | -static int skl_get_time_info(struct snd_pcm_substream *substream, |
---|
1200 | | - struct timespec *system_ts, struct timespec *audio_ts, |
---|
| 1245 | +static int skl_platform_soc_get_time_info( |
---|
| 1246 | + struct snd_soc_component *component, |
---|
| 1247 | + struct snd_pcm_substream *substream, |
---|
| 1248 | + struct timespec64 *system_ts, struct timespec64 *audio_ts, |
---|
1201 | 1249 | struct snd_pcm_audio_tstamp_config *audio_tstamp_config, |
---|
1202 | 1250 | struct snd_pcm_audio_tstamp_report *audio_tstamp_report) |
---|
1203 | 1251 | { |
---|
.. | .. |
---|
1215 | 1263 | if (audio_tstamp_config->report_delay) |
---|
1216 | 1264 | nsec = skl_adjust_codec_delay(substream, nsec); |
---|
1217 | 1265 | |
---|
1218 | | - *audio_ts = ns_to_timespec(nsec); |
---|
| 1266 | + *audio_ts = ns_to_timespec64(nsec); |
---|
1219 | 1267 | |
---|
1220 | 1268 | audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; |
---|
1221 | 1269 | audio_tstamp_report->accuracy_report = 1; /* rest of struct is valid */ |
---|
.. | .. |
---|
1228 | 1276 | return 0; |
---|
1229 | 1277 | } |
---|
1230 | 1278 | |
---|
1231 | | -static const struct snd_pcm_ops skl_platform_ops = { |
---|
1232 | | - .open = skl_platform_open, |
---|
1233 | | - .ioctl = snd_pcm_lib_ioctl, |
---|
1234 | | - .trigger = skl_platform_pcm_trigger, |
---|
1235 | | - .pointer = skl_platform_pcm_pointer, |
---|
1236 | | - .get_time_info = skl_get_time_info, |
---|
1237 | | - .mmap = snd_pcm_lib_default_mmap, |
---|
1238 | | - .page = snd_pcm_sgbuf_ops_page, |
---|
1239 | | -}; |
---|
1240 | | - |
---|
1241 | | -static void skl_pcm_free(struct snd_pcm *pcm) |
---|
1242 | | -{ |
---|
1243 | | - snd_pcm_lib_preallocate_free_for_all(pcm); |
---|
1244 | | -} |
---|
1245 | | - |
---|
1246 | 1279 | #define MAX_PREALLOC_SIZE (32 * 1024 * 1024) |
---|
1247 | 1280 | |
---|
1248 | | -static int skl_pcm_new(struct snd_soc_pcm_runtime *rtd) |
---|
| 1281 | +static int skl_platform_soc_new(struct snd_soc_component *component, |
---|
| 1282 | + struct snd_soc_pcm_runtime *rtd) |
---|
1249 | 1283 | { |
---|
1250 | | - struct snd_soc_dai *dai = rtd->cpu_dai; |
---|
| 1284 | + struct snd_soc_dai *dai = asoc_rtd_to_cpu(rtd, 0); |
---|
1251 | 1285 | struct hdac_bus *bus = dev_get_drvdata(dai->dev); |
---|
1252 | 1286 | struct snd_pcm *pcm = rtd->pcm; |
---|
1253 | 1287 | unsigned int size; |
---|
1254 | | - int retval = 0; |
---|
1255 | | - struct skl *skl = bus_to_skl(bus); |
---|
| 1288 | + struct skl_dev *skl = bus_to_skl(bus); |
---|
1256 | 1289 | |
---|
1257 | 1290 | if (dai->driver->playback.channels_min || |
---|
1258 | 1291 | dai->driver->capture.channels_min) { |
---|
.. | .. |
---|
1260 | 1293 | size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024; |
---|
1261 | 1294 | if (size > MAX_PREALLOC_SIZE) |
---|
1262 | 1295 | size = MAX_PREALLOC_SIZE; |
---|
1263 | | - retval = snd_pcm_lib_preallocate_pages_for_all(pcm, |
---|
1264 | | - SNDRV_DMA_TYPE_DEV_SG, |
---|
1265 | | - snd_dma_pci_data(skl->pci), |
---|
1266 | | - size, MAX_PREALLOC_SIZE); |
---|
1267 | | - if (retval) { |
---|
1268 | | - dev_err(dai->dev, "dma buffer allocation fail\n"); |
---|
1269 | | - return retval; |
---|
1270 | | - } |
---|
1271 | | - } |
---|
1272 | | - |
---|
1273 | | - return retval; |
---|
1274 | | -} |
---|
1275 | | - |
---|
1276 | | -static int skl_get_module_info(struct skl *skl, struct skl_module_cfg *mconfig) |
---|
1277 | | -{ |
---|
1278 | | - struct skl_sst *ctx = skl->skl_sst; |
---|
1279 | | - struct skl_module_inst_id *pin_id; |
---|
1280 | | - uuid_le *uuid_mod, *uuid_tplg; |
---|
1281 | | - struct skl_module *skl_module; |
---|
1282 | | - struct uuid_module *module; |
---|
1283 | | - int i, ret = -EIO; |
---|
1284 | | - |
---|
1285 | | - uuid_mod = (uuid_le *)mconfig->guid; |
---|
1286 | | - |
---|
1287 | | - if (list_empty(&ctx->uuid_list)) { |
---|
1288 | | - dev_err(ctx->dev, "Module list is empty\n"); |
---|
1289 | | - return -EIO; |
---|
1290 | | - } |
---|
1291 | | - |
---|
1292 | | - list_for_each_entry(module, &ctx->uuid_list, list) { |
---|
1293 | | - if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) { |
---|
1294 | | - mconfig->id.module_id = module->id; |
---|
1295 | | - if (mconfig->module) |
---|
1296 | | - mconfig->module->loadable = module->is_loadable; |
---|
1297 | | - ret = 0; |
---|
1298 | | - break; |
---|
1299 | | - } |
---|
1300 | | - } |
---|
1301 | | - |
---|
1302 | | - if (ret) |
---|
1303 | | - return ret; |
---|
1304 | | - |
---|
1305 | | - uuid_mod = &module->uuid; |
---|
1306 | | - ret = -EIO; |
---|
1307 | | - for (i = 0; i < skl->nr_modules; i++) { |
---|
1308 | | - skl_module = skl->modules[i]; |
---|
1309 | | - uuid_tplg = &skl_module->uuid; |
---|
1310 | | - if (!uuid_le_cmp(*uuid_mod, *uuid_tplg)) { |
---|
1311 | | - mconfig->module = skl_module; |
---|
1312 | | - ret = 0; |
---|
1313 | | - break; |
---|
1314 | | - } |
---|
1315 | | - } |
---|
1316 | | - if (skl->nr_modules && ret) |
---|
1317 | | - return ret; |
---|
1318 | | - |
---|
1319 | | - list_for_each_entry(module, &ctx->uuid_list, list) { |
---|
1320 | | - for (i = 0; i < MAX_IN_QUEUE; i++) { |
---|
1321 | | - pin_id = &mconfig->m_in_pin[i].id; |
---|
1322 | | - if (!uuid_le_cmp(pin_id->mod_uuid, module->uuid)) |
---|
1323 | | - pin_id->module_id = module->id; |
---|
1324 | | - } |
---|
1325 | | - |
---|
1326 | | - for (i = 0; i < MAX_OUT_QUEUE; i++) { |
---|
1327 | | - pin_id = &mconfig->m_out_pin[i].id; |
---|
1328 | | - if (!uuid_le_cmp(pin_id->mod_uuid, module->uuid)) |
---|
1329 | | - pin_id->module_id = module->id; |
---|
1330 | | - } |
---|
| 1296 | + snd_pcm_set_managed_buffer_all(pcm, |
---|
| 1297 | + SNDRV_DMA_TYPE_DEV_SG, |
---|
| 1298 | + &skl->pci->dev, |
---|
| 1299 | + size, MAX_PREALLOC_SIZE); |
---|
1331 | 1300 | } |
---|
1332 | 1301 | |
---|
1333 | 1302 | return 0; |
---|
1334 | 1303 | } |
---|
1335 | 1304 | |
---|
1336 | | -static int skl_populate_modules(struct skl *skl) |
---|
| 1305 | +static int skl_get_module_info(struct skl_dev *skl, |
---|
| 1306 | + struct skl_module_cfg *mconfig) |
---|
| 1307 | +{ |
---|
| 1308 | + struct skl_module_inst_id *pin_id; |
---|
| 1309 | + guid_t *uuid_mod, *uuid_tplg; |
---|
| 1310 | + struct skl_module *skl_module; |
---|
| 1311 | + struct uuid_module *module; |
---|
| 1312 | + int i, ret = -EIO; |
---|
| 1313 | + |
---|
| 1314 | + uuid_mod = (guid_t *)mconfig->guid; |
---|
| 1315 | + |
---|
| 1316 | + if (list_empty(&skl->uuid_list)) { |
---|
| 1317 | + dev_err(skl->dev, "Module list is empty\n"); |
---|
| 1318 | + return -EIO; |
---|
| 1319 | + } |
---|
| 1320 | + |
---|
| 1321 | + for (i = 0; i < skl->nr_modules; i++) { |
---|
| 1322 | + skl_module = skl->modules[i]; |
---|
| 1323 | + uuid_tplg = &skl_module->uuid; |
---|
| 1324 | + if (guid_equal(uuid_mod, uuid_tplg)) { |
---|
| 1325 | + mconfig->module = skl_module; |
---|
| 1326 | + ret = 0; |
---|
| 1327 | + break; |
---|
| 1328 | + } |
---|
| 1329 | + } |
---|
| 1330 | + |
---|
| 1331 | + if (skl->nr_modules && ret) |
---|
| 1332 | + return ret; |
---|
| 1333 | + |
---|
| 1334 | + ret = -EIO; |
---|
| 1335 | + list_for_each_entry(module, &skl->uuid_list, list) { |
---|
| 1336 | + if (guid_equal(uuid_mod, &module->uuid)) { |
---|
| 1337 | + mconfig->id.module_id = module->id; |
---|
| 1338 | + mconfig->module->loadable = module->is_loadable; |
---|
| 1339 | + ret = 0; |
---|
| 1340 | + } |
---|
| 1341 | + |
---|
| 1342 | + for (i = 0; i < MAX_IN_QUEUE; i++) { |
---|
| 1343 | + pin_id = &mconfig->m_in_pin[i].id; |
---|
| 1344 | + if (guid_equal(&pin_id->mod_uuid, &module->uuid)) |
---|
| 1345 | + pin_id->module_id = module->id; |
---|
| 1346 | + } |
---|
| 1347 | + |
---|
| 1348 | + for (i = 0; i < MAX_OUT_QUEUE; i++) { |
---|
| 1349 | + pin_id = &mconfig->m_out_pin[i].id; |
---|
| 1350 | + if (guid_equal(&pin_id->mod_uuid, &module->uuid)) |
---|
| 1351 | + pin_id->module_id = module->id; |
---|
| 1352 | + } |
---|
| 1353 | + } |
---|
| 1354 | + |
---|
| 1355 | + return ret; |
---|
| 1356 | +} |
---|
| 1357 | + |
---|
| 1358 | +static int skl_populate_modules(struct skl_dev *skl) |
---|
1337 | 1359 | { |
---|
1338 | 1360 | struct skl_pipeline *p; |
---|
1339 | 1361 | struct skl_pipe_module *m; |
---|
.. | .. |
---|
1348 | 1370 | |
---|
1349 | 1371 | ret = skl_get_module_info(skl, mconfig); |
---|
1350 | 1372 | if (ret < 0) { |
---|
1351 | | - dev_err(skl->skl_sst->dev, |
---|
| 1373 | + dev_err(skl->dev, |
---|
1352 | 1374 | "query module info failed\n"); |
---|
1353 | 1375 | return ret; |
---|
1354 | 1376 | } |
---|
.. | .. |
---|
1363 | 1385 | static int skl_platform_soc_probe(struct snd_soc_component *component) |
---|
1364 | 1386 | { |
---|
1365 | 1387 | struct hdac_bus *bus = dev_get_drvdata(component->dev); |
---|
1366 | | - struct skl *skl = bus_to_skl(bus); |
---|
| 1388 | + struct skl_dev *skl = bus_to_skl(bus); |
---|
1367 | 1389 | const struct skl_dsp_ops *ops; |
---|
1368 | 1390 | int ret; |
---|
1369 | 1391 | |
---|
.. | .. |
---|
1385 | 1407 | if (!ops) |
---|
1386 | 1408 | return -EIO; |
---|
1387 | 1409 | |
---|
1388 | | - if (skl->skl_sst->is_first_boot == false) { |
---|
1389 | | - dev_err(component->dev, "DSP reports first boot done!!!\n"); |
---|
1390 | | - return -EIO; |
---|
1391 | | - } |
---|
1392 | | - |
---|
1393 | 1410 | /* |
---|
1394 | 1411 | * Disable dynamic clock and power gating during firmware |
---|
1395 | 1412 | * and library download |
---|
1396 | 1413 | */ |
---|
1397 | | - skl->skl_sst->enable_miscbdcge(component->dev, false); |
---|
1398 | | - skl->skl_sst->clock_power_gating(component->dev, false); |
---|
| 1414 | + skl->enable_miscbdcge(component->dev, false); |
---|
| 1415 | + skl->clock_power_gating(component->dev, false); |
---|
1399 | 1416 | |
---|
1400 | | - ret = ops->init_fw(component->dev, skl->skl_sst); |
---|
1401 | | - skl->skl_sst->enable_miscbdcge(component->dev, true); |
---|
1402 | | - skl->skl_sst->clock_power_gating(component->dev, true); |
---|
| 1417 | + ret = ops->init_fw(component->dev, skl); |
---|
| 1418 | + skl->enable_miscbdcge(component->dev, true); |
---|
| 1419 | + skl->clock_power_gating(component->dev, true); |
---|
1403 | 1420 | if (ret < 0) { |
---|
1404 | 1421 | dev_err(component->dev, "Failed to boot first fw: %d\n", ret); |
---|
1405 | 1422 | return ret; |
---|
1406 | 1423 | } |
---|
1407 | 1424 | skl_populate_modules(skl); |
---|
1408 | | - skl->skl_sst->update_d0i3c = skl_update_d0i3c; |
---|
1409 | | - skl_dsp_enable_notification(skl->skl_sst, false); |
---|
| 1425 | + skl->update_d0i3c = skl_update_d0i3c; |
---|
1410 | 1426 | |
---|
1411 | 1427 | if (skl->cfg.astate_cfg != NULL) { |
---|
1412 | | - skl_dsp_set_astate_cfg(skl->skl_sst, |
---|
| 1428 | + skl_dsp_set_astate_cfg(skl, |
---|
1413 | 1429 | skl->cfg.astate_cfg->count, |
---|
1414 | 1430 | skl->cfg.astate_cfg); |
---|
1415 | 1431 | } |
---|
.. | .. |
---|
1420 | 1436 | return 0; |
---|
1421 | 1437 | } |
---|
1422 | 1438 | |
---|
| 1439 | +static void skl_platform_soc_remove(struct snd_soc_component *component) |
---|
| 1440 | +{ |
---|
| 1441 | + struct hdac_bus *bus = dev_get_drvdata(component->dev); |
---|
| 1442 | + struct skl_dev *skl = bus_to_skl(bus); |
---|
| 1443 | + |
---|
| 1444 | + skl_tplg_exit(component, bus); |
---|
| 1445 | + |
---|
| 1446 | + skl_debugfs_exit(skl); |
---|
| 1447 | +} |
---|
| 1448 | + |
---|
1423 | 1449 | static const struct snd_soc_component_driver skl_component = { |
---|
1424 | 1450 | .name = "pcm", |
---|
1425 | 1451 | .probe = skl_platform_soc_probe, |
---|
1426 | | - .ops = &skl_platform_ops, |
---|
1427 | | - .pcm_new = skl_pcm_new, |
---|
1428 | | - .pcm_free = skl_pcm_free, |
---|
| 1452 | + .remove = skl_platform_soc_remove, |
---|
| 1453 | + .open = skl_platform_soc_open, |
---|
| 1454 | + .trigger = skl_platform_soc_trigger, |
---|
| 1455 | + .pointer = skl_platform_soc_pointer, |
---|
| 1456 | + .get_time_info = skl_platform_soc_get_time_info, |
---|
| 1457 | + .mmap = skl_platform_soc_mmap, |
---|
| 1458 | + .pcm_construct = skl_platform_soc_new, |
---|
| 1459 | + .module_get_upon_open = 1, /* increment refcount when a pcm is opened */ |
---|
1429 | 1460 | }; |
---|
1430 | 1461 | |
---|
1431 | 1462 | int skl_platform_register(struct device *dev) |
---|
.. | .. |
---|
1434 | 1465 | struct snd_soc_dai_driver *dais; |
---|
1435 | 1466 | int num_dais = ARRAY_SIZE(skl_platform_dai); |
---|
1436 | 1467 | struct hdac_bus *bus = dev_get_drvdata(dev); |
---|
1437 | | - struct skl *skl = bus_to_skl(bus); |
---|
1438 | | - |
---|
1439 | | - INIT_LIST_HEAD(&skl->ppl_list); |
---|
1440 | | - INIT_LIST_HEAD(&skl->bind_list); |
---|
| 1468 | + struct skl_dev *skl = bus_to_skl(bus); |
---|
1441 | 1469 | |
---|
1442 | 1470 | skl->dais = kmemdup(skl_platform_dai, sizeof(skl_platform_dai), |
---|
1443 | 1471 | GFP_KERNEL); |
---|
.. | .. |
---|
1471 | 1499 | int skl_platform_unregister(struct device *dev) |
---|
1472 | 1500 | { |
---|
1473 | 1501 | struct hdac_bus *bus = dev_get_drvdata(dev); |
---|
1474 | | - struct skl *skl = bus_to_skl(bus); |
---|
| 1502 | + struct skl_dev *skl = bus_to_skl(bus); |
---|
1475 | 1503 | struct skl_module_deferred_bind *modules, *tmp; |
---|
1476 | 1504 | |
---|
1477 | | - if (!list_empty(&skl->bind_list)) { |
---|
1478 | | - list_for_each_entry_safe(modules, tmp, &skl->bind_list, node) { |
---|
1479 | | - list_del(&modules->node); |
---|
1480 | | - kfree(modules); |
---|
1481 | | - } |
---|
| 1505 | + list_for_each_entry_safe(modules, tmp, &skl->bind_list, node) { |
---|
| 1506 | + list_del(&modules->node); |
---|
| 1507 | + kfree(modules); |
---|
1482 | 1508 | } |
---|
1483 | 1509 | |
---|
1484 | 1510 | kfree(skl->dais); |
---|