1 // SPDX-License-Identifier: GPL-2.0-only
3 // Copyright(c) 2021-2022 Intel Corporation
9 #include <linux/debugfs.h>
10 #include <linux/device.h>
11 #include <sound/hda_register.h>
12 #include <sound/hdaudio_ext.h>
13 #include <sound/pcm_params.h>
14 #include <sound/soc-acpi.h>
15 #include <sound/soc-acpi-intel-match.h>
16 #include <sound/soc-component.h>
21 #include "../../codecs/hda.h"
24 struct avs_tplg_path_template *template;
25 struct avs_path *path;
28 /* LINK-stream utilized in BE operations while HOST in FE ones. */
30 struct hdac_ext_stream *link_stream;
31 struct hdac_ext_stream *host_stream;
34 struct work_struct period_elapsed_work;
35 struct snd_pcm_substream *substream;
38 static struct avs_tplg_path_template *
39 avs_dai_find_path_template(struct snd_soc_dai *dai, bool is_fe, int direction)
41 struct snd_soc_dapm_widget *dw = snd_soc_dai_get_widget(dai, direction);
42 struct snd_soc_dapm_path *dp;
43 enum snd_soc_dapm_direction dir;
45 if (direction == SNDRV_PCM_STREAM_CAPTURE) {
46 dir = is_fe ? SND_SOC_DAPM_DIR_OUT : SND_SOC_DAPM_DIR_IN;
48 dir = is_fe ? SND_SOC_DAPM_DIR_IN : SND_SOC_DAPM_DIR_OUT;
51 dp = list_first_entry_or_null(&dw->edges[dir], typeof(*dp), list_node[dir]);
55 /* Get the other widget, with actual path template data */
56 dw = (dp->source == dw) ? dp->sink : dp->source;
61 static void avs_period_elapsed_work(struct work_struct *work)
63 struct avs_dma_data *data = container_of(work, struct avs_dma_data, period_elapsed_work);
65 snd_pcm_period_elapsed(data->substream);
68 void avs_period_elapsed(struct snd_pcm_substream *substream)
70 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
71 struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0);
72 struct avs_dma_data *data = snd_soc_dai_get_dma_data(dai, substream);
74 schedule_work(&data->period_elapsed_work);
77 static int avs_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
79 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
80 struct avs_dev *adev = to_avs_dev(dai->component->dev);
81 struct avs_tplg_path_template *template;
82 struct avs_dma_data *data;
84 template = avs_dai_find_path_template(dai, !rtd->dai_link->no_pcm, substream->stream);
86 dev_err(dai->dev, "no %s path for dai %s, invalid tplg?\n",
87 snd_pcm_stream_str(substream), dai->name);
91 data = kzalloc(sizeof(*data), GFP_KERNEL);
95 data->substream = substream;
96 data->template = template;
98 INIT_WORK(&data->period_elapsed_work, avs_period_elapsed_work);
99 snd_soc_dai_set_dma_data(dai, substream, data);
101 if (rtd->dai_link->ignore_suspend)
102 adev->num_lp_paths++;
107 static void avs_dai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
109 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
110 struct avs_dma_data *data;
112 data = snd_soc_dai_get_dma_data(dai, substream);
114 if (rtd->dai_link->ignore_suspend)
115 data->adev->num_lp_paths--;
117 snd_soc_dai_set_dma_data(dai, substream, NULL);
121 static int avs_dai_hw_params(struct snd_pcm_substream *substream,
122 struct snd_pcm_hw_params *fe_hw_params,
123 struct snd_pcm_hw_params *be_hw_params, struct snd_soc_dai *dai,
126 struct avs_dma_data *data;
127 struct avs_path *path;
130 data = snd_soc_dai_get_dma_data(dai, substream);
132 dev_dbg(dai->dev, "%s FE hw_params str %p rtd %p",
133 __func__, substream, substream->runtime);
134 dev_dbg(dai->dev, "rate %d chn %d vbd %d bd %d\n",
135 params_rate(fe_hw_params), params_channels(fe_hw_params),
136 params_width(fe_hw_params), params_physical_width(fe_hw_params));
138 dev_dbg(dai->dev, "%s BE hw_params str %p rtd %p",
139 __func__, substream, substream->runtime);
140 dev_dbg(dai->dev, "rate %d chn %d vbd %d bd %d\n",
141 params_rate(be_hw_params), params_channels(be_hw_params),
142 params_width(be_hw_params), params_physical_width(be_hw_params));
144 path = avs_path_create(data->adev, dma_id, data->template, fe_hw_params, be_hw_params);
147 dev_err(dai->dev, "create path failed: %d\n", ret);
155 static int avs_dai_be_hw_params(struct snd_pcm_substream *substream,
156 struct snd_pcm_hw_params *be_hw_params, struct snd_soc_dai *dai,
159 struct snd_pcm_hw_params *fe_hw_params = NULL;
160 struct snd_soc_pcm_runtime *fe, *be;
161 struct snd_soc_dpcm *dpcm;
163 be = snd_soc_substream_to_rtd(substream);
164 /* dpcm_fe_dai_open() guarantees the list is not empty at this point. */
165 for_each_dpcm_fe(be, substream->stream, dpcm) {
167 fe_hw_params = &fe->dpcm[substream->stream].hw_params;
170 return avs_dai_hw_params(substream, fe_hw_params, be_hw_params, dai, dma_id);
173 static int avs_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
175 struct avs_dma_data *data;
178 data = snd_soc_dai_get_dma_data(dai, substream);
182 ret = avs_path_reset(data->path);
184 dev_err(dai->dev, "reset path failed: %d\n", ret);
188 ret = avs_path_pause(data->path);
190 dev_err(dai->dev, "pause path failed: %d\n", ret);
194 static int avs_dai_nonhda_be_hw_params(struct snd_pcm_substream *substream,
195 struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai)
197 struct avs_dma_data *data;
199 data = snd_soc_dai_get_dma_data(dai, substream);
203 /* Actual port-id comes from topology. */
204 return avs_dai_be_hw_params(substream, hw_params, dai, 0);
207 static int avs_dai_nonhda_be_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
209 struct avs_dma_data *data;
211 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
213 data = snd_soc_dai_get_dma_data(dai, substream);
215 avs_path_free(data->path);
222 static int avs_dai_nonhda_be_trigger(struct snd_pcm_substream *substream, int cmd,
223 struct snd_soc_dai *dai)
225 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
226 struct avs_dma_data *data;
229 data = snd_soc_dai_get_dma_data(dai, substream);
232 case SNDRV_PCM_TRIGGER_RESUME:
233 if (rtd->dai_link->ignore_suspend)
236 case SNDRV_PCM_TRIGGER_START:
237 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
238 ret = avs_path_pause(data->path);
240 dev_err(dai->dev, "pause BE path failed: %d\n", ret);
244 ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO);
246 dev_err(dai->dev, "run BE path failed: %d\n", ret);
249 case SNDRV_PCM_TRIGGER_SUSPEND:
250 if (rtd->dai_link->ignore_suspend)
253 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
254 case SNDRV_PCM_TRIGGER_STOP:
255 ret = avs_path_pause(data->path);
257 dev_err(dai->dev, "pause BE path failed: %d\n", ret);
259 ret = avs_path_reset(data->path);
261 dev_err(dai->dev, "reset BE path failed: %d\n", ret);
272 static const struct snd_soc_dai_ops avs_dai_nonhda_be_ops = {
273 .startup = avs_dai_startup,
274 .shutdown = avs_dai_shutdown,
275 .hw_params = avs_dai_nonhda_be_hw_params,
276 .hw_free = avs_dai_nonhda_be_hw_free,
277 .prepare = avs_dai_prepare,
278 .trigger = avs_dai_nonhda_be_trigger,
281 static int avs_dai_hda_be_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
283 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
284 struct hdac_ext_stream *link_stream;
285 struct avs_dma_data *data;
286 struct hda_codec *codec;
289 ret = avs_dai_startup(substream, dai);
293 codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev);
294 link_stream = snd_hdac_ext_stream_assign(&codec->bus->core, substream,
295 HDAC_EXT_STREAM_TYPE_LINK);
297 avs_dai_shutdown(substream, dai);
301 data = snd_soc_dai_get_dma_data(dai, substream);
302 data->link_stream = link_stream;
303 substream->runtime->private_data = link_stream;
307 static void avs_dai_hda_be_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
309 struct avs_dma_data *data = snd_soc_dai_get_dma_data(dai, substream);
311 snd_hdac_ext_stream_release(data->link_stream, HDAC_EXT_STREAM_TYPE_LINK);
312 substream->runtime->private_data = NULL;
313 avs_dai_shutdown(substream, dai);
316 static int avs_dai_hda_be_hw_params(struct snd_pcm_substream *substream,
317 struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai)
319 struct avs_dma_data *data;
321 data = snd_soc_dai_get_dma_data(dai, substream);
325 return avs_dai_be_hw_params(substream, hw_params, dai,
326 hdac_stream(data->link_stream)->stream_tag - 1);
329 static int avs_dai_hda_be_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
331 struct avs_dma_data *data;
332 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
333 struct hdac_ext_stream *link_stream;
334 struct hdac_ext_link *link;
335 struct hda_codec *codec;
337 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
339 data = snd_soc_dai_get_dma_data(dai, substream);
343 link_stream = data->link_stream;
344 link_stream->link_prepared = false;
345 avs_path_free(data->path);
348 /* clear link <-> stream mapping */
349 codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev);
350 link = snd_hdac_ext_bus_get_hlink_by_addr(&codec->bus->core, codec->core.addr);
354 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
355 snd_hdac_ext_bus_link_clear_stream_id(link, hdac_stream(link_stream)->stream_tag);
360 static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
362 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
363 struct snd_pcm_runtime *runtime = substream->runtime;
364 const struct snd_soc_pcm_stream *stream_info;
365 struct hdac_ext_stream *link_stream;
366 struct hdac_ext_link *link;
367 struct avs_dma_data *data;
368 struct hda_codec *codec;
369 struct hdac_bus *bus;
370 unsigned int format_val;
374 data = snd_soc_dai_get_dma_data(dai, substream);
375 link_stream = data->link_stream;
377 if (link_stream->link_prepared)
380 codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev);
381 bus = &codec->bus->core;
382 stream_info = snd_soc_dai_get_pcm_stream(dai, substream->stream);
383 bits = snd_hdac_stream_format_bits(runtime->format, runtime->subformat,
384 stream_info->sig_bits);
385 format_val = snd_hdac_stream_format(runtime->channels, bits, runtime->rate);
387 snd_hdac_ext_stream_decouple(bus, link_stream, true);
388 snd_hdac_ext_stream_reset(link_stream);
389 snd_hdac_ext_stream_setup(link_stream, format_val);
391 link = snd_hdac_ext_bus_get_hlink_by_addr(bus, codec->core.addr);
395 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
396 snd_hdac_ext_bus_link_set_stream_id(link, hdac_stream(link_stream)->stream_tag);
398 ret = avs_dai_prepare(substream, dai);
402 link_stream->link_prepared = true;
406 static int avs_dai_hda_be_trigger(struct snd_pcm_substream *substream, int cmd,
407 struct snd_soc_dai *dai)
409 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
410 struct avs_dma_data *data;
413 dev_dbg(dai->dev, "entry %s cmd=%d\n", __func__, cmd);
415 data = snd_soc_dai_get_dma_data(dai, substream);
418 case SNDRV_PCM_TRIGGER_RESUME:
419 if (rtd->dai_link->ignore_suspend)
422 case SNDRV_PCM_TRIGGER_START:
423 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
424 snd_hdac_ext_stream_start(data->link_stream);
426 ret = avs_path_pause(data->path);
428 dev_err(dai->dev, "pause BE path failed: %d\n", ret);
432 ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO);
434 dev_err(dai->dev, "run BE path failed: %d\n", ret);
437 case SNDRV_PCM_TRIGGER_SUSPEND:
438 if (rtd->dai_link->ignore_suspend)
441 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
442 case SNDRV_PCM_TRIGGER_STOP:
443 ret = avs_path_pause(data->path);
445 dev_err(dai->dev, "pause BE path failed: %d\n", ret);
447 snd_hdac_ext_stream_clear(data->link_stream);
449 ret = avs_path_reset(data->path);
451 dev_err(dai->dev, "reset BE path failed: %d\n", ret);
462 static const struct snd_soc_dai_ops avs_dai_hda_be_ops = {
463 .startup = avs_dai_hda_be_startup,
464 .shutdown = avs_dai_hda_be_shutdown,
465 .hw_params = avs_dai_hda_be_hw_params,
466 .hw_free = avs_dai_hda_be_hw_free,
467 .prepare = avs_dai_hda_be_prepare,
468 .trigger = avs_dai_hda_be_trigger,
471 static int hw_rule_param_size(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)
473 struct snd_interval *interval = hw_param_interval(params, rule->var);
474 struct snd_interval to;
476 snd_interval_any(&to);
477 to.integer = interval->integer;
478 to.max = interval->max;
480 * Commonly 2ms buffer size is used in HDA scenarios whereas 4ms is used
481 * when streaming through GPDMA. Align to the latter to account for both.
483 to.min = params_rate(params) / 1000 * 4;
485 if (rule->var == SNDRV_PCM_HW_PARAM_PERIOD_SIZE)
486 to.min /= params_periods(params);
488 return snd_interval_refine(interval, &to);
491 static int avs_pcm_hw_constraints_init(struct snd_pcm_substream *substream)
493 struct snd_pcm_runtime *runtime = substream->runtime;
496 ret = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
500 /* Avoid wrap-around with wall-clock. */
501 ret = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME, 20, 178000000);
505 /* Adjust buffer and period size based on the audio format. */
506 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, hw_rule_param_size, NULL,
507 SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_CHANNELS,
508 SNDRV_PCM_HW_PARAM_RATE, -1);
509 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, hw_rule_param_size, NULL,
510 SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_CHANNELS,
511 SNDRV_PCM_HW_PARAM_RATE, -1);
516 static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
518 struct hdac_ext_stream *host_stream;
519 struct avs_dma_data *data;
520 struct hdac_bus *bus;
523 ret = avs_pcm_hw_constraints_init(substream);
527 ret = avs_dai_startup(substream, dai);
531 data = snd_soc_dai_get_dma_data(dai, substream);
532 bus = &data->adev->base.core;
534 host_stream = snd_hdac_ext_stream_assign(bus, substream, HDAC_EXT_STREAM_TYPE_HOST);
536 avs_dai_shutdown(substream, dai);
540 data->host_stream = host_stream;
541 snd_pcm_set_sync(substream);
543 dev_dbg(dai->dev, "%s fe STARTUP tag %d str %p",
544 __func__, hdac_stream(host_stream)->stream_tag, substream);
549 static void avs_dai_fe_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
551 struct avs_dma_data *data;
553 data = snd_soc_dai_get_dma_data(dai, substream);
555 snd_hdac_ext_stream_release(data->host_stream, HDAC_EXT_STREAM_TYPE_HOST);
556 avs_dai_shutdown(substream, dai);
559 static int avs_dai_fe_hw_params(struct snd_pcm_substream *substream,
560 struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai)
562 struct snd_pcm_hw_params *be_hw_params = NULL;
563 struct snd_soc_pcm_runtime *fe, *be;
564 struct snd_soc_dpcm *dpcm;
565 struct avs_dma_data *data;
566 struct hdac_ext_stream *host_stream;
569 data = snd_soc_dai_get_dma_data(dai, substream);
573 host_stream = data->host_stream;
575 hdac_stream(host_stream)->bufsize = 0;
576 hdac_stream(host_stream)->period_bytes = 0;
577 hdac_stream(host_stream)->format_val = 0;
579 fe = snd_soc_substream_to_rtd(substream);
580 /* dpcm_fe_dai_open() guarantees the list is not empty at this point. */
581 for_each_dpcm_be(fe, substream->stream, dpcm) {
583 be_hw_params = &be->dpcm[substream->stream].hw_params;
586 ret = avs_dai_hw_params(substream, hw_params, be_hw_params, dai,
587 hdac_stream(host_stream)->stream_tag - 1);
591 ret = avs_path_bind(data->path);
593 dev_err(dai->dev, "bind FE <-> BE failed: %d\n", ret);
600 avs_path_free(data->path);
603 snd_pcm_lib_free_pages(substream);
607 static int __avs_dai_fe_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
609 struct avs_dma_data *data;
610 struct hdac_ext_stream *host_stream;
613 dev_dbg(dai->dev, "%s fe HW_FREE str %p rtd %p",
614 __func__, substream, substream->runtime);
616 data = snd_soc_dai_get_dma_data(dai, substream);
620 host_stream = data->host_stream;
622 ret = avs_path_unbind(data->path);
624 dev_err(dai->dev, "unbind FE <-> BE failed: %d\n", ret);
626 avs_path_free(data->path);
628 snd_hdac_stream_cleanup(hdac_stream(host_stream));
629 hdac_stream(host_stream)->prepared = false;
634 static int avs_dai_fe_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
638 ret = __avs_dai_fe_hw_free(substream, dai);
639 snd_pcm_lib_free_pages(substream);
644 static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
646 struct snd_pcm_runtime *runtime = substream->runtime;
647 const struct snd_soc_pcm_stream *stream_info;
648 struct avs_dma_data *data;
649 struct hdac_ext_stream *host_stream;
650 unsigned int format_val;
651 struct hdac_bus *bus;
655 data = snd_soc_dai_get_dma_data(dai, substream);
656 host_stream = data->host_stream;
658 if (hdac_stream(host_stream)->prepared)
661 bus = hdac_stream(host_stream)->bus;
662 snd_hdac_ext_stream_decouple(bus, data->host_stream, true);
663 snd_hdac_stream_reset(hdac_stream(host_stream));
665 stream_info = snd_soc_dai_get_pcm_stream(dai, substream->stream);
666 bits = snd_hdac_stream_format_bits(runtime->format, runtime->subformat,
667 stream_info->sig_bits);
668 format_val = snd_hdac_stream_format(runtime->channels, bits, runtime->rate);
670 ret = snd_hdac_stream_set_params(hdac_stream(host_stream), format_val);
674 ret = snd_hdac_ext_host_stream_setup(host_stream, false);
678 ret = avs_dai_prepare(substream, dai);
682 hdac_stream(host_stream)->prepared = true;
686 static void avs_hda_stream_start(struct hdac_bus *bus, struct hdac_ext_stream *host_stream)
688 struct hdac_stream *first_running = NULL;
689 struct hdac_stream *pos;
690 struct avs_dev *adev = hdac_to_avs(bus);
692 list_for_each_entry(pos, &bus->stream_list, list) {
695 break; /* more than one running */
701 * If host_stream is a CAPTURE stream and will be the only one running,
702 * disable L1SEN to avoid sound clipping.
704 if (!first_running) {
705 if (hdac_stream(host_stream)->direction == SNDRV_PCM_STREAM_CAPTURE)
706 avs_hda_l1sen_enable(adev, false);
707 snd_hdac_stream_start(hdac_stream(host_stream));
711 snd_hdac_stream_start(hdac_stream(host_stream));
713 * If host_stream is the first stream to break the rule above,
716 if (list_entry_is_head(pos, &bus->stream_list, list) &&
717 first_running->direction == SNDRV_PCM_STREAM_CAPTURE)
718 avs_hda_l1sen_enable(adev, true);
721 static void avs_hda_stream_stop(struct hdac_bus *bus, struct hdac_ext_stream *host_stream)
723 struct hdac_stream *first_running = NULL;
724 struct hdac_stream *pos;
725 struct avs_dev *adev = hdac_to_avs(bus);
727 list_for_each_entry(pos, &bus->stream_list, list) {
728 if (pos == hdac_stream(host_stream))
729 continue; /* ignore stream that is about to be stopped */
732 break; /* more than one running */
738 * If host_stream is a CAPTURE stream and is the only one running,
741 if (!first_running) {
742 snd_hdac_stream_stop(hdac_stream(host_stream));
743 if (hdac_stream(host_stream)->direction == SNDRV_PCM_STREAM_CAPTURE)
744 avs_hda_l1sen_enable(adev, true);
749 * If by stopping host_stream there is only a single, CAPTURE stream running
750 * left, disable L1SEN to avoid sound clipping.
752 if (list_entry_is_head(pos, &bus->stream_list, list) &&
753 first_running->direction == SNDRV_PCM_STREAM_CAPTURE)
754 avs_hda_l1sen_enable(adev, false);
756 snd_hdac_stream_stop(hdac_stream(host_stream));
759 static int avs_dai_fe_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai)
761 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
762 struct avs_dma_data *data;
763 struct hdac_ext_stream *host_stream;
764 struct hdac_bus *bus;
768 data = snd_soc_dai_get_dma_data(dai, substream);
769 host_stream = data->host_stream;
770 bus = hdac_stream(host_stream)->bus;
773 case SNDRV_PCM_TRIGGER_RESUME:
774 if (rtd->dai_link->ignore_suspend)
777 case SNDRV_PCM_TRIGGER_START:
778 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
779 spin_lock_irqsave(&bus->reg_lock, flags);
780 avs_hda_stream_start(bus, host_stream);
781 spin_unlock_irqrestore(&bus->reg_lock, flags);
783 /* Timeout on DRSM poll shall not stop the resume so ignore the result. */
784 if (cmd == SNDRV_PCM_TRIGGER_RESUME)
785 snd_hdac_stream_wait_drsm(hdac_stream(host_stream));
787 ret = avs_path_pause(data->path);
789 dev_err(dai->dev, "pause FE path failed: %d\n", ret);
793 ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO);
795 dev_err(dai->dev, "run FE path failed: %d\n", ret);
799 case SNDRV_PCM_TRIGGER_SUSPEND:
800 if (rtd->dai_link->ignore_suspend)
803 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
804 case SNDRV_PCM_TRIGGER_STOP:
805 ret = avs_path_pause(data->path);
807 dev_err(dai->dev, "pause FE path failed: %d\n", ret);
809 spin_lock_irqsave(&bus->reg_lock, flags);
810 avs_hda_stream_stop(bus, host_stream);
811 spin_unlock_irqrestore(&bus->reg_lock, flags);
813 ret = avs_path_reset(data->path);
815 dev_err(dai->dev, "reset FE path failed: %d\n", ret);
826 const struct snd_soc_dai_ops avs_dai_fe_ops = {
827 .startup = avs_dai_fe_startup,
828 .shutdown = avs_dai_fe_shutdown,
829 .hw_params = avs_dai_fe_hw_params,
830 .hw_free = avs_dai_fe_hw_free,
831 .prepare = avs_dai_fe_prepare,
832 .trigger = avs_dai_fe_trigger,
835 static ssize_t topology_name_read(struct file *file, char __user *user_buf, size_t count,
838 struct snd_soc_component *component = file->private_data;
839 struct snd_soc_card *card = component->card;
840 struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev);
844 len = scnprintf(buf, sizeof(buf), "%s/%s\n", component->driver->topology_name_prefix,
845 mach->tplg_filename);
847 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
850 static const struct file_operations topology_name_fops = {
852 .read = topology_name_read,
853 .llseek = default_llseek,
856 static int avs_component_load_libraries(struct avs_soc_component *acomp)
858 struct avs_tplg *tplg = acomp->tplg;
859 struct avs_dev *adev = to_avs_dev(acomp->base.dev);
865 /* Parent device may be asleep and library loading involves IPCs. */
866 ret = pm_runtime_resume_and_get(adev->dev);
870 avs_hda_power_gating_enable(adev, false);
871 avs_hda_clock_gating_enable(adev, false);
872 avs_hda_l1sen_enable(adev, false);
874 ret = avs_dsp_load_libraries(adev, tplg->libs, tplg->num_libs);
876 avs_hda_l1sen_enable(adev, true);
877 avs_hda_clock_gating_enable(adev, true);
878 avs_hda_power_gating_enable(adev, true);
881 ret = avs_module_info_init(adev, false);
883 pm_runtime_mark_last_busy(adev->dev);
884 pm_runtime_put_autosuspend(adev->dev);
889 static int avs_component_probe(struct snd_soc_component *component)
891 struct snd_soc_card *card = component->card;
892 struct snd_soc_acpi_mach *mach;
893 struct avs_soc_component *acomp;
894 struct avs_dev *adev;
898 dev_dbg(card->dev, "probing %s card %s\n", component->name, card->name);
899 mach = dev_get_platdata(card->dev);
900 acomp = to_avs_soc_component(component);
901 adev = to_avs_dev(component->dev);
903 acomp->tplg = avs_tplg_new(component);
907 if (!mach->tplg_filename)
910 /* Load specified topology and create debugfs for it. */
911 filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
912 mach->tplg_filename);
916 ret = avs_load_topology(component, filename);
918 if (ret == -ENOENT && !strncmp(mach->tplg_filename, "hda-", 4)) {
919 unsigned int vendor_id;
921 if (sscanf(mach->tplg_filename, "hda-%08x-tplg.bin", &vendor_id) != 1)
924 if (((vendor_id >> 16) & 0xFFFF) == 0x8086)
925 mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
926 "hda-8086-generic-tplg.bin");
928 mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL,
929 "hda-generic-tplg.bin");
931 filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix,
932 mach->tplg_filename);
936 dev_info(card->dev, "trying to load fallback topology %s\n", mach->tplg_filename);
937 ret = avs_load_topology(component, filename);
943 ret = avs_component_load_libraries(acomp);
945 dev_err(card->dev, "libraries loading failed: %d\n", ret);
950 debugfs_create_file("topology_name", 0444, component->debugfs_root, component,
951 &topology_name_fops);
953 mutex_lock(&adev->comp_list_mutex);
954 list_add_tail(&acomp->node, &adev->comp_list);
955 mutex_unlock(&adev->comp_list_mutex);
960 avs_remove_topology(component);
964 static void avs_component_remove(struct snd_soc_component *component)
966 struct avs_soc_component *acomp = to_avs_soc_component(component);
967 struct snd_soc_acpi_mach *mach;
968 struct avs_dev *adev = to_avs_dev(component->dev);
971 mach = dev_get_platdata(component->card->dev);
973 mutex_lock(&adev->comp_list_mutex);
974 list_del(&acomp->node);
975 mutex_unlock(&adev->comp_list_mutex);
977 if (mach->tplg_filename) {
978 ret = avs_remove_topology(component);
980 dev_err(component->dev, "unload topology failed: %d\n", ret);
984 static int avs_dai_resume_hw_params(struct snd_soc_dai *dai, struct avs_dma_data *data)
986 struct snd_pcm_substream *substream;
987 struct snd_soc_pcm_runtime *rtd;
990 substream = data->substream;
991 rtd = snd_soc_substream_to_rtd(substream);
993 ret = dai->driver->ops->hw_params(substream, &rtd->dpcm[substream->stream].hw_params, dai);
995 dev_err(dai->dev, "hw_params on resume failed: %d\n", ret);
1000 static int avs_dai_resume_fe_prepare(struct snd_soc_dai *dai, struct avs_dma_data *data)
1002 struct hdac_ext_stream *host_stream;
1003 struct hdac_stream *hstream;
1004 struct hdac_bus *bus;
1007 host_stream = data->host_stream;
1008 hstream = hdac_stream(host_stream);
1009 bus = hdac_stream(host_stream)->bus;
1011 /* Set DRSM before programming stream and position registers. */
1012 snd_hdac_stream_drsm_enable(bus, true, hstream->index);
1014 ret = dai->driver->ops->prepare(data->substream, dai);
1016 dev_err(dai->dev, "prepare FE on resume failed: %d\n", ret);
1020 writel(host_stream->pphcllpl, host_stream->pphc_addr + AZX_REG_PPHCLLPL);
1021 writel(host_stream->pphcllpu, host_stream->pphc_addr + AZX_REG_PPHCLLPU);
1022 writel(host_stream->pphcldpl, host_stream->pphc_addr + AZX_REG_PPHCLDPL);
1023 writel(host_stream->pphcldpu, host_stream->pphc_addr + AZX_REG_PPHCLDPU);
1025 /* As per HW spec recommendation, program LPIB and DPIB to the same value. */
1026 snd_hdac_stream_set_lpib(hstream, hstream->lpib);
1027 snd_hdac_stream_set_dpibr(bus, hstream, hstream->lpib);
1032 static int avs_dai_resume_be_prepare(struct snd_soc_dai *dai, struct avs_dma_data *data)
1036 ret = dai->driver->ops->prepare(data->substream, dai);
1038 dev_err(dai->dev, "prepare BE on resume failed: %d\n", ret);
1043 static int avs_dai_suspend_fe_hw_free(struct snd_soc_dai *dai, struct avs_dma_data *data)
1045 struct hdac_ext_stream *host_stream;
1048 host_stream = data->host_stream;
1050 /* Store position addresses so we can resume from them later on. */
1051 hdac_stream(host_stream)->lpib = snd_hdac_stream_get_pos_lpib(hdac_stream(host_stream));
1052 host_stream->pphcllpl = readl(host_stream->pphc_addr + AZX_REG_PPHCLLPL);
1053 host_stream->pphcllpu = readl(host_stream->pphc_addr + AZX_REG_PPHCLLPU);
1054 host_stream->pphcldpl = readl(host_stream->pphc_addr + AZX_REG_PPHCLDPL);
1055 host_stream->pphcldpu = readl(host_stream->pphc_addr + AZX_REG_PPHCLDPU);
1057 ret = __avs_dai_fe_hw_free(data->substream, dai);
1059 dev_err(dai->dev, "hw_free FE on suspend failed: %d\n", ret);
1064 static int avs_dai_suspend_be_hw_free(struct snd_soc_dai *dai, struct avs_dma_data *data)
1068 ret = dai->driver->ops->hw_free(data->substream, dai);
1070 dev_err(dai->dev, "hw_free BE on suspend failed: %d\n", ret);
1075 static int avs_component_pm_op(struct snd_soc_component *component, bool be,
1076 int (*op)(struct snd_soc_dai *, struct avs_dma_data *))
1078 struct snd_soc_pcm_runtime *rtd;
1079 struct avs_dma_data *data;
1080 struct snd_soc_dai *dai;
1083 for_each_component_dais(component, dai) {
1084 data = snd_soc_dai_dma_data_get_playback(dai);
1086 rtd = snd_soc_substream_to_rtd(data->substream);
1087 if (rtd->dai_link->no_pcm == be && !rtd->dai_link->ignore_suspend) {
1088 ret = op(dai, data);
1090 __snd_pcm_set_state(data->substream->runtime,
1091 SNDRV_PCM_STATE_DISCONNECTED);
1097 data = snd_soc_dai_dma_data_get_capture(dai);
1099 rtd = snd_soc_substream_to_rtd(data->substream);
1100 if (rtd->dai_link->no_pcm == be && !rtd->dai_link->ignore_suspend) {
1101 ret = op(dai, data);
1103 __snd_pcm_set_state(data->substream->runtime,
1104 SNDRV_PCM_STATE_DISCONNECTED);
1114 static int avs_component_resume_hw_params(struct snd_soc_component *component, bool be)
1116 return avs_component_pm_op(component, be, &avs_dai_resume_hw_params);
1119 static int avs_component_resume_prepare(struct snd_soc_component *component, bool be)
1121 int (*prepare_cb)(struct snd_soc_dai *dai, struct avs_dma_data *data);
1124 prepare_cb = &avs_dai_resume_be_prepare;
1126 prepare_cb = &avs_dai_resume_fe_prepare;
1128 return avs_component_pm_op(component, be, prepare_cb);
1131 static int avs_component_suspend_hw_free(struct snd_soc_component *component, bool be)
1133 int (*hw_free_cb)(struct snd_soc_dai *dai, struct avs_dma_data *data);
1136 hw_free_cb = &avs_dai_suspend_be_hw_free;
1138 hw_free_cb = &avs_dai_suspend_fe_hw_free;
1140 return avs_component_pm_op(component, be, hw_free_cb);
1143 static int avs_component_suspend(struct snd_soc_component *component)
1148 * When freeing paths, FEs need to be first as they perform
1151 ret = avs_component_suspend_hw_free(component, false);
1155 return avs_component_suspend_hw_free(component, true);
1158 static int avs_component_resume(struct snd_soc_component *component)
1163 * When creating paths, FEs need to be last as they perform
1166 ret = avs_component_resume_hw_params(component, true);
1170 ret = avs_component_resume_hw_params(component, false);
1174 /* It is expected that the LINK stream is prepared first. */
1175 ret = avs_component_resume_prepare(component, true);
1179 return avs_component_resume_prepare(component, false);
1182 static const struct snd_pcm_hardware avs_pcm_hardware = {
1183 .info = SNDRV_PCM_INFO_MMAP |
1184 SNDRV_PCM_INFO_MMAP_VALID |
1185 SNDRV_PCM_INFO_INTERLEAVED |
1186 SNDRV_PCM_INFO_PAUSE |
1187 SNDRV_PCM_INFO_RESUME |
1188 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
1189 .formats = SNDRV_PCM_FMTBIT_S16_LE |
1190 SNDRV_PCM_FMTBIT_S32_LE,
1191 .subformats = SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1192 SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1193 SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1194 .buffer_bytes_max = AZX_MAX_BUF_SIZE,
1195 .period_bytes_min = 128,
1196 .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
1198 .periods_max = AZX_MAX_FRAG,
1202 static int avs_component_open(struct snd_soc_component *component,
1203 struct snd_pcm_substream *substream)
1205 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
1207 /* only FE DAI links are handled here */
1208 if (rtd->dai_link->no_pcm)
1211 return snd_soc_set_runtime_hwparams(substream, &avs_pcm_hardware);
1214 static unsigned int avs_hda_stream_dpib_read(struct hdac_ext_stream *stream)
1216 return readl(hdac_stream(stream)->bus->remap_addr + AZX_REG_VS_SDXDPIB_XBASE +
1217 (AZX_REG_VS_SDXDPIB_XINTERVAL * hdac_stream(stream)->index));
1220 static snd_pcm_uframes_t
1221 avs_component_pointer(struct snd_soc_component *component, struct snd_pcm_substream *substream)
1223 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
1224 struct avs_dma_data *data;
1225 struct hdac_ext_stream *host_stream;
1228 data = snd_soc_dai_get_dma_data(snd_soc_rtd_to_cpu(rtd, 0), substream);
1229 if (!data->host_stream)
1232 host_stream = data->host_stream;
1233 pos = avs_hda_stream_dpib_read(host_stream);
1235 if (pos >= hdac_stream(host_stream)->bufsize)
1238 return bytes_to_frames(substream->runtime, pos);
1241 static int avs_component_mmap(struct snd_soc_component *component,
1242 struct snd_pcm_substream *substream,
1243 struct vm_area_struct *vma)
1245 return snd_pcm_lib_default_mmap(substream, vma);
1248 #define MAX_PREALLOC_SIZE (32 * 1024 * 1024)
1250 static int avs_component_construct(struct snd_soc_component *component,
1251 struct snd_soc_pcm_runtime *rtd)
1253 struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0);
1254 struct snd_pcm *pcm = rtd->pcm;
1256 if (dai->driver->playback.channels_min)
1257 snd_pcm_set_managed_buffer(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
1258 SNDRV_DMA_TYPE_DEV_SG, component->dev, 0,
1261 if (dai->driver->capture.channels_min)
1262 snd_pcm_set_managed_buffer(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
1263 SNDRV_DMA_TYPE_DEV_SG, component->dev, 0,
1269 static const struct snd_soc_component_driver avs_component_driver = {
1271 .probe = avs_component_probe,
1272 .remove = avs_component_remove,
1273 .suspend = avs_component_suspend,
1274 .resume = avs_component_resume,
1275 .open = avs_component_open,
1276 .pointer = avs_component_pointer,
1277 .mmap = avs_component_mmap,
1278 .pcm_construct = avs_component_construct,
1279 .module_get_upon_open = 1, /* increment refcount when a pcm is opened */
1280 .topology_name_prefix = "intel/avs",
1283 int avs_soc_component_register(struct device *dev, const char *name,
1284 const struct snd_soc_component_driver *drv,
1285 struct snd_soc_dai_driver *cpu_dais, int num_cpu_dais)
1287 struct avs_soc_component *acomp;
1290 acomp = devm_kzalloc(dev, sizeof(*acomp), GFP_KERNEL);
1294 ret = snd_soc_component_initialize(&acomp->base, drv, dev);
1298 /* force name change after ASoC is done with its init */
1299 acomp->base.name = name;
1300 INIT_LIST_HEAD(&acomp->node);
1302 return snd_soc_add_component(&acomp->base, cpu_dais, num_cpu_dais);
1305 static struct snd_soc_dai_driver dmic_cpu_dais[] = {
1308 .ops = &avs_dai_nonhda_be_ops,
1310 .stream_name = "DMIC Rx",
1313 .rates = SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_48000,
1314 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
1318 .name = "DMIC WoV Pin",
1319 .ops = &avs_dai_nonhda_be_ops,
1321 .stream_name = "DMIC WoV Rx",
1324 .rates = SNDRV_PCM_RATE_16000,
1325 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1330 int avs_dmic_platform_register(struct avs_dev *adev, const char *name)
1332 return avs_soc_component_register(adev->dev, name, &avs_component_driver, dmic_cpu_dais,
1333 ARRAY_SIZE(dmic_cpu_dais));
1336 static const struct snd_soc_dai_driver i2s_dai_template = {
1337 .ops = &avs_dai_nonhda_be_ops,
1341 .rates = SNDRV_PCM_RATE_8000_192000 |
1342 SNDRV_PCM_RATE_12000 |
1343 SNDRV_PCM_RATE_24000 |
1344 SNDRV_PCM_RATE_128000,
1345 .formats = SNDRV_PCM_FMTBIT_S16_LE |
1346 SNDRV_PCM_FMTBIT_S32_LE,
1347 .subformats = SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1348 SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1349 SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1354 .rates = SNDRV_PCM_RATE_8000_192000 |
1355 SNDRV_PCM_RATE_12000 |
1356 SNDRV_PCM_RATE_24000 |
1357 SNDRV_PCM_RATE_128000,
1358 .formats = SNDRV_PCM_FMTBIT_S16_LE |
1359 SNDRV_PCM_FMTBIT_S32_LE,
1360 .subformats = SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1361 SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1362 SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1366 int avs_i2s_platform_register(struct avs_dev *adev, const char *name, unsigned long port_mask,
1367 unsigned long *tdms)
1369 struct snd_soc_dai_driver *cpus, *dai;
1370 size_t ssp_count, cpu_count;
1373 ssp_count = adev->hw_cfg.i2s_caps.ctrl_count;
1376 for_each_set_bit(i, &port_mask, ssp_count)
1377 if (!tdms || test_bit(0, &tdms[i]))
1380 for_each_set_bit(i, &port_mask, ssp_count)
1381 cpu_count += hweight_long(tdms[i]);
1383 cpus = devm_kzalloc(adev->dev, sizeof(*cpus) * cpu_count, GFP_KERNEL);
1388 for_each_set_bit(i, &port_mask, ssp_count) {
1389 if (!tdms || test_bit(0, &tdms[i])) {
1390 memcpy(dai, &i2s_dai_template, sizeof(*dai));
1393 devm_kasprintf(adev->dev, GFP_KERNEL, "SSP%d Pin", i);
1394 dai->playback.stream_name =
1395 devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d Tx", i);
1396 dai->capture.stream_name =
1397 devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d Rx", i);
1399 if (!dai->name || !dai->playback.stream_name || !dai->capture.stream_name)
1408 for_each_set_bit(i, &port_mask, ssp_count) {
1409 for_each_set_bit(j, &tdms[i], ssp_count) {
1410 memcpy(dai, &i2s_dai_template, sizeof(*dai));
1413 devm_kasprintf(adev->dev, GFP_KERNEL, "SSP%d:%d Pin", i, j);
1414 dai->playback.stream_name =
1415 devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d:%d Tx", i, j);
1416 dai->capture.stream_name =
1417 devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d:%d Rx", i, j);
1419 if (!dai->name || !dai->playback.stream_name || !dai->capture.stream_name)
1426 return avs_soc_component_register(adev->dev, name, &avs_component_driver, cpus, cpu_count);
1429 /* HD-Audio CPU DAI template */
1430 static const struct snd_soc_dai_driver hda_cpu_dai = {
1431 .ops = &avs_dai_hda_be_ops,
1435 .rates = SNDRV_PCM_RATE_8000_192000,
1436 .formats = SNDRV_PCM_FMTBIT_S16_LE |
1437 SNDRV_PCM_FMTBIT_S32_LE,
1438 .subformats = SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1439 SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1440 SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1445 .rates = SNDRV_PCM_RATE_8000_192000,
1446 .formats = SNDRV_PCM_FMTBIT_S16_LE |
1447 SNDRV_PCM_FMTBIT_S32_LE,
1448 .subformats = SNDRV_PCM_SUBFMTBIT_MSBITS_20 |
1449 SNDRV_PCM_SUBFMTBIT_MSBITS_24 |
1450 SNDRV_PCM_SUBFMTBIT_MSBITS_MAX,
1454 static void avs_component_hda_unregister_dais(struct snd_soc_component *component)
1456 struct snd_soc_acpi_mach *mach;
1457 struct snd_soc_dai *dai, *save;
1458 struct hda_codec *codec;
1461 mach = dev_get_platdata(component->card->dev);
1462 codec = mach->pdata;
1463 snprintf(name, sizeof(name), "%s-cpu", dev_name(&codec->core.dev));
1465 for_each_component_dais_safe(component, dai, save) {
1468 if (!strstr(dai->driver->name, name))
1471 for_each_pcm_streams(stream)
1472 snd_soc_dapm_free_widget(snd_soc_dai_get_widget(dai, stream));
1474 snd_soc_unregister_dai(dai);
1478 static int avs_component_hda_probe(struct snd_soc_component *component)
1480 struct snd_soc_dapm_context *dapm;
1481 struct snd_soc_dai_driver *dais;
1482 struct snd_soc_acpi_mach *mach;
1483 struct hda_codec *codec;
1484 struct hda_pcm *pcm;
1486 int pcm_count = 0, ret, i;
1488 mach = dev_get_platdata(component->card->dev);
1492 codec = mach->pdata;
1493 if (list_empty(&codec->pcm_list_head))
1495 list_for_each_entry(pcm, &codec->pcm_list_head, list)
1498 dais = devm_kcalloc(component->dev, pcm_count, sizeof(*dais),
1503 cname = dev_name(&codec->core.dev);
1504 dapm = snd_soc_component_get_dapm(component);
1505 pcm = list_first_entry(&codec->pcm_list_head, struct hda_pcm, list);
1507 for (i = 0; i < pcm_count; i++, pcm = list_next_entry(pcm, list)) {
1508 struct snd_soc_dai *dai;
1510 memcpy(&dais[i], &hda_cpu_dai, sizeof(*dais));
1512 dais[i].name = devm_kasprintf(component->dev, GFP_KERNEL,
1513 "%s-cpu%d", cname, i);
1514 if (!dais[i].name) {
1519 if (pcm->stream[0].substreams) {
1520 dais[i].playback.stream_name =
1521 devm_kasprintf(component->dev, GFP_KERNEL,
1522 "%s-cpu%d Tx", cname, i);
1523 if (!dais[i].playback.stream_name) {
1528 if (!hda_codec_is_display(codec)) {
1529 dais[i].playback.formats = pcm->stream[0].formats;
1530 dais[i].playback.subformats = pcm->stream[0].subformats;
1531 dais[i].playback.rates = pcm->stream[0].rates;
1532 dais[i].playback.channels_min = pcm->stream[0].channels_min;
1533 dais[i].playback.channels_max = pcm->stream[0].channels_max;
1534 dais[i].playback.sig_bits = pcm->stream[0].maxbps;
1538 if (pcm->stream[1].substreams) {
1539 dais[i].capture.stream_name =
1540 devm_kasprintf(component->dev, GFP_KERNEL,
1541 "%s-cpu%d Rx", cname, i);
1542 if (!dais[i].capture.stream_name) {
1547 if (!hda_codec_is_display(codec)) {
1548 dais[i].capture.formats = pcm->stream[1].formats;
1549 dais[i].capture.subformats = pcm->stream[1].subformats;
1550 dais[i].capture.rates = pcm->stream[1].rates;
1551 dais[i].capture.channels_min = pcm->stream[1].channels_min;
1552 dais[i].capture.channels_max = pcm->stream[1].channels_max;
1553 dais[i].capture.sig_bits = pcm->stream[1].maxbps;
1557 dai = snd_soc_register_dai(component, &dais[i], false);
1559 dev_err(component->dev, "register dai for %s failed\n",
1565 ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
1567 dev_err(component->dev, "create widgets failed: %d\n",
1569 snd_soc_unregister_dai(dai);
1574 ret = avs_component_probe(component);
1577 avs_component_hda_unregister_dais(component);
1582 static void avs_component_hda_remove(struct snd_soc_component *component)
1584 avs_component_remove(component);
1585 avs_component_hda_unregister_dais(component);
1588 static int avs_component_hda_open(struct snd_soc_component *component,
1589 struct snd_pcm_substream *substream)
1591 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
1593 if (!rtd->dai_link->no_pcm) {
1594 struct snd_pcm_hardware hwparams = avs_pcm_hardware;
1595 struct snd_soc_pcm_runtime *be;
1596 struct snd_soc_dpcm *dpcm;
1597 int dir = substream->stream;
1600 * Support the DPCM reparenting while still fulfilling expectations of HDAudio
1601 * common code - a valid stream pointer at substream->runtime->private_data -
1602 * by having all FEs point to the same private data.
1604 for_each_dpcm_be(rtd, dir, dpcm) {
1605 struct snd_pcm_substream *be_substream;
1608 if (be->dpcm[dir].users == 1)
1611 be_substream = snd_soc_dpcm_get_substream(be, dir);
1612 substream->runtime->private_data = be_substream->runtime->private_data;
1616 /* RESUME unsupported for de-coupled HD-Audio capture. */
1617 if (dir == SNDRV_PCM_STREAM_CAPTURE)
1618 hwparams.info &= ~SNDRV_PCM_INFO_RESUME;
1620 return snd_soc_set_runtime_hwparams(substream, &hwparams);
1626 static const struct snd_soc_component_driver avs_hda_component_driver = {
1627 .name = "avs-hda-pcm",
1628 .probe = avs_component_hda_probe,
1629 .remove = avs_component_hda_remove,
1630 .suspend = avs_component_suspend,
1631 .resume = avs_component_resume,
1632 .open = avs_component_hda_open,
1633 .pointer = avs_component_pointer,
1634 .mmap = avs_component_mmap,
1635 .pcm_construct = avs_component_construct,
1637 * hda platform component's probe() is dependent on
1638 * codec->pcm_list_head, it needs to be initialized after codec
1639 * component. remove_order is here for completeness sake
1641 .probe_order = SND_SOC_COMP_ORDER_LATE,
1642 .remove_order = SND_SOC_COMP_ORDER_EARLY,
1643 .module_get_upon_open = 1,
1644 .topology_name_prefix = "intel/avs",
1647 int avs_hda_platform_register(struct avs_dev *adev, const char *name)
1649 return avs_soc_component_register(adev->dev, name,
1650 &avs_hda_component_driver, NULL, 0);