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. All rights reserved.
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"
14 #include "sof-of-dev.h"
17 static void sof_reset_route_setup_status(struct snd_sof_dev *sdev, struct snd_sof_widget *widget)
19 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
20 struct snd_sof_route *sroute;
22 list_for_each_entry(sroute, &sdev->route_list, list)
23 if (sroute->src_widget == widget || sroute->sink_widget == widget) {
24 if (sroute->setup && tplg_ops && tplg_ops->route_free)
25 tplg_ops->route_free(sdev, sroute);
27 sroute->setup = false;
31 static int sof_widget_free_unlocked(struct snd_sof_dev *sdev,
32 struct snd_sof_widget *swidget)
34 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
35 struct snd_sof_widget *pipe_widget;
39 if (!swidget->private)
42 trace_sof_widget_free(swidget);
44 /* only free when use_count is 0 */
45 if (--swidget->use_count)
48 pipe_widget = swidget->spipe->pipe_widget;
50 /* reset route setup status for all routes that contain this widget */
51 sof_reset_route_setup_status(sdev, swidget);
53 /* free DAI config and continue to free widget even if it fails */
54 if (WIDGET_IS_DAI(swidget->id)) {
55 struct snd_sof_dai_config_data data;
56 unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_FREE;
58 data.dai_data = DMA_CHAN_INVALID;
60 if (tplg_ops && tplg_ops->dai_config) {
61 err = tplg_ops->dai_config(sdev, swidget, flags, &data);
63 dev_err(sdev->dev, "failed to free config for widget %s\n",
64 swidget->widget->name);
68 /* continue to disable core even if IPC fails */
69 if (tplg_ops && tplg_ops->widget_free) {
70 ret = tplg_ops->widget_free(sdev, swidget);
76 * disable widget core. continue to route setup status and complete flag
77 * even if this fails and return the appropriate error
79 ret = snd_sof_dsp_core_put(sdev, swidget->core);
81 dev_err(sdev->dev, "error: failed to disable target core: %d for widget %s\n",
82 swidget->core, swidget->widget->name);
88 * free the scheduler widget (same as pipe_widget) associated with the current swidget.
89 * skip for static pipelines
91 if (swidget->dynamic_pipeline_widget && swidget->id != snd_soc_dapm_scheduler) {
92 ret = sof_widget_free_unlocked(sdev, pipe_widget);
97 /* clear pipeline complete */
98 if (swidget->id == snd_soc_dapm_scheduler)
99 swidget->spipe->complete = 0;
102 dev_dbg(sdev->dev, "widget %s freed\n", swidget->widget->name);
107 int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
111 mutex_lock(&swidget->setup_mutex);
112 ret = sof_widget_free_unlocked(sdev, swidget);
113 mutex_unlock(&swidget->setup_mutex);
117 EXPORT_SYMBOL(sof_widget_free);
119 static int sof_widget_setup_unlocked(struct snd_sof_dev *sdev,
120 struct snd_sof_widget *swidget)
122 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
123 bool use_count_decremented = false;
126 /* skip if there is no private data */
127 if (!swidget->private)
130 trace_sof_widget_setup(swidget);
132 /* widget already set up */
133 if (++swidget->use_count > 1)
137 * The scheduler widget for a pipeline is not part of the connected DAPM
138 * widget list and it needs to be set up before the widgets in the pipeline
139 * are set up. The use_count for the scheduler widget is incremented for every
140 * widget in a given pipeline to ensure that it is freed only after the last
141 * widget in the pipeline is freed. Skip setting up scheduler widget for static pipelines.
143 if (swidget->dynamic_pipeline_widget && swidget->id != snd_soc_dapm_scheduler) {
144 if (!swidget->spipe || !swidget->spipe->pipe_widget) {
145 dev_err(sdev->dev, "No pipeline set for %s\n", swidget->widget->name);
150 ret = sof_widget_setup_unlocked(sdev, swidget->spipe->pipe_widget);
155 /* enable widget core */
156 ret = snd_sof_dsp_core_get(sdev, swidget->core);
158 dev_err(sdev->dev, "error: failed to enable target core for widget %s\n",
159 swidget->widget->name);
160 goto pipe_widget_free;
163 /* setup widget in the DSP */
164 if (tplg_ops && tplg_ops->widget_setup) {
165 ret = tplg_ops->widget_setup(sdev, swidget);
170 /* send config for DAI components */
171 if (WIDGET_IS_DAI(swidget->id)) {
172 unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS;
175 * The config flags saved during BE DAI hw_params will be used for IPC3. IPC4 does
176 * not use the flags argument.
178 if (tplg_ops && tplg_ops->dai_config) {
179 ret = tplg_ops->dai_config(sdev, swidget, flags, NULL);
185 /* restore kcontrols for widget */
186 if (tplg_ops && tplg_ops->control && tplg_ops->control->widget_kcontrol_setup) {
187 ret = tplg_ops->control->widget_kcontrol_setup(sdev, swidget);
192 dev_dbg(sdev->dev, "widget %s setup complete\n", swidget->widget->name);
197 /* widget use_count and core ref_count will both be decremented by sof_widget_free() */
198 sof_widget_free_unlocked(sdev, swidget);
199 use_count_decremented = true;
201 snd_sof_dsp_core_put(sdev, swidget->core);
203 if (swidget->id != snd_soc_dapm_scheduler)
204 sof_widget_free_unlocked(sdev, swidget->spipe->pipe_widget);
206 if (!use_count_decremented)
207 swidget->use_count--;
212 int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
216 mutex_lock(&swidget->setup_mutex);
217 ret = sof_widget_setup_unlocked(sdev, swidget);
218 mutex_unlock(&swidget->setup_mutex);
222 EXPORT_SYMBOL(sof_widget_setup);
224 int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
225 struct snd_soc_dapm_widget *wsink)
227 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
228 struct snd_sof_widget *src_widget = wsource->dobj.private;
229 struct snd_sof_widget *sink_widget = wsink->dobj.private;
230 struct snd_sof_route *sroute;
231 bool route_found = false;
233 /* ignore routes involving virtual widgets in topology */
234 switch (src_widget->id) {
235 case snd_soc_dapm_out_drv:
236 case snd_soc_dapm_output:
237 case snd_soc_dapm_input:
243 switch (sink_widget->id) {
244 case snd_soc_dapm_out_drv:
245 case snd_soc_dapm_output:
246 case snd_soc_dapm_input:
252 /* find route matching source and sink widgets */
253 list_for_each_entry(sroute, &sdev->route_list, list)
254 if (sroute->src_widget == src_widget && sroute->sink_widget == sink_widget) {
260 dev_err(sdev->dev, "error: cannot find SOF route for source %s -> %s sink\n",
261 wsource->name, wsink->name);
265 /* nothing to do if route is already set up */
269 if (tplg_ops && tplg_ops->route_setup) {
270 int ret = tplg_ops->route_setup(sdev, sroute);
276 sroute->setup = true;
280 static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
281 struct snd_soc_dapm_widget_list *list, int dir)
283 struct snd_soc_dapm_widget *widget;
284 struct snd_soc_dapm_path *p;
289 * Set up connections between widgets in the sink/source paths based on direction.
290 * Some non-SOF widgets exist in topology either for compatibility or for the
291 * purpose of connecting a pipeline from a host to a DAI in order to receive the DAPM
292 * events. But they are not handled by the firmware. So ignore them.
294 if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
295 for_each_dapm_widgets(list, i, widget) {
296 if (!widget->dobj.private)
299 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
300 if (!widget_in_list(list, p->sink))
303 if (p->sink->dobj.private) {
304 ret = sof_route_setup(sdev, widget, p->sink);
311 for_each_dapm_widgets(list, i, widget) {
312 if (!widget->dobj.private)
315 snd_soc_dapm_widget_for_each_source_path(widget, p) {
316 if (!widget_in_list(list, p->source))
319 if (p->source->dobj.private) {
320 ret = sof_route_setup(sdev, p->source, widget);
332 sof_unprepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
333 struct snd_soc_dapm_widget_list *list)
335 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
336 struct snd_sof_widget *swidget = widget->dobj.private;
337 const struct sof_ipc_tplg_widget_ops *widget_ops;
338 struct snd_soc_dapm_path *p;
340 /* skip if the widget is in use or if it is already unprepared */
341 if (!swidget || !swidget->prepared || swidget->use_count > 0)
344 widget_ops = tplg_ops ? tplg_ops->widget : NULL;
345 if (widget_ops && widget_ops[widget->id].ipc_unprepare)
346 /* unprepare the source widget */
347 widget_ops[widget->id].ipc_unprepare(swidget);
349 swidget->prepared = false;
352 /* unprepare all widgets in the sink paths */
353 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
354 if (!widget_in_list(list, p->sink))
356 if (!p->walking && p->sink->dobj.private) {
358 sof_unprepare_widgets_in_path(sdev, p->sink, list);
365 sof_prepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
366 struct snd_pcm_hw_params *fe_params,
367 struct snd_sof_platform_stream_params *platform_params,
368 struct snd_pcm_hw_params *pipeline_params, int dir,
369 struct snd_soc_dapm_widget_list *list)
371 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
372 struct snd_sof_widget *swidget = widget->dobj.private;
373 const struct sof_ipc_tplg_widget_ops *widget_ops;
374 struct snd_soc_dapm_path *p;
377 widget_ops = tplg_ops ? tplg_ops->widget : NULL;
381 if (!swidget || !widget_ops[widget->id].ipc_prepare || swidget->prepared)
384 /* prepare the source widget */
385 ret = widget_ops[widget->id].ipc_prepare(swidget, fe_params, platform_params,
386 pipeline_params, dir);
388 dev_err(sdev->dev, "failed to prepare widget %s\n", widget->name);
392 swidget->prepared = true;
395 /* prepare all widgets in the sink paths */
396 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
397 if (!widget_in_list(list, p->sink))
399 if (!p->walking && p->sink->dobj.private) {
401 ret = sof_prepare_widgets_in_path(sdev, p->sink, fe_params,
402 platform_params, pipeline_params, dir,
406 /* unprepare the source widget */
407 if (widget_ops[widget->id].ipc_unprepare &&
408 swidget && swidget->prepared) {
409 widget_ops[widget->id].ipc_unprepare(swidget);
410 swidget->prepared = false;
421 * free all widgets in the sink path starting from the source widget
422 * (DAI type for capture, AIF type for playback)
424 static int sof_free_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
425 int dir, struct snd_sof_pcm *spcm)
427 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
428 struct snd_soc_dapm_path *p;
432 if (widget->dobj.private) {
433 err = sof_widget_free(sdev, widget->dobj.private);
438 /* free all widgets in the sink paths even in case of error to keep use counts balanced */
439 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
441 if (!widget_in_list(list, p->sink))
446 err = sof_free_widgets_in_path(sdev, p->sink, dir, spcm);
457 * set up all widgets in the sink path starting from the source widget
458 * (DAI type for capture, AIF type for playback).
459 * The error path in this function ensures that all successfully set up widgets getting freed.
461 static int sof_set_up_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
462 int dir, struct snd_sof_pcm *spcm)
464 struct snd_sof_pcm_stream_pipeline_list *pipeline_list = &spcm->stream[dir].pipeline_list;
465 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
466 struct snd_sof_widget *swidget = widget->dobj.private;
467 struct snd_sof_pipeline *spipe;
468 struct snd_soc_dapm_path *p;
474 ret = sof_widget_setup(sdev, widget->dobj.private);
478 /* skip populating the pipe_widgets array if it is NULL */
479 if (!pipeline_list->pipelines)
483 * Add the widget's pipe_widget to the list of pipelines to be triggered if not
484 * already in the list. This will result in the pipelines getting added in the
485 * order source to sink.
487 for (i = 0; i < pipeline_list->count; i++) {
488 spipe = pipeline_list->pipelines[i];
489 if (spipe == swidget->spipe)
493 if (i == pipeline_list->count) {
494 pipeline_list->count++;
495 pipeline_list->pipelines[i] = swidget->spipe;
500 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
502 if (!widget_in_list(list, p->sink))
507 ret = sof_set_up_widgets_in_path(sdev, p->sink, dir, spcm);
511 sof_widget_free(sdev, swidget);
521 sof_walk_widgets_in_order(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
522 struct snd_pcm_hw_params *fe_params,
523 struct snd_sof_platform_stream_params *platform_params, int dir,
524 enum sof_widget_op op)
526 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
527 struct snd_soc_dapm_widget *widget;
535 for_each_dapm_widgets(list, i, widget) {
536 /* starting widget for playback is AIF type */
537 if (dir == SNDRV_PCM_STREAM_PLAYBACK && widget->id != snd_soc_dapm_aif_in)
540 /* starting widget for capture is DAI type */
541 if (dir == SNDRV_PCM_STREAM_CAPTURE && widget->id != snd_soc_dapm_dai_out)
545 case SOF_WIDGET_SETUP:
546 ret = sof_set_up_widgets_in_path(sdev, widget, dir, spcm);
549 case SOF_WIDGET_FREE:
550 ret = sof_free_widgets_in_path(sdev, widget, dir, spcm);
553 case SOF_WIDGET_PREPARE:
555 struct snd_pcm_hw_params pipeline_params;
559 * When walking the list of connected widgets, the pipeline_params for each
560 * widget is modified by the source widget in the path. Use a local
561 * copy of the runtime params as the pipeline_params so that the runtime
562 * params does not get overwritten.
564 memcpy(&pipeline_params, fe_params, sizeof(*fe_params));
566 ret = sof_prepare_widgets_in_path(sdev, widget, fe_params, platform_params,
567 &pipeline_params, dir, list);
570 case SOF_WIDGET_UNPREPARE:
571 sof_unprepare_widgets_in_path(sdev, widget, list);
574 dev_err(sdev->dev, "Invalid widget op %d\n", op);
578 dev_err(sdev->dev, "Failed to %s connected widgets\n", str);
586 int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
587 struct snd_pcm_hw_params *fe_params,
588 struct snd_sof_platform_stream_params *platform_params,
591 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
592 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
593 struct snd_soc_dapm_widget *widget;
596 /* nothing to set up */
601 * Prepare widgets for set up. The prepare step is used to allocate memory, assign
602 * instance ID and pick the widget configuration based on the runtime PCM params.
604 ret = sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params,
605 dir, SOF_WIDGET_PREPARE);
609 /* Set up is used to send the IPC to the DSP to create the widget */
610 ret = sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params,
611 dir, SOF_WIDGET_SETUP);
613 sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params,
614 dir, SOF_WIDGET_UNPREPARE);
619 * error in setting pipeline connections will result in route status being reset for
620 * routes that were successfully set up when the widgets are freed.
622 ret = sof_setup_pipeline_connections(sdev, list, dir);
626 /* complete pipelines */
627 for_each_dapm_widgets(list, i, widget) {
628 struct snd_sof_widget *swidget = widget->dobj.private;
629 struct snd_sof_widget *pipe_widget;
630 struct snd_sof_pipeline *spipe;
635 spipe = swidget->spipe;
637 dev_err(sdev->dev, "no pipeline found for %s\n",
638 swidget->widget->name);
643 pipe_widget = spipe->pipe_widget;
645 dev_err(sdev->dev, "error: no pipeline widget found for %s\n",
646 swidget->widget->name);
654 if (tplg_ops && tplg_ops->pipeline_complete) {
655 spipe->complete = tplg_ops->pipeline_complete(sdev, pipe_widget);
656 if (spipe->complete < 0) {
657 ret = spipe->complete;
666 sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params, dir,
668 sof_walk_widgets_in_order(sdev, spcm, NULL, NULL, dir, SOF_WIDGET_UNPREPARE);
673 int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir)
675 struct snd_sof_pcm_stream_pipeline_list *pipeline_list = &spcm->stream[dir].pipeline_list;
676 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
679 /* nothing to free */
683 /* send IPC to free widget in the DSP */
684 ret = sof_walk_widgets_in_order(sdev, spcm, NULL, NULL, dir, SOF_WIDGET_FREE);
686 /* unprepare the widget */
687 sof_walk_widgets_in_order(sdev, spcm, NULL, NULL, dir, SOF_WIDGET_UNPREPARE);
689 snd_soc_dapm_dai_free_widgets(&list);
690 spcm->stream[dir].list = NULL;
692 pipeline_list->count = 0;
698 * helper to determine if there are only D0i3 compatible
701 bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev)
703 struct snd_pcm_substream *substream;
704 struct snd_sof_pcm *spcm;
705 bool d0i3_compatible_active = false;
708 list_for_each_entry(spcm, &sdev->pcm_list, list) {
709 for_each_pcm_streams(dir) {
710 substream = spcm->stream[dir].substream;
711 if (!substream || !substream->runtime)
715 * substream->runtime being not NULL indicates
716 * that the stream is open. No need to check the
719 if (!spcm->stream[dir].d0i3_compatible)
722 d0i3_compatible_active = true;
726 return d0i3_compatible_active;
728 EXPORT_SYMBOL(snd_sof_dsp_only_d0i3_compatible_stream_active);
730 bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev)
732 struct snd_sof_pcm *spcm;
734 list_for_each_entry(spcm, &sdev->pcm_list, list) {
735 if (spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].suspend_ignored ||
736 spcm->stream[SNDRV_PCM_STREAM_CAPTURE].suspend_ignored)
743 int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
744 struct snd_sof_pcm *spcm, int dir, bool free_widget_list)
746 const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
749 /* Send PCM_FREE IPC to reset pipeline */
750 if (pcm_ops && pcm_ops->hw_free && spcm->prepared[substream->stream]) {
751 ret = pcm_ops->hw_free(sdev->component, substream);
756 spcm->prepared[substream->stream] = false;
759 ret = snd_sof_pcm_platform_hw_free(sdev, substream);
763 /* free widget list */
764 if (free_widget_list) {
765 ret = sof_widget_list_free(sdev, spcm, dir);
767 dev_err(sdev->dev, "failed to free widgets during suspend\n");
774 * Generic object lookup APIs.
777 struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
780 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
781 struct snd_sof_pcm *spcm;
783 list_for_each_entry(spcm, &sdev->pcm_list, list) {
784 /* match with PCM dai name */
785 if (strcmp(spcm->pcm.dai_name, name) == 0)
788 /* match with playback caps name if set */
789 if (*spcm->pcm.caps[0].name &&
790 !strcmp(spcm->pcm.caps[0].name, name))
793 /* match with capture caps name if set */
794 if (*spcm->pcm.caps[1].name &&
795 !strcmp(spcm->pcm.caps[1].name, name))
802 struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
803 unsigned int comp_id,
806 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
807 struct snd_sof_pcm *spcm;
810 list_for_each_entry(spcm, &sdev->pcm_list, list) {
811 for_each_pcm_streams(dir) {
812 if (spcm->stream[dir].comp_id == comp_id) {
822 struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
825 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
826 struct snd_sof_widget *swidget;
828 list_for_each_entry(swidget, &sdev->widget_list, list) {
829 if (strcmp(name, swidget->widget->name) == 0)
836 /* find widget by stream name and direction */
837 struct snd_sof_widget *
838 snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
839 const char *pcm_name, int dir)
841 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
842 struct snd_sof_widget *swidget;
843 enum snd_soc_dapm_type type;
845 if (dir == SNDRV_PCM_STREAM_PLAYBACK)
846 type = snd_soc_dapm_aif_in;
848 type = snd_soc_dapm_aif_out;
850 list_for_each_entry(swidget, &sdev->widget_list, list) {
851 if (!strcmp(pcm_name, swidget->widget->sname) &&
859 struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
862 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
863 struct snd_sof_dai *dai;
865 list_for_each_entry(dai, &sdev->dai_list, list) {
866 if (dai->name && (strcmp(name, dai->name) == 0))
873 static int sof_dai_get_clk(struct snd_soc_pcm_runtime *rtd, int clk_type)
875 struct snd_soc_component *component =
876 snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
877 struct snd_sof_dai *dai =
878 snd_sof_find_dai(component, (char *)rtd->dai_link->name);
879 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
880 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
882 /* use the tplg configured mclk if existed */
886 if (tplg_ops && tplg_ops->dai_get_clk)
887 return tplg_ops->dai_get_clk(sdev, dai, clk_type);
893 * Helper to get SSP MCLK from a pcm_runtime.
894 * Return 0 if not exist.
896 int sof_dai_get_mclk(struct snd_soc_pcm_runtime *rtd)
898 return sof_dai_get_clk(rtd, SOF_DAI_CLK_INTEL_SSP_MCLK);
900 EXPORT_SYMBOL(sof_dai_get_mclk);
903 * Helper to get SSP BCLK from a pcm_runtime.
904 * Return 0 if not exist.
906 int sof_dai_get_bclk(struct snd_soc_pcm_runtime *rtd)
908 return sof_dai_get_clk(rtd, SOF_DAI_CLK_INTEL_SSP_BCLK);
910 EXPORT_SYMBOL(sof_dai_get_bclk);
912 static struct snd_sof_of_mach *sof_of_machine_select(struct snd_sof_dev *sdev)
914 struct snd_sof_pdata *sof_pdata = sdev->pdata;
915 const struct sof_dev_desc *desc = sof_pdata->desc;
916 struct snd_sof_of_mach *mach = desc->of_machines;
921 for (; mach->compatible; mach++) {
922 if (of_machine_is_compatible(mach->compatible)) {
923 sof_pdata->tplg_filename = mach->sof_tplg_filename;
924 if (mach->fw_filename)
925 sof_pdata->fw_filename = mach->fw_filename;
935 * SOF Driver enumeration.
937 int sof_machine_check(struct snd_sof_dev *sdev)
939 struct snd_sof_pdata *sof_pdata = sdev->pdata;
940 const struct sof_dev_desc *desc = sof_pdata->desc;
941 struct snd_soc_acpi_mach *mach;
943 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_FORCE_NOCODEC_MODE)) {
944 const struct snd_sof_of_mach *of_mach;
946 if (IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC_DEBUG_SUPPORT) &&
947 sof_debug_check_flag(SOF_DBG_FORCE_NOCODEC))
951 mach = snd_sof_machine_select(sdev);
953 sof_pdata->machine = mach;
954 snd_sof_set_mach_params(mach, sdev);
958 of_mach = sof_of_machine_select(sdev);
960 sof_pdata->of_machine = of_mach;
964 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC)) {
965 dev_err(sdev->dev, "error: no matching ASoC machine driver found - aborting probe\n");
969 dev_warn(sdev->dev, "Force to use nocodec mode\n");
973 /* select nocodec mode */
974 dev_warn(sdev->dev, "Using nocodec machine driver\n");
975 mach = devm_kzalloc(sdev->dev, sizeof(*mach), GFP_KERNEL);
979 mach->drv_name = "sof-nocodec";
980 if (!sof_pdata->tplg_filename)
981 sof_pdata->tplg_filename = desc->nocodec_tplg_filename;
983 sof_pdata->machine = mach;
984 snd_sof_set_mach_params(mach, sdev);
988 EXPORT_SYMBOL(sof_machine_check);
990 int sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
992 struct snd_sof_pdata *plat_data = pdata;
993 const char *drv_name;
997 drv_name = plat_data->machine->drv_name;
998 mach = plat_data->machine;
999 size = sizeof(*plat_data->machine);
1001 /* register machine driver, pass machine info as pdata */
1002 plat_data->pdev_mach =
1003 platform_device_register_data(sdev->dev, drv_name,
1004 PLATFORM_DEVID_NONE, mach, size);
1005 if (IS_ERR(plat_data->pdev_mach))
1006 return PTR_ERR(plat_data->pdev_mach);
1008 dev_dbg(sdev->dev, "created machine %s\n",
1009 dev_name(&plat_data->pdev_mach->dev));
1013 EXPORT_SYMBOL(sof_machine_register);
1015 void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
1017 struct snd_sof_pdata *plat_data = pdata;
1019 if (!IS_ERR_OR_NULL(plat_data->pdev_mach))
1020 platform_device_unregister(plat_data->pdev_mach);
1022 EXPORT_SYMBOL(sof_machine_unregister);