Lines Matching +full:fe +full:- +full:dai +full:- +full:link

1 // SPDX-License-Identifier: GPL-2.0-only
3 // Copyright(c) 2021-2022 Intel Corporation
14 #include <sound/soc-acpi.h>
15 #include <sound/soc-acpi-intel-match.h>
16 #include <sound/soc-component.h>
28 /* LINK-stream utilized in BE operations while HOST in FE ones. */
39 avs_dai_find_path_template(struct snd_soc_dai *dai, bool is_fe, int direction) in avs_dai_find_path_template() argument
41 struct snd_soc_dapm_widget *dw = snd_soc_dai_get_widget(dai, direction); in avs_dai_find_path_template()
51 dp = list_first_entry_or_null(&dw->edges[dir], typeof(*dp), list_node[dir]); in avs_dai_find_path_template()
56 dw = (dp->source == dw) ? dp->sink : dp->source; in avs_dai_find_path_template()
58 return dw->priv; in avs_dai_find_path_template()
65 snd_pcm_period_elapsed(data->substream); in avs_period_elapsed_work()
71 struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0); in avs_period_elapsed() local
72 struct avs_dma_data *data = snd_soc_dai_get_dma_data(dai, substream); in avs_period_elapsed()
74 schedule_work(&data->period_elapsed_work); in avs_period_elapsed()
77 static int avs_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_startup() argument
80 struct avs_dev *adev = to_avs_dev(dai->component->dev); in avs_dai_startup()
84 template = avs_dai_find_path_template(dai, !rtd->dai_link->no_pcm, substream->stream); in avs_dai_startup()
86 dev_err(dai->dev, "no %s path for dai %s, invalid tplg?\n", in avs_dai_startup()
87 snd_pcm_stream_str(substream), dai->name); in avs_dai_startup()
88 return -EINVAL; in avs_dai_startup()
93 return -ENOMEM; in avs_dai_startup()
95 data->substream = substream; in avs_dai_startup()
96 data->template = template; in avs_dai_startup()
97 data->adev = adev; in avs_dai_startup()
98 INIT_WORK(&data->period_elapsed_work, avs_period_elapsed_work); in avs_dai_startup()
99 snd_soc_dai_set_dma_data(dai, substream, data); in avs_dai_startup()
101 if (rtd->dai_link->ignore_suspend) in avs_dai_startup()
102 adev->num_lp_paths++; in avs_dai_startup()
107 static void avs_dai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_shutdown() argument
112 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_shutdown()
114 if (rtd->dai_link->ignore_suspend) in avs_dai_shutdown()
115 data->adev->num_lp_paths--; in avs_dai_shutdown()
117 snd_soc_dai_set_dma_data(dai, substream, NULL); in avs_dai_shutdown()
123 struct snd_pcm_hw_params *be_hw_params, struct snd_soc_dai *dai, in avs_dai_hw_params() argument
130 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_hw_params()
132 dev_dbg(dai->dev, "%s FE hw_params str %p rtd %p", in avs_dai_hw_params()
133 __func__, substream, substream->runtime); in avs_dai_hw_params()
134 dev_dbg(dai->dev, "rate %d chn %d vbd %d bd %d\n", in avs_dai_hw_params()
138 dev_dbg(dai->dev, "%s BE hw_params str %p rtd %p", in avs_dai_hw_params()
139 __func__, substream, substream->runtime); in avs_dai_hw_params()
140 dev_dbg(dai->dev, "rate %d chn %d vbd %d bd %d\n", in avs_dai_hw_params()
144 path = avs_path_create(data->adev, dma_id, data->template, fe_hw_params, be_hw_params); in avs_dai_hw_params()
147 dev_err(dai->dev, "create path failed: %d\n", ret); in avs_dai_hw_params()
151 data->path = path; in avs_dai_hw_params()
156 struct snd_pcm_hw_params *be_hw_params, struct snd_soc_dai *dai, in avs_dai_be_hw_params() argument
160 struct snd_soc_pcm_runtime *fe, *be; in avs_dai_be_hw_params() local
164 for_each_dpcm_fe(be, substream->stream, dpcm) { in avs_dai_be_hw_params()
165 fe = dpcm->fe; in avs_dai_be_hw_params()
166 fe_hw_params = &fe->dpcm[substream->stream].hw_params; in avs_dai_be_hw_params()
169 return avs_dai_hw_params(substream, fe_hw_params, be_hw_params, dai, dma_id); in avs_dai_be_hw_params()
172 static int avs_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_prepare() argument
177 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_prepare()
178 if (!data->path) in avs_dai_prepare()
181 ret = avs_path_reset(data->path); in avs_dai_prepare()
183 dev_err(dai->dev, "reset path failed: %d\n", ret); in avs_dai_prepare()
187 ret = avs_path_pause(data->path); in avs_dai_prepare()
189 dev_err(dai->dev, "pause path failed: %d\n", ret); in avs_dai_prepare()
194 struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai) in avs_dai_nonhda_be_hw_params() argument
198 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_nonhda_be_hw_params()
199 if (data->path) in avs_dai_nonhda_be_hw_params()
202 /* Actual port-id comes from topology. */ in avs_dai_nonhda_be_hw_params()
203 return avs_dai_be_hw_params(substream, hw_params, dai, 0); in avs_dai_nonhda_be_hw_params()
206 static int avs_dai_nonhda_be_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_nonhda_be_hw_free() argument
210 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); in avs_dai_nonhda_be_hw_free()
212 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_nonhda_be_hw_free()
213 if (data->path) { in avs_dai_nonhda_be_hw_free()
214 avs_path_free(data->path); in avs_dai_nonhda_be_hw_free()
215 data->path = NULL; in avs_dai_nonhda_be_hw_free()
222 struct snd_soc_dai *dai) in avs_dai_nonhda_be_trigger() argument
228 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_nonhda_be_trigger()
232 if (rtd->dai_link->ignore_suspend) in avs_dai_nonhda_be_trigger()
237 ret = avs_path_pause(data->path); in avs_dai_nonhda_be_trigger()
239 dev_err(dai->dev, "pause BE path failed: %d\n", ret); in avs_dai_nonhda_be_trigger()
243 ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO); in avs_dai_nonhda_be_trigger()
245 dev_err(dai->dev, "run BE path failed: %d\n", ret); in avs_dai_nonhda_be_trigger()
249 if (rtd->dai_link->ignore_suspend) in avs_dai_nonhda_be_trigger()
254 ret = avs_path_pause(data->path); in avs_dai_nonhda_be_trigger()
256 dev_err(dai->dev, "pause BE path failed: %d\n", ret); in avs_dai_nonhda_be_trigger()
258 ret = avs_path_reset(data->path); in avs_dai_nonhda_be_trigger()
260 dev_err(dai->dev, "reset BE path failed: %d\n", ret); in avs_dai_nonhda_be_trigger()
264 ret = -EINVAL; in avs_dai_nonhda_be_trigger()
280 static int avs_dai_hda_be_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_hda_be_startup() argument
288 ret = avs_dai_startup(substream, dai); in avs_dai_hda_be_startup()
292 codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev); in avs_dai_hda_be_startup()
293 link_stream = snd_hdac_ext_stream_assign(&codec->bus->core, substream, in avs_dai_hda_be_startup()
296 avs_dai_shutdown(substream, dai); in avs_dai_hda_be_startup()
297 return -EBUSY; in avs_dai_hda_be_startup()
300 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_hda_be_startup()
301 data->link_stream = link_stream; in avs_dai_hda_be_startup()
302 substream->runtime->private_data = link_stream; in avs_dai_hda_be_startup()
306 static void avs_dai_hda_be_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_hda_be_shutdown() argument
308 struct avs_dma_data *data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_hda_be_shutdown()
310 snd_hdac_ext_stream_release(data->link_stream, HDAC_EXT_STREAM_TYPE_LINK); in avs_dai_hda_be_shutdown()
311 substream->runtime->private_data = NULL; in avs_dai_hda_be_shutdown()
312 avs_dai_shutdown(substream, dai); in avs_dai_hda_be_shutdown()
316 struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai) in avs_dai_hda_be_hw_params() argument
320 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_hda_be_hw_params()
321 if (data->path) in avs_dai_hda_be_hw_params()
324 return avs_dai_be_hw_params(substream, hw_params, dai, in avs_dai_hda_be_hw_params()
325 hdac_stream(data->link_stream)->stream_tag - 1); in avs_dai_hda_be_hw_params()
328 static int avs_dai_hda_be_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_hda_be_hw_free() argument
333 struct hdac_ext_link *link; in avs_dai_hda_be_hw_free() local
336 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name); in avs_dai_hda_be_hw_free()
338 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_hda_be_hw_free()
339 if (!data->path) in avs_dai_hda_be_hw_free()
342 link_stream = data->link_stream; in avs_dai_hda_be_hw_free()
343 link_stream->link_prepared = false; in avs_dai_hda_be_hw_free()
344 avs_path_free(data->path); in avs_dai_hda_be_hw_free()
345 data->path = NULL; in avs_dai_hda_be_hw_free()
347 /* clear link <-> stream mapping */ in avs_dai_hda_be_hw_free()
348 codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev); in avs_dai_hda_be_hw_free()
349 link = snd_hdac_ext_bus_get_hlink_by_addr(&codec->bus->core, codec->core.addr); in avs_dai_hda_be_hw_free()
350 if (!link) in avs_dai_hda_be_hw_free()
351 return -EINVAL; in avs_dai_hda_be_hw_free()
353 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in avs_dai_hda_be_hw_free()
354 snd_hdac_ext_bus_link_clear_stream_id(link, hdac_stream(link_stream)->stream_tag); in avs_dai_hda_be_hw_free()
359 static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_hda_be_prepare() argument
362 struct snd_pcm_runtime *runtime = substream->runtime; in avs_dai_hda_be_prepare()
365 struct hdac_ext_link *link; in avs_dai_hda_be_prepare() local
373 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_hda_be_prepare()
374 link_stream = data->link_stream; in avs_dai_hda_be_prepare()
376 if (link_stream->link_prepared) in avs_dai_hda_be_prepare()
379 codec = dev_to_hda_codec(snd_soc_rtd_to_codec(rtd, 0)->dev); in avs_dai_hda_be_prepare()
380 bus = &codec->bus->core; in avs_dai_hda_be_prepare()
381 stream_info = snd_soc_dai_get_pcm_stream(dai, substream->stream); in avs_dai_hda_be_prepare()
382 bits = snd_hdac_stream_format_bits(runtime->format, runtime->subformat, in avs_dai_hda_be_prepare()
383 stream_info->sig_bits); in avs_dai_hda_be_prepare()
384 format_val = snd_hdac_stream_format(runtime->channels, bits, runtime->rate); in avs_dai_hda_be_prepare()
390 link = snd_hdac_ext_bus_get_hlink_by_addr(bus, codec->core.addr); in avs_dai_hda_be_prepare()
391 if (!link) in avs_dai_hda_be_prepare()
392 return -EINVAL; in avs_dai_hda_be_prepare()
394 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in avs_dai_hda_be_prepare()
395 snd_hdac_ext_bus_link_set_stream_id(link, hdac_stream(link_stream)->stream_tag); in avs_dai_hda_be_prepare()
397 ret = avs_dai_prepare(substream, dai); in avs_dai_hda_be_prepare()
401 link_stream->link_prepared = true; in avs_dai_hda_be_prepare()
406 struct snd_soc_dai *dai) in avs_dai_hda_be_trigger() argument
412 dev_dbg(dai->dev, "entry %s cmd=%d\n", __func__, cmd); in avs_dai_hda_be_trigger()
414 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_hda_be_trigger()
418 if (rtd->dai_link->ignore_suspend) in avs_dai_hda_be_trigger()
423 snd_hdac_ext_stream_start(data->link_stream); in avs_dai_hda_be_trigger()
425 ret = avs_path_pause(data->path); in avs_dai_hda_be_trigger()
427 dev_err(dai->dev, "pause BE path failed: %d\n", ret); in avs_dai_hda_be_trigger()
431 ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO); in avs_dai_hda_be_trigger()
433 dev_err(dai->dev, "run BE path failed: %d\n", ret); in avs_dai_hda_be_trigger()
437 if (rtd->dai_link->ignore_suspend) in avs_dai_hda_be_trigger()
442 ret = avs_path_pause(data->path); in avs_dai_hda_be_trigger()
444 dev_err(dai->dev, "pause BE path failed: %d\n", ret); in avs_dai_hda_be_trigger()
446 snd_hdac_ext_stream_clear(data->link_stream); in avs_dai_hda_be_trigger()
448 ret = avs_path_reset(data->path); in avs_dai_hda_be_trigger()
450 dev_err(dai->dev, "reset BE path failed: %d\n", ret); in avs_dai_hda_be_trigger()
454 ret = -EINVAL; in avs_dai_hda_be_trigger()
472 struct snd_interval *interval = hw_param_interval(params, rule->var); in hw_rule_param_size()
476 to.integer = interval->integer; in hw_rule_param_size()
477 to.max = interval->max; in hw_rule_param_size()
484 if (rule->var == SNDRV_PCM_HW_PARAM_PERIOD_SIZE) in hw_rule_param_size()
492 struct snd_pcm_runtime *runtime = substream->runtime; in avs_pcm_hw_constraints_init()
499 /* Avoid wrap-around with wall-clock. */ in avs_pcm_hw_constraints_init()
507 SNDRV_PCM_HW_PARAM_RATE, -1); in avs_pcm_hw_constraints_init()
510 SNDRV_PCM_HW_PARAM_RATE, -1); in avs_pcm_hw_constraints_init()
515 static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_fe_startup() argument
526 ret = avs_dai_startup(substream, dai); in avs_dai_fe_startup()
530 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_fe_startup()
531 bus = &data->adev->base.core; in avs_dai_fe_startup()
535 avs_dai_shutdown(substream, dai); in avs_dai_fe_startup()
536 return -EBUSY; in avs_dai_fe_startup()
539 data->host_stream = host_stream; in avs_dai_fe_startup()
542 dev_dbg(dai->dev, "%s fe STARTUP tag %d str %p", in avs_dai_fe_startup()
543 __func__, hdac_stream(host_stream)->stream_tag, substream); in avs_dai_fe_startup()
548 static void avs_dai_fe_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_fe_shutdown() argument
552 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_fe_shutdown()
554 snd_hdac_ext_stream_release(data->host_stream, HDAC_EXT_STREAM_TYPE_HOST); in avs_dai_fe_shutdown()
555 avs_dai_shutdown(substream, dai); in avs_dai_fe_shutdown()
559 struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai) in avs_dai_fe_hw_params() argument
562 struct snd_soc_pcm_runtime *fe, *be; in avs_dai_fe_hw_params() local
568 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_fe_hw_params()
569 if (data->path) in avs_dai_fe_hw_params()
572 host_stream = data->host_stream; in avs_dai_fe_hw_params()
574 hdac_stream(host_stream)->bufsize = 0; in avs_dai_fe_hw_params()
575 hdac_stream(host_stream)->period_bytes = 0; in avs_dai_fe_hw_params()
576 hdac_stream(host_stream)->format_val = 0; in avs_dai_fe_hw_params()
578 fe = snd_soc_substream_to_rtd(substream); in avs_dai_fe_hw_params()
579 for_each_dpcm_be(fe, substream->stream, dpcm) { in avs_dai_fe_hw_params()
580 be = dpcm->be; in avs_dai_fe_hw_params()
581 be_hw_params = &be->dpcm[substream->stream].hw_params; in avs_dai_fe_hw_params()
584 ret = avs_dai_hw_params(substream, hw_params, be_hw_params, dai, in avs_dai_fe_hw_params()
585 hdac_stream(host_stream)->stream_tag - 1); in avs_dai_fe_hw_params()
589 ret = avs_path_bind(data->path); in avs_dai_fe_hw_params()
591 dev_err(dai->dev, "bind FE <-> BE failed: %d\n", ret); in avs_dai_fe_hw_params()
598 avs_path_free(data->path); in avs_dai_fe_hw_params()
599 data->path = NULL; in avs_dai_fe_hw_params()
605 static int __avs_dai_fe_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in __avs_dai_fe_hw_free() argument
611 dev_dbg(dai->dev, "%s fe HW_FREE str %p rtd %p", in __avs_dai_fe_hw_free()
612 __func__, substream, substream->runtime); in __avs_dai_fe_hw_free()
614 data = snd_soc_dai_get_dma_data(dai, substream); in __avs_dai_fe_hw_free()
615 if (!data->path) in __avs_dai_fe_hw_free()
618 host_stream = data->host_stream; in __avs_dai_fe_hw_free()
620 ret = avs_path_unbind(data->path); in __avs_dai_fe_hw_free()
622 dev_err(dai->dev, "unbind FE <-> BE failed: %d\n", ret); in __avs_dai_fe_hw_free()
624 avs_path_free(data->path); in __avs_dai_fe_hw_free()
625 data->path = NULL; in __avs_dai_fe_hw_free()
627 hdac_stream(host_stream)->prepared = false; in __avs_dai_fe_hw_free()
632 static int avs_dai_fe_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_fe_hw_free() argument
636 ret = __avs_dai_fe_hw_free(substream, dai); in avs_dai_fe_hw_free()
642 static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) in avs_dai_fe_prepare() argument
644 struct snd_pcm_runtime *runtime = substream->runtime; in avs_dai_fe_prepare()
653 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_fe_prepare()
654 host_stream = data->host_stream; in avs_dai_fe_prepare()
656 if (hdac_stream(host_stream)->prepared) in avs_dai_fe_prepare()
659 bus = hdac_stream(host_stream)->bus; in avs_dai_fe_prepare()
660 snd_hdac_ext_stream_decouple(bus, data->host_stream, true); in avs_dai_fe_prepare()
663 stream_info = snd_soc_dai_get_pcm_stream(dai, substream->stream); in avs_dai_fe_prepare()
664 bits = snd_hdac_stream_format_bits(runtime->format, runtime->subformat, in avs_dai_fe_prepare()
665 stream_info->sig_bits); in avs_dai_fe_prepare()
666 format_val = snd_hdac_stream_format(runtime->channels, bits, runtime->rate); in avs_dai_fe_prepare()
676 ret = avs_dai_prepare(substream, dai); in avs_dai_fe_prepare()
680 hdac_stream(host_stream)->prepared = true; in avs_dai_fe_prepare()
690 list_for_each_entry(pos, &bus->stream_list, list) { in avs_hda_stream_start()
691 if (pos->running) { in avs_hda_stream_start()
703 if (hdac_stream(host_stream)->direction == SNDRV_PCM_STREAM_CAPTURE) in avs_hda_stream_start()
712 * re-enable L1SEN. in avs_hda_stream_start()
714 if (list_entry_is_head(pos, &bus->stream_list, list) && in avs_hda_stream_start()
715 first_running->direction == SNDRV_PCM_STREAM_CAPTURE) in avs_hda_stream_start()
725 list_for_each_entry(pos, &bus->stream_list, list) { in avs_hda_stream_stop()
728 if (pos->running) { in avs_hda_stream_stop()
737 * re-enable L1SEN. in avs_hda_stream_stop()
741 if (hdac_stream(host_stream)->direction == SNDRV_PCM_STREAM_CAPTURE) in avs_hda_stream_stop()
750 if (list_entry_is_head(pos, &bus->stream_list, list) && in avs_hda_stream_stop()
751 first_running->direction == SNDRV_PCM_STREAM_CAPTURE) in avs_hda_stream_stop()
757 static int avs_dai_fe_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) in avs_dai_fe_trigger() argument
766 data = snd_soc_dai_get_dma_data(dai, substream); in avs_dai_fe_trigger()
767 host_stream = data->host_stream; in avs_dai_fe_trigger()
768 bus = hdac_stream(host_stream)->bus; in avs_dai_fe_trigger()
772 if (rtd->dai_link->ignore_suspend) in avs_dai_fe_trigger()
777 spin_lock_irqsave(&bus->reg_lock, flags); in avs_dai_fe_trigger()
779 spin_unlock_irqrestore(&bus->reg_lock, flags); in avs_dai_fe_trigger()
785 ret = avs_path_pause(data->path); in avs_dai_fe_trigger()
787 dev_err(dai->dev, "pause FE path failed: %d\n", ret); in avs_dai_fe_trigger()
791 ret = avs_path_run(data->path, AVS_TPLG_TRIGGER_AUTO); in avs_dai_fe_trigger()
793 dev_err(dai->dev, "run FE path failed: %d\n", ret); in avs_dai_fe_trigger()
798 if (rtd->dai_link->ignore_suspend) in avs_dai_fe_trigger()
803 ret = avs_path_pause(data->path); in avs_dai_fe_trigger()
805 dev_err(dai->dev, "pause FE path failed: %d\n", ret); in avs_dai_fe_trigger()
807 spin_lock_irqsave(&bus->reg_lock, flags); in avs_dai_fe_trigger()
809 spin_unlock_irqrestore(&bus->reg_lock, flags); in avs_dai_fe_trigger()
811 ret = avs_path_reset(data->path); in avs_dai_fe_trigger()
813 dev_err(dai->dev, "reset FE path failed: %d\n", ret); in avs_dai_fe_trigger()
817 ret = -EINVAL; in avs_dai_fe_trigger()
836 struct snd_soc_component *component = file->private_data; in topology_name_read()
837 struct snd_soc_card *card = component->card; in topology_name_read()
838 struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev); in topology_name_read()
842 len = scnprintf(buf, sizeof(buf), "%s/%s\n", component->driver->topology_name_prefix, in topology_name_read()
843 mach->tplg_filename); in topology_name_read()
856 struct avs_tplg *tplg = acomp->tplg; in avs_component_load_libraries()
857 struct avs_dev *adev = to_avs_dev(acomp->base.dev); in avs_component_load_libraries()
860 if (!tplg->num_libs) in avs_component_load_libraries()
864 ret = pm_runtime_resume_and_get(adev->dev); in avs_component_load_libraries()
872 ret = avs_dsp_load_libraries(adev, tplg->libs, tplg->num_libs); in avs_component_load_libraries()
881 pm_runtime_mark_last_busy(adev->dev); in avs_component_load_libraries()
882 pm_runtime_put_autosuspend(adev->dev); in avs_component_load_libraries()
889 struct snd_soc_card *card = component->card; in avs_component_probe()
896 dev_dbg(card->dev, "probing %s card %s\n", component->name, card->name); in avs_component_probe()
897 mach = dev_get_platdata(card->dev); in avs_component_probe()
899 adev = to_avs_dev(component->dev); in avs_component_probe()
901 acomp->tplg = avs_tplg_new(component); in avs_component_probe()
902 if (!acomp->tplg) in avs_component_probe()
903 return -ENOMEM; in avs_component_probe()
905 if (!mach->tplg_filename) in avs_component_probe()
909 filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix, in avs_component_probe()
910 mach->tplg_filename); in avs_component_probe()
912 return -ENOMEM; in avs_component_probe()
916 if (ret == -ENOENT && !strncmp(mach->tplg_filename, "hda-", 4)) { in avs_component_probe()
919 if (sscanf(mach->tplg_filename, "hda-%08x-tplg.bin", &vendor_id) != 1) in avs_component_probe()
923 mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL, in avs_component_probe()
924 "hda-8086-generic-tplg.bin"); in avs_component_probe()
926 mach->tplg_filename = devm_kasprintf(adev->dev, GFP_KERNEL, in avs_component_probe()
927 "hda-generic-tplg.bin"); in avs_component_probe()
929 filename = kasprintf(GFP_KERNEL, "%s/%s", component->driver->topology_name_prefix, in avs_component_probe()
930 mach->tplg_filename); in avs_component_probe()
932 return -ENOMEM; in avs_component_probe()
934 dev_info(card->dev, "trying to load fallback topology %s\n", mach->tplg_filename); in avs_component_probe()
943 dev_err(card->dev, "libraries loading failed: %d\n", ret); in avs_component_probe()
948 debugfs_create_file("topology_name", 0444, component->debugfs_root, component, in avs_component_probe()
951 mutex_lock(&adev->comp_list_mutex); in avs_component_probe()
952 list_add_tail(&acomp->node, &adev->comp_list); in avs_component_probe()
953 mutex_unlock(&adev->comp_list_mutex); in avs_component_probe()
966 struct avs_dev *adev = to_avs_dev(component->dev); in avs_component_remove()
969 mach = dev_get_platdata(component->card->dev); in avs_component_remove()
971 mutex_lock(&adev->comp_list_mutex); in avs_component_remove()
972 list_del(&acomp->node); in avs_component_remove()
973 mutex_unlock(&adev->comp_list_mutex); in avs_component_remove()
975 if (mach->tplg_filename) { in avs_component_remove()
978 dev_err(component->dev, "unload topology failed: %d\n", ret); in avs_component_remove()
982 static int avs_dai_resume_hw_params(struct snd_soc_dai *dai, struct avs_dma_data *data) in avs_dai_resume_hw_params() argument
988 substream = data->substream; in avs_dai_resume_hw_params()
991 ret = dai->driver->ops->hw_params(substream, &rtd->dpcm[substream->stream].hw_params, dai); in avs_dai_resume_hw_params()
993 dev_err(dai->dev, "hw_params on resume failed: %d\n", ret); in avs_dai_resume_hw_params()
998 static int avs_dai_resume_fe_prepare(struct snd_soc_dai *dai, struct avs_dma_data *data) in avs_dai_resume_fe_prepare() argument
1005 host_stream = data->host_stream; in avs_dai_resume_fe_prepare()
1007 bus = hdac_stream(host_stream)->bus; in avs_dai_resume_fe_prepare()
1010 snd_hdac_stream_drsm_enable(bus, true, hstream->index); in avs_dai_resume_fe_prepare()
1012 ret = dai->driver->ops->prepare(data->substream, dai); in avs_dai_resume_fe_prepare()
1014 dev_err(dai->dev, "prepare FE on resume failed: %d\n", ret); in avs_dai_resume_fe_prepare()
1018 writel(host_stream->pphcllpl, host_stream->pphc_addr + AZX_REG_PPHCLLPL); in avs_dai_resume_fe_prepare()
1019 writel(host_stream->pphcllpu, host_stream->pphc_addr + AZX_REG_PPHCLLPU); in avs_dai_resume_fe_prepare()
1020 writel(host_stream->pphcldpl, host_stream->pphc_addr + AZX_REG_PPHCLDPL); in avs_dai_resume_fe_prepare()
1021 writel(host_stream->pphcldpu, host_stream->pphc_addr + AZX_REG_PPHCLDPU); in avs_dai_resume_fe_prepare()
1024 snd_hdac_stream_set_lpib(hstream, hstream->lpib); in avs_dai_resume_fe_prepare()
1025 snd_hdac_stream_set_dpibr(bus, hstream, hstream->lpib); in avs_dai_resume_fe_prepare()
1030 static int avs_dai_resume_be_prepare(struct snd_soc_dai *dai, struct avs_dma_data *data) in avs_dai_resume_be_prepare() argument
1034 ret = dai->driver->ops->prepare(data->substream, dai); in avs_dai_resume_be_prepare()
1036 dev_err(dai->dev, "prepare BE on resume failed: %d\n", ret); in avs_dai_resume_be_prepare()
1041 static int avs_dai_suspend_fe_hw_free(struct snd_soc_dai *dai, struct avs_dma_data *data) in avs_dai_suspend_fe_hw_free() argument
1046 host_stream = data->host_stream; in avs_dai_suspend_fe_hw_free()
1049 hdac_stream(host_stream)->lpib = snd_hdac_stream_get_pos_lpib(hdac_stream(host_stream)); in avs_dai_suspend_fe_hw_free()
1050 host_stream->pphcllpl = readl(host_stream->pphc_addr + AZX_REG_PPHCLLPL); in avs_dai_suspend_fe_hw_free()
1051 host_stream->pphcllpu = readl(host_stream->pphc_addr + AZX_REG_PPHCLLPU); in avs_dai_suspend_fe_hw_free()
1052 host_stream->pphcldpl = readl(host_stream->pphc_addr + AZX_REG_PPHCLDPL); in avs_dai_suspend_fe_hw_free()
1053 host_stream->pphcldpu = readl(host_stream->pphc_addr + AZX_REG_PPHCLDPU); in avs_dai_suspend_fe_hw_free()
1055 ret = __avs_dai_fe_hw_free(data->substream, dai); in avs_dai_suspend_fe_hw_free()
1057 dev_err(dai->dev, "hw_free FE on suspend failed: %d\n", ret); in avs_dai_suspend_fe_hw_free()
1062 static int avs_dai_suspend_be_hw_free(struct snd_soc_dai *dai, struct avs_dma_data *data) in avs_dai_suspend_be_hw_free() argument
1066 ret = dai->driver->ops->hw_free(data->substream, dai); in avs_dai_suspend_be_hw_free()
1068 dev_err(dai->dev, "hw_free BE on suspend failed: %d\n", ret); in avs_dai_suspend_be_hw_free()
1078 struct snd_soc_dai *dai; in avs_component_pm_op() local
1081 for_each_component_dais(component, dai) { in avs_component_pm_op()
1082 data = snd_soc_dai_dma_data_get_playback(dai); in avs_component_pm_op()
1084 rtd = snd_soc_substream_to_rtd(data->substream); in avs_component_pm_op()
1085 if (rtd->dai_link->no_pcm == be && !rtd->dai_link->ignore_suspend) { in avs_component_pm_op()
1086 ret = op(dai, data); in avs_component_pm_op()
1088 __snd_pcm_set_state(data->substream->runtime, in avs_component_pm_op()
1095 data = snd_soc_dai_dma_data_get_capture(dai); in avs_component_pm_op()
1097 rtd = snd_soc_substream_to_rtd(data->substream); in avs_component_pm_op()
1098 if (rtd->dai_link->no_pcm == be && !rtd->dai_link->ignore_suspend) { in avs_component_pm_op()
1099 ret = op(dai, data); in avs_component_pm_op()
1101 __snd_pcm_set_state(data->substream->runtime, in avs_component_pm_op()
1119 int (*prepare_cb)(struct snd_soc_dai *dai, struct avs_dma_data *data); in avs_component_resume_prepare()
1131 int (*hw_free_cb)(struct snd_soc_dai *dai, struct avs_dma_data *data); in avs_component_suspend_hw_free()
1172 /* It is expected that the LINK stream is prepared first. */ in avs_component_resume()
1205 /* only FE DAI links are handled here */ in avs_component_open()
1206 if (rtd->dai_link->no_pcm) in avs_component_open()
1214 return readl(hdac_stream(stream)->bus->remap_addr + AZX_REG_VS_SDXDPIB_XBASE + in avs_hda_stream_dpib_read()
1215 (AZX_REG_VS_SDXDPIB_XINTERVAL * hdac_stream(stream)->index)); in avs_hda_stream_dpib_read()
1227 if (!data->host_stream) in avs_component_pointer()
1230 host_stream = data->host_stream; in avs_component_pointer()
1233 if (pos >= hdac_stream(host_stream)->bufsize) in avs_component_pointer()
1236 return bytes_to_frames(substream->runtime, pos); in avs_component_pointer()
1251 struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0); in avs_component_construct() local
1252 struct snd_pcm *pcm = rtd->pcm; in avs_component_construct()
1254 if (dai->driver->playback.channels_min) in avs_component_construct()
1255 snd_pcm_set_managed_buffer(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, in avs_component_construct()
1256 SNDRV_DMA_TYPE_DEV_SG, component->dev, 0, in avs_component_construct()
1259 if (dai->driver->capture.channels_min) in avs_component_construct()
1260 snd_pcm_set_managed_buffer(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, in avs_component_construct()
1261 SNDRV_DMA_TYPE_DEV_SG, component->dev, 0, in avs_component_construct()
1268 .name = "avs-pcm",
1290 return -ENOMEM; in avs_soc_component_register()
1292 ret = snd_soc_component_initialize(&acomp->base, drv, dev); in avs_soc_component_register()
1297 acomp->base.name = name; in avs_soc_component_register()
1298 INIT_LIST_HEAD(&acomp->node); in avs_soc_component_register()
1300 return snd_soc_add_component(&acomp->base, cpu_dais, num_cpu_dais); in avs_soc_component_register()
1330 return avs_soc_component_register(adev->dev, name, &avs_component_driver, dmic_cpu_dais, in avs_dmic_platform_register()
1367 struct snd_soc_dai_driver *cpus, *dai; in avs_i2s_platform_register() local
1371 ssp_count = adev->hw_cfg.i2s_caps.ctrl_count; in avs_i2s_platform_register()
1381 cpus = devm_kzalloc(adev->dev, sizeof(*cpus) * cpu_count, GFP_KERNEL); in avs_i2s_platform_register()
1383 return -ENOMEM; in avs_i2s_platform_register()
1385 dai = cpus; in avs_i2s_platform_register()
1388 memcpy(dai, &i2s_dai_template, sizeof(*dai)); in avs_i2s_platform_register()
1390 dai->name = in avs_i2s_platform_register()
1391 devm_kasprintf(adev->dev, GFP_KERNEL, "SSP%d Pin", i); in avs_i2s_platform_register()
1392 dai->playback.stream_name = in avs_i2s_platform_register()
1393 devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d Tx", i); in avs_i2s_platform_register()
1394 dai->capture.stream_name = in avs_i2s_platform_register()
1395 devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d Rx", i); in avs_i2s_platform_register()
1397 if (!dai->name || !dai->playback.stream_name || !dai->capture.stream_name) in avs_i2s_platform_register()
1398 return -ENOMEM; in avs_i2s_platform_register()
1399 dai++; in avs_i2s_platform_register()
1408 memcpy(dai, &i2s_dai_template, sizeof(*dai)); in avs_i2s_platform_register()
1410 dai->name = in avs_i2s_platform_register()
1411 devm_kasprintf(adev->dev, GFP_KERNEL, "SSP%d:%d Pin", i, j); in avs_i2s_platform_register()
1412 dai->playback.stream_name = in avs_i2s_platform_register()
1413 devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d:%d Tx", i, j); in avs_i2s_platform_register()
1414 dai->capture.stream_name = in avs_i2s_platform_register()
1415 devm_kasprintf(adev->dev, GFP_KERNEL, "ssp%d:%d Rx", i, j); in avs_i2s_platform_register()
1417 if (!dai->name || !dai->playback.stream_name || !dai->capture.stream_name) in avs_i2s_platform_register()
1418 return -ENOMEM; in avs_i2s_platform_register()
1419 dai++; in avs_i2s_platform_register()
1424 return avs_soc_component_register(adev->dev, name, &avs_component_driver, cpus, cpu_count); in avs_i2s_platform_register()
1427 /* HD-Audio CPU DAI template */
1455 struct snd_soc_dai *dai, *save; in avs_component_hda_unregister_dais() local
1459 mach = dev_get_platdata(component->card->dev); in avs_component_hda_unregister_dais()
1460 codec = mach->pdata; in avs_component_hda_unregister_dais()
1461 snprintf(name, sizeof(name), "%s-cpu", dev_name(&codec->core.dev)); in avs_component_hda_unregister_dais()
1463 for_each_component_dais_safe(component, dai, save) { in avs_component_hda_unregister_dais()
1466 if (!strstr(dai->driver->name, name)) in avs_component_hda_unregister_dais()
1470 snd_soc_dapm_free_widget(snd_soc_dai_get_widget(dai, stream)); in avs_component_hda_unregister_dais()
1472 snd_soc_unregister_dai(dai); in avs_component_hda_unregister_dais()
1486 mach = dev_get_platdata(component->card->dev); in avs_component_hda_probe()
1488 return -EINVAL; in avs_component_hda_probe()
1490 codec = mach->pdata; in avs_component_hda_probe()
1491 if (list_empty(&codec->pcm_list_head)) in avs_component_hda_probe()
1492 return -EINVAL; in avs_component_hda_probe()
1493 list_for_each_entry(pcm, &codec->pcm_list_head, list) in avs_component_hda_probe()
1496 dais = devm_kcalloc(component->dev, pcm_count, sizeof(*dais), in avs_component_hda_probe()
1499 return -ENOMEM; in avs_component_hda_probe()
1501 cname = dev_name(&codec->core.dev); in avs_component_hda_probe()
1503 pcm = list_first_entry(&codec->pcm_list_head, struct hda_pcm, list); in avs_component_hda_probe()
1506 struct snd_soc_dai *dai; in avs_component_hda_probe() local
1510 dais[i].name = devm_kasprintf(component->dev, GFP_KERNEL, in avs_component_hda_probe()
1511 "%s-cpu%d", cname, i); in avs_component_hda_probe()
1513 ret = -ENOMEM; in avs_component_hda_probe()
1517 if (pcm->stream[0].substreams) { in avs_component_hda_probe()
1519 devm_kasprintf(component->dev, GFP_KERNEL, in avs_component_hda_probe()
1520 "%s-cpu%d Tx", cname, i); in avs_component_hda_probe()
1522 ret = -ENOMEM; in avs_component_hda_probe()
1527 dais[i].playback.formats = pcm->stream[0].formats; in avs_component_hda_probe()
1528 dais[i].playback.subformats = pcm->stream[0].subformats; in avs_component_hda_probe()
1529 dais[i].playback.rates = pcm->stream[0].rates; in avs_component_hda_probe()
1530 dais[i].playback.channels_min = pcm->stream[0].channels_min; in avs_component_hda_probe()
1531 dais[i].playback.channels_max = pcm->stream[0].channels_max; in avs_component_hda_probe()
1532 dais[i].playback.sig_bits = pcm->stream[0].maxbps; in avs_component_hda_probe()
1536 if (pcm->stream[1].substreams) { in avs_component_hda_probe()
1538 devm_kasprintf(component->dev, GFP_KERNEL, in avs_component_hda_probe()
1539 "%s-cpu%d Rx", cname, i); in avs_component_hda_probe()
1541 ret = -ENOMEM; in avs_component_hda_probe()
1546 dais[i].capture.formats = pcm->stream[1].formats; in avs_component_hda_probe()
1547 dais[i].capture.subformats = pcm->stream[1].subformats; in avs_component_hda_probe()
1548 dais[i].capture.rates = pcm->stream[1].rates; in avs_component_hda_probe()
1549 dais[i].capture.channels_min = pcm->stream[1].channels_min; in avs_component_hda_probe()
1550 dais[i].capture.channels_max = pcm->stream[1].channels_max; in avs_component_hda_probe()
1551 dais[i].capture.sig_bits = pcm->stream[1].maxbps; in avs_component_hda_probe()
1555 dai = snd_soc_register_dai(component, &dais[i], false); in avs_component_hda_probe()
1556 if (!dai) { in avs_component_hda_probe()
1557 dev_err(component->dev, "register dai for %s failed\n", in avs_component_hda_probe()
1558 pcm->name); in avs_component_hda_probe()
1559 ret = -EINVAL; in avs_component_hda_probe()
1563 ret = snd_soc_dapm_new_dai_widgets(dapm, dai); in avs_component_hda_probe()
1565 dev_err(component->dev, "create widgets failed: %d\n", in avs_component_hda_probe()
1590 if (!rtd->dai_link->no_pcm) { in avs_component_hda_open()
1594 int dir = substream->stream; in avs_component_hda_open()
1598 * common code - a valid stream pointer at substream->runtime->private_data - in avs_component_hda_open()
1604 be = dpcm->be; in avs_component_hda_open()
1605 if (be->dpcm[dir].users == 1) in avs_component_hda_open()
1609 substream->runtime->private_data = be_substream->runtime->private_data; in avs_component_hda_open()
1613 /* RESUME unsupported for de-coupled HD-Audio capture. */ in avs_component_hda_open()
1624 .name = "avs-hda-pcm",
1635 * codec->pcm_list_head, it needs to be initialized after codec
1646 return avs_soc_component_register(adev->dev, name, in avs_hda_platform_register()