1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2019 Intel Corporation
8 // Author: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
11 #include <linux/bitfield.h>
12 #include <trace/events/sof.h>
13 #include "sof-audio.h"
16 static bool is_virtual_widget(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
20 case snd_soc_dapm_out_drv:
21 case snd_soc_dapm_output:
22 case snd_soc_dapm_input:
23 dev_dbg(sdev->dev, "%s: %s is a virtual widget\n", func, widget->name);
30 static void sof_reset_route_setup_status(struct snd_sof_dev *sdev, struct snd_sof_widget *widget)
32 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
33 struct snd_sof_route *sroute;
35 list_for_each_entry(sroute, &sdev->route_list, list)
36 if (sroute->src_widget == widget || sroute->sink_widget == widget) {
37 if (sroute->setup && tplg_ops && tplg_ops->route_free)
38 tplg_ops->route_free(sdev, sroute);
40 sroute->setup = false;
44 static int sof_widget_free_unlocked(struct snd_sof_dev *sdev,
45 struct snd_sof_widget *swidget)
47 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
48 struct snd_sof_pipeline *spipe = swidget->spipe;
52 if (!swidget->private)
55 trace_sof_widget_free(swidget);
57 /* only free when use_count is 0 */
58 if (--swidget->use_count)
61 /* reset route setup status for all routes that contain this widget */
62 sof_reset_route_setup_status(sdev, swidget);
64 /* free DAI config and continue to free widget even if it fails */
65 if (WIDGET_IS_DAI(swidget->id)) {
66 struct snd_sof_dai_config_data data;
67 unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_FREE;
69 data.dai_data = DMA_CHAN_INVALID;
71 if (tplg_ops && tplg_ops->dai_config) {
72 err = tplg_ops->dai_config(sdev, swidget, flags, &data);
74 dev_err(sdev->dev, "failed to free config for widget %s\n",
75 swidget->widget->name);
79 /* continue to disable core even if IPC fails */
80 if (tplg_ops && tplg_ops->widget_free) {
81 ret = tplg_ops->widget_free(sdev, swidget);
87 * decrement ref count for cores associated with all modules in the pipeline and clear
90 if (swidget->id == snd_soc_dapm_scheduler) {
93 for_each_set_bit(i, &spipe->core_mask, sdev->num_cores) {
94 ret = snd_sof_dsp_core_put(sdev, i);
96 dev_err(sdev->dev, "failed to disable target core: %d for pipeline %s\n",
97 i, swidget->widget->name);
102 swidget->spipe->complete = 0;
106 * free the scheduler widget (same as pipe_widget) associated with the current swidget.
107 * skip for static pipelines
109 if (swidget->spipe && swidget->dynamic_pipeline_widget &&
110 swidget->id != snd_soc_dapm_scheduler) {
111 ret = sof_widget_free_unlocked(sdev, swidget->spipe->pipe_widget);
117 dev_dbg(sdev->dev, "widget %s freed\n", swidget->widget->name);
122 int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
126 mutex_lock(&swidget->setup_mutex);
127 ret = sof_widget_free_unlocked(sdev, swidget);
128 mutex_unlock(&swidget->setup_mutex);
132 EXPORT_SYMBOL(sof_widget_free);
134 static int sof_widget_setup_unlocked(struct snd_sof_dev *sdev,
135 struct snd_sof_widget *swidget)
137 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
138 struct snd_sof_pipeline *spipe = swidget->spipe;
139 bool use_count_decremented = false;
143 /* skip if there is no private data */
144 if (!swidget->private)
147 trace_sof_widget_setup(swidget);
149 /* widget already set up */
150 if (++swidget->use_count > 1)
154 * The scheduler widget for a pipeline is not part of the connected DAPM
155 * widget list and it needs to be set up before the widgets in the pipeline
156 * are set up. The use_count for the scheduler widget is incremented for every
157 * widget in a given pipeline to ensure that it is freed only after the last
158 * widget in the pipeline is freed. Skip setting up scheduler widget for static pipelines.
160 if (swidget->dynamic_pipeline_widget && swidget->id != snd_soc_dapm_scheduler) {
161 if (!swidget->spipe || !swidget->spipe->pipe_widget) {
162 dev_err(sdev->dev, "No pipeline set for %s\n", swidget->widget->name);
167 ret = sof_widget_setup_unlocked(sdev, swidget->spipe->pipe_widget);
172 /* update ref count for cores associated with all modules in the pipeline */
173 if (swidget->id == snd_soc_dapm_scheduler) {
174 for_each_set_bit(i, &spipe->core_mask, sdev->num_cores) {
175 ret = snd_sof_dsp_core_get(sdev, i);
177 dev_err(sdev->dev, "failed to enable target core %d for pipeline %s\n",
178 i, swidget->widget->name);
179 goto pipe_widget_free;
184 /* setup widget in the DSP */
185 if (tplg_ops && tplg_ops->widget_setup) {
186 ret = tplg_ops->widget_setup(sdev, swidget);
188 goto pipe_widget_free;
191 /* send config for DAI components */
192 if (WIDGET_IS_DAI(swidget->id)) {
193 unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS;
196 * The config flags saved during BE DAI hw_params will be used for IPC3. IPC4 does
197 * not use the flags argument.
199 if (tplg_ops && tplg_ops->dai_config) {
200 ret = tplg_ops->dai_config(sdev, swidget, flags, NULL);
206 /* restore kcontrols for widget */
207 if (tplg_ops && tplg_ops->control && tplg_ops->control->widget_kcontrol_setup) {
208 ret = tplg_ops->control->widget_kcontrol_setup(sdev, swidget);
213 dev_dbg(sdev->dev, "widget %s setup complete\n", swidget->widget->name);
218 /* widget use_count will be decremented by sof_widget_free() */
219 sof_widget_free_unlocked(sdev, swidget);
220 use_count_decremented = true;
222 if (swidget->id != snd_soc_dapm_scheduler) {
223 sof_widget_free_unlocked(sdev, swidget->spipe->pipe_widget);
227 /* decrement ref count for all cores that were updated previously */
228 for_each_set_bit(j, &spipe->core_mask, sdev->num_cores) {
231 snd_sof_dsp_core_put(sdev, j);
235 if (!use_count_decremented)
236 swidget->use_count--;
241 int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
245 mutex_lock(&swidget->setup_mutex);
246 ret = sof_widget_setup_unlocked(sdev, swidget);
247 mutex_unlock(&swidget->setup_mutex);
251 EXPORT_SYMBOL(sof_widget_setup);
253 int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
254 struct snd_soc_dapm_widget *wsink)
256 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
257 struct snd_sof_widget *src_widget = wsource->dobj.private;
258 struct snd_sof_widget *sink_widget = wsink->dobj.private;
259 struct snd_sof_route *sroute;
260 bool route_found = false;
262 /* ignore routes involving virtual widgets in topology */
263 if (is_virtual_widget(sdev, src_widget->widget, __func__) ||
264 is_virtual_widget(sdev, sink_widget->widget, __func__))
267 /* find route matching source and sink widgets */
268 list_for_each_entry(sroute, &sdev->route_list, list)
269 if (sroute->src_widget == src_widget && sroute->sink_widget == sink_widget) {
275 dev_err(sdev->dev, "error: cannot find SOF route for source %s -> %s sink\n",
276 wsource->name, wsink->name);
280 /* nothing to do if route is already set up */
284 if (tplg_ops && tplg_ops->route_setup) {
285 int ret = tplg_ops->route_setup(sdev, sroute);
291 sroute->setup = true;
295 static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
296 struct snd_soc_dapm_widget_list *list, int dir)
298 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
299 struct snd_soc_dapm_widget *widget;
300 struct snd_sof_route *sroute;
301 struct snd_soc_dapm_path *p;
306 * Set up connections between widgets in the sink/source paths based on direction.
307 * Some non-SOF widgets exist in topology either for compatibility or for the
308 * purpose of connecting a pipeline from a host to a DAI in order to receive the DAPM
309 * events. But they are not handled by the firmware. So ignore them.
311 if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
312 for_each_dapm_widgets(list, i, widget) {
313 if (!widget->dobj.private)
316 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
317 if (!widget_in_list(list, p->sink))
320 if (p->sink->dobj.private) {
321 ret = sof_route_setup(sdev, widget, p->sink);
328 for_each_dapm_widgets(list, i, widget) {
329 if (!widget->dobj.private)
332 snd_soc_dapm_widget_for_each_source_path(widget, p) {
333 if (!widget_in_list(list, p->source))
336 if (p->source->dobj.private) {
337 ret = sof_route_setup(sdev, p->source, widget);
346 * The above loop handles connections between widgets that belong to the DAPM widget list.
347 * This is not sufficient to handle loopback cases between pipelines configured with
348 * different directions, e.g. a sidetone or an amplifier feedback connected to a speaker
351 list_for_each_entry(sroute, &sdev->route_list, list) {
352 bool src_widget_in_dapm_list, sink_widget_in_dapm_list;
353 struct snd_sof_widget *swidget;
358 src_widget_in_dapm_list = widget_in_list(list, sroute->src_widget->widget);
359 sink_widget_in_dapm_list = widget_in_list(list, sroute->sink_widget->widget);
362 * if both source and sink are in the DAPM list, the route must already have been
363 * set up above. And if neither are in the DAPM list, the route shouldn't be
366 if (src_widget_in_dapm_list == sink_widget_in_dapm_list)
370 * At this point either the source widget or the sink widget is in the DAPM list
371 * with a route that might need to be set up. Check the use_count of the widget
372 * that is not in the DAPM list to confirm if it is in use currently before setting
375 if (src_widget_in_dapm_list)
376 swidget = sroute->sink_widget;
378 swidget = sroute->src_widget;
380 mutex_lock(&swidget->setup_mutex);
381 if (!swidget->use_count) {
382 mutex_unlock(&swidget->setup_mutex);
386 if (tplg_ops && tplg_ops->route_setup) {
388 * this route will get freed when either the source widget or the sink
389 * widget is freed during hw_free
391 ret = tplg_ops->route_setup(sdev, sroute);
393 sroute->setup = true;
396 mutex_unlock(&swidget->setup_mutex);
406 sof_unprepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
407 struct snd_soc_dapm_widget_list *list)
409 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
410 struct snd_sof_widget *swidget = widget->dobj.private;
411 const struct sof_ipc_tplg_widget_ops *widget_ops;
412 struct snd_soc_dapm_path *p;
414 if (is_virtual_widget(sdev, widget, __func__))
417 /* skip if the widget is in use or if it is already unprepared */
418 if (!swidget || !swidget->prepared || swidget->use_count > 0)
421 widget_ops = tplg_ops ? tplg_ops->widget : NULL;
422 if (widget_ops && widget_ops[widget->id].ipc_unprepare)
423 /* unprepare the source widget */
424 widget_ops[widget->id].ipc_unprepare(swidget);
426 swidget->prepared = false;
429 /* unprepare all widgets in the sink paths */
430 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
431 if (!widget_in_list(list, p->sink))
433 if (!p->walking && p->sink->dobj.private) {
435 sof_unprepare_widgets_in_path(sdev, p->sink, list);
442 sof_prepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
443 struct snd_pcm_hw_params *fe_params,
444 struct snd_sof_platform_stream_params *platform_params,
445 struct snd_pcm_hw_params *pipeline_params, int dir,
446 struct snd_soc_dapm_widget_list *list)
448 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
449 struct snd_sof_widget *swidget = widget->dobj.private;
450 const struct sof_ipc_tplg_widget_ops *widget_ops;
451 struct snd_soc_dapm_path *p;
454 if (is_virtual_widget(sdev, widget, __func__))
457 widget_ops = tplg_ops ? tplg_ops->widget : NULL;
461 if (!swidget || !widget_ops[widget->id].ipc_prepare || swidget->prepared)
464 /* prepare the source widget */
465 ret = widget_ops[widget->id].ipc_prepare(swidget, fe_params, platform_params,
466 pipeline_params, dir);
468 dev_err(sdev->dev, "failed to prepare widget %s\n", widget->name);
472 swidget->prepared = true;
475 /* prepare all widgets in the sink paths */
476 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
477 if (!widget_in_list(list, p->sink))
479 if (!p->walking && p->sink->dobj.private) {
481 ret = sof_prepare_widgets_in_path(sdev, p->sink, fe_params,
482 platform_params, pipeline_params, dir,
486 /* unprepare the source widget */
487 if (widget_ops[widget->id].ipc_unprepare &&
488 swidget && swidget->prepared) {
489 widget_ops[widget->id].ipc_unprepare(swidget);
490 swidget->prepared = false;
501 * free all widgets in the sink path starting from the source widget
502 * (DAI type for capture, AIF type for playback)
504 static int sof_free_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
505 int dir, struct snd_sof_pcm *spcm)
507 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
508 struct snd_soc_dapm_path *p;
512 if (is_virtual_widget(sdev, widget, __func__))
515 if (widget->dobj.private) {
516 err = sof_widget_free(sdev, widget->dobj.private);
521 /* free all widgets in the sink paths even in case of error to keep use counts balanced */
522 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
524 if (!widget_in_list(list, p->sink))
529 err = sof_free_widgets_in_path(sdev, p->sink, dir, spcm);
540 * set up all widgets in the sink path starting from the source widget
541 * (DAI type for capture, AIF type for playback).
542 * The error path in this function ensures that all successfully set up widgets getting freed.
544 static int sof_set_up_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
545 int dir, struct snd_sof_pcm *spcm)
547 struct snd_sof_pcm_stream_pipeline_list *pipeline_list = &spcm->stream[dir].pipeline_list;
548 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
549 struct snd_sof_widget *swidget = widget->dobj.private;
550 struct snd_sof_pipeline *spipe;
551 struct snd_soc_dapm_path *p;
554 if (is_virtual_widget(sdev, widget, __func__))
560 ret = sof_widget_setup(sdev, widget->dobj.private);
564 /* skip populating the pipe_widgets array if it is NULL */
565 if (!pipeline_list->pipelines)
569 * Add the widget's pipe_widget to the list of pipelines to be triggered if not
570 * already in the list. This will result in the pipelines getting added in the
571 * order source to sink.
573 for (i = 0; i < pipeline_list->count; i++) {
574 spipe = pipeline_list->pipelines[i];
575 if (spipe == swidget->spipe)
579 if (i == pipeline_list->count) {
580 pipeline_list->count++;
581 pipeline_list->pipelines[i] = swidget->spipe;
586 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
588 if (!widget_in_list(list, p->sink))
593 ret = sof_set_up_widgets_in_path(sdev, p->sink, dir, spcm);
597 sof_widget_free(sdev, swidget);
607 sof_walk_widgets_in_order(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
608 struct snd_pcm_hw_params *fe_params,
609 struct snd_sof_platform_stream_params *platform_params, int dir,
610 enum sof_widget_op op)
612 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
613 struct snd_soc_dapm_widget *widget;
621 for_each_dapm_widgets(list, i, widget) {
622 if (is_virtual_widget(sdev, widget, __func__))
625 /* starting widget for playback is AIF type */
626 if (dir == SNDRV_PCM_STREAM_PLAYBACK && widget->id != snd_soc_dapm_aif_in)
629 /* starting widget for capture is DAI type */
630 if (dir == SNDRV_PCM_STREAM_CAPTURE && widget->id != snd_soc_dapm_dai_out)
634 case SOF_WIDGET_SETUP:
635 ret = sof_set_up_widgets_in_path(sdev, widget, dir, spcm);
638 case SOF_WIDGET_FREE:
639 ret = sof_free_widgets_in_path(sdev, widget, dir, spcm);
642 case SOF_WIDGET_PREPARE:
644 struct snd_pcm_hw_params pipeline_params;
648 * When walking the list of connected widgets, the pipeline_params for each
649 * widget is modified by the source widget in the path. Use a local
650 * copy of the runtime params as the pipeline_params so that the runtime
651 * params does not get overwritten.
653 memcpy(&pipeline_params, fe_params, sizeof(*fe_params));
655 ret = sof_prepare_widgets_in_path(sdev, widget, fe_params, platform_params,
656 &pipeline_params, dir, list);
659 case SOF_WIDGET_UNPREPARE:
660 sof_unprepare_widgets_in_path(sdev, widget, list);
663 dev_err(sdev->dev, "Invalid widget op %d\n", op);
667 dev_err(sdev->dev, "Failed to %s connected widgets\n", str);
675 int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
676 struct snd_pcm_hw_params *fe_params,
677 struct snd_sof_platform_stream_params *platform_params,
680 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
681 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
682 struct snd_soc_dapm_widget *widget;
685 /* nothing to set up */
690 * Prepare widgets for set up. The prepare step is used to allocate memory, assign
691 * instance ID and pick the widget configuration based on the runtime PCM params.
693 ret = sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params,
694 dir, SOF_WIDGET_PREPARE);
698 /* Set up is used to send the IPC to the DSP to create the widget */
699 ret = sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params,
700 dir, SOF_WIDGET_SETUP);
702 sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params,
703 dir, SOF_WIDGET_UNPREPARE);
708 * error in setting pipeline connections will result in route status being reset for
709 * routes that were successfully set up when the widgets are freed.
711 ret = sof_setup_pipeline_connections(sdev, list, dir);
715 /* complete pipelines */
716 for_each_dapm_widgets(list, i, widget) {
717 struct snd_sof_widget *swidget = widget->dobj.private;
718 struct snd_sof_widget *pipe_widget;
719 struct snd_sof_pipeline *spipe;
721 if (!swidget || sdev->dspless_mode_selected)
724 spipe = swidget->spipe;
726 dev_err(sdev->dev, "no pipeline found for %s\n",
727 swidget->widget->name);
732 pipe_widget = spipe->pipe_widget;
734 dev_err(sdev->dev, "error: no pipeline widget found for %s\n",
735 swidget->widget->name);
743 if (tplg_ops && tplg_ops->pipeline_complete) {
744 spipe->complete = tplg_ops->pipeline_complete(sdev, pipe_widget);
745 if (spipe->complete < 0) {
746 ret = spipe->complete;
755 sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params, dir,
757 sof_walk_widgets_in_order(sdev, spcm, NULL, NULL, dir, SOF_WIDGET_UNPREPARE);
762 int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir)
764 struct snd_sof_pcm_stream_pipeline_list *pipeline_list = &spcm->stream[dir].pipeline_list;
765 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
768 /* nothing to free */
772 /* send IPC to free widget in the DSP */
773 ret = sof_walk_widgets_in_order(sdev, spcm, NULL, NULL, dir, SOF_WIDGET_FREE);
775 /* unprepare the widget */
776 sof_walk_widgets_in_order(sdev, spcm, NULL, NULL, dir, SOF_WIDGET_UNPREPARE);
778 snd_soc_dapm_dai_free_widgets(&list);
779 spcm->stream[dir].list = NULL;
781 pipeline_list->count = 0;
787 * helper to determine if there are only D0i3 compatible
790 bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev)
792 struct snd_pcm_substream *substream;
793 struct snd_sof_pcm *spcm;
794 bool d0i3_compatible_active = false;
797 list_for_each_entry(spcm, &sdev->pcm_list, list) {
798 for_each_pcm_streams(dir) {
799 substream = spcm->stream[dir].substream;
800 if (!substream || !substream->runtime)
804 * substream->runtime being not NULL indicates
805 * that the stream is open. No need to check the
808 if (!spcm->stream[dir].d0i3_compatible)
811 d0i3_compatible_active = true;
815 return d0i3_compatible_active;
817 EXPORT_SYMBOL(snd_sof_dsp_only_d0i3_compatible_stream_active);
819 bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev)
821 struct snd_sof_pcm *spcm;
823 list_for_each_entry(spcm, &sdev->pcm_list, list) {
824 if (spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].suspend_ignored ||
825 spcm->stream[SNDRV_PCM_STREAM_CAPTURE].suspend_ignored)
832 int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
833 struct snd_sof_pcm *spcm, int dir, bool free_widget_list)
835 const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
839 if (spcm->prepared[substream->stream]) {
840 /* stop DMA first if needed */
841 if (pcm_ops && pcm_ops->platform_stop_during_hw_free)
842 snd_sof_pcm_platform_trigger(sdev, substream, SNDRV_PCM_TRIGGER_STOP);
844 /* free PCM in the DSP */
845 if (pcm_ops && pcm_ops->hw_free) {
846 ret = pcm_ops->hw_free(sdev->component, substream);
848 dev_err(sdev->dev, "%s: pcm_ops hw_free failed %d\n",
854 spcm->prepared[substream->stream] = false;
855 spcm->pending_stop[substream->stream] = false;
859 ret = snd_sof_pcm_platform_hw_free(sdev, substream);
861 dev_err(sdev->dev, "%s: platform hw free failed %d\n",
867 /* free widget list */
868 if (free_widget_list) {
869 ret = sof_widget_list_free(sdev, spcm, dir);
871 dev_err(sdev->dev, "%s: sof_widget_list_free failed %d\n",
882 * Generic object lookup APIs.
885 struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
888 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
889 struct snd_sof_pcm *spcm;
891 list_for_each_entry(spcm, &sdev->pcm_list, list) {
892 /* match with PCM dai name */
893 if (strcmp(spcm->pcm.dai_name, name) == 0)
896 /* match with playback caps name if set */
897 if (*spcm->pcm.caps[0].name &&
898 !strcmp(spcm->pcm.caps[0].name, name))
901 /* match with capture caps name if set */
902 if (*spcm->pcm.caps[1].name &&
903 !strcmp(spcm->pcm.caps[1].name, name))
910 struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
911 unsigned int comp_id,
914 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
915 struct snd_sof_pcm *spcm;
918 list_for_each_entry(spcm, &sdev->pcm_list, list) {
919 for_each_pcm_streams(dir) {
920 if (spcm->stream[dir].comp_id == comp_id) {
930 struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
933 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
934 struct snd_sof_widget *swidget;
936 list_for_each_entry(swidget, &sdev->widget_list, list) {
937 if (strcmp(name, swidget->widget->name) == 0)
944 /* find widget by stream name and direction */
945 struct snd_sof_widget *
946 snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
947 const char *pcm_name, int dir)
949 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
950 struct snd_sof_widget *swidget;
951 enum snd_soc_dapm_type type;
953 if (dir == SNDRV_PCM_STREAM_PLAYBACK)
954 type = snd_soc_dapm_aif_in;
956 type = snd_soc_dapm_aif_out;
958 list_for_each_entry(swidget, &sdev->widget_list, list) {
959 if (!strcmp(pcm_name, swidget->widget->sname) &&
967 struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
970 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
971 struct snd_sof_dai *dai;
973 list_for_each_entry(dai, &sdev->dai_list, list) {
974 if (dai->name && (strcmp(name, dai->name) == 0))
981 static int sof_dai_get_clk(struct snd_soc_pcm_runtime *rtd, int clk_type)
983 struct snd_soc_component *component =
984 snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
985 struct snd_sof_dai *dai =
986 snd_sof_find_dai(component, (char *)rtd->dai_link->name);
987 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
988 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
990 /* use the tplg configured mclk if existed */
994 if (tplg_ops && tplg_ops->dai_get_clk)
995 return tplg_ops->dai_get_clk(sdev, dai, clk_type);
1001 * Helper to get SSP MCLK from a pcm_runtime.
1002 * Return 0 if not exist.
1004 int sof_dai_get_mclk(struct snd_soc_pcm_runtime *rtd)
1006 return sof_dai_get_clk(rtd, SOF_DAI_CLK_INTEL_SSP_MCLK);
1008 EXPORT_SYMBOL(sof_dai_get_mclk);
1011 * Helper to get SSP BCLK from a pcm_runtime.
1012 * Return 0 if not exist.
1014 int sof_dai_get_bclk(struct snd_soc_pcm_runtime *rtd)
1016 return sof_dai_get_clk(rtd, SOF_DAI_CLK_INTEL_SSP_BCLK);
1018 EXPORT_SYMBOL(sof_dai_get_bclk);