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 /* continue to disable core even if IPC fails */
54 if (tplg_ops && tplg_ops->widget_free)
55 err = tplg_ops->widget_free(sdev, swidget);
58 * disable widget core. continue to route setup status and complete flag
59 * even if this fails and return the appropriate error
61 ret = snd_sof_dsp_core_put(sdev, swidget->core);
63 dev_err(sdev->dev, "error: failed to disable target core: %d for widget %s\n",
64 swidget->core, swidget->widget->name);
70 * free the scheduler widget (same as pipe_widget) associated with the current swidget.
71 * skip for static pipelines
73 if (swidget->dynamic_pipeline_widget && swidget->id != snd_soc_dapm_scheduler) {
74 ret = sof_widget_free_unlocked(sdev, pipe_widget);
79 /* clear pipeline complete */
80 if (swidget->id == snd_soc_dapm_scheduler)
81 swidget->spipe->complete = 0;
84 dev_dbg(sdev->dev, "widget %s freed\n", swidget->widget->name);
89 int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
93 mutex_lock(&swidget->setup_mutex);
94 ret = sof_widget_free_unlocked(sdev, swidget);
95 mutex_unlock(&swidget->setup_mutex);
99 EXPORT_SYMBOL(sof_widget_free);
101 static int sof_widget_setup_unlocked(struct snd_sof_dev *sdev,
102 struct snd_sof_widget *swidget)
104 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
105 bool use_count_decremented = false;
108 /* skip if there is no private data */
109 if (!swidget->private)
112 trace_sof_widget_setup(swidget);
114 /* widget already set up */
115 if (++swidget->use_count > 1)
119 * The scheduler widget for a pipeline is not part of the connected DAPM
120 * widget list and it needs to be set up before the widgets in the pipeline
121 * are set up. The use_count for the scheduler widget is incremented for every
122 * widget in a given pipeline to ensure that it is freed only after the last
123 * widget in the pipeline is freed. Skip setting up scheduler widget for static pipelines.
125 if (swidget->dynamic_pipeline_widget && swidget->id != snd_soc_dapm_scheduler) {
126 if (!swidget->spipe || !swidget->spipe->pipe_widget) {
127 dev_err(sdev->dev, "No pipeline set for %s\n", swidget->widget->name);
132 ret = sof_widget_setup_unlocked(sdev, swidget->spipe->pipe_widget);
137 /* enable widget core */
138 ret = snd_sof_dsp_core_get(sdev, swidget->core);
140 dev_err(sdev->dev, "error: failed to enable target core for widget %s\n",
141 swidget->widget->name);
142 goto pipe_widget_free;
145 /* setup widget in the DSP */
146 if (tplg_ops && tplg_ops->widget_setup) {
147 ret = tplg_ops->widget_setup(sdev, swidget);
152 /* send config for DAI components */
153 if (WIDGET_IS_DAI(swidget->id)) {
154 unsigned int flags = SOF_DAI_CONFIG_FLAGS_NONE;
156 if (tplg_ops && tplg_ops->dai_config) {
157 ret = tplg_ops->dai_config(sdev, swidget, flags, NULL);
163 /* restore kcontrols for widget */
164 if (tplg_ops && tplg_ops->control && tplg_ops->control->widget_kcontrol_setup) {
165 ret = tplg_ops->control->widget_kcontrol_setup(sdev, swidget);
170 dev_dbg(sdev->dev, "widget %s setup complete\n", swidget->widget->name);
175 /* widget use_count and core ref_count will both be decremented by sof_widget_free() */
176 sof_widget_free_unlocked(sdev, swidget);
177 use_count_decremented = true;
179 snd_sof_dsp_core_put(sdev, swidget->core);
181 if (swidget->id != snd_soc_dapm_scheduler)
182 sof_widget_free_unlocked(sdev, swidget->spipe->pipe_widget);
184 if (!use_count_decremented)
185 swidget->use_count--;
190 int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
194 mutex_lock(&swidget->setup_mutex);
195 ret = sof_widget_setup_unlocked(sdev, swidget);
196 mutex_unlock(&swidget->setup_mutex);
200 EXPORT_SYMBOL(sof_widget_setup);
202 int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
203 struct snd_soc_dapm_widget *wsink)
205 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
206 struct snd_sof_widget *src_widget = wsource->dobj.private;
207 struct snd_sof_widget *sink_widget = wsink->dobj.private;
208 struct snd_sof_route *sroute;
209 bool route_found = false;
211 /* ignore routes involving virtual widgets in topology */
212 switch (src_widget->id) {
213 case snd_soc_dapm_out_drv:
214 case snd_soc_dapm_output:
215 case snd_soc_dapm_input:
221 switch (sink_widget->id) {
222 case snd_soc_dapm_out_drv:
223 case snd_soc_dapm_output:
224 case snd_soc_dapm_input:
230 /* find route matching source and sink widgets */
231 list_for_each_entry(sroute, &sdev->route_list, list)
232 if (sroute->src_widget == src_widget && sroute->sink_widget == sink_widget) {
238 dev_err(sdev->dev, "error: cannot find SOF route for source %s -> %s sink\n",
239 wsource->name, wsink->name);
243 /* nothing to do if route is already set up */
247 if (tplg_ops && tplg_ops->route_setup) {
248 int ret = tplg_ops->route_setup(sdev, sroute);
254 sroute->setup = true;
258 static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
259 struct snd_soc_dapm_widget_list *list, int dir)
261 struct snd_soc_dapm_widget *widget;
262 struct snd_soc_dapm_path *p;
267 * Set up connections between widgets in the sink/source paths based on direction.
268 * Some non-SOF widgets exist in topology either for compatibility or for the
269 * purpose of connecting a pipeline from a host to a DAI in order to receive the DAPM
270 * events. But they are not handled by the firmware. So ignore them.
272 if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
273 for_each_dapm_widgets(list, i, widget) {
274 if (!widget->dobj.private)
277 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
278 if (!widget_in_list(list, p->sink))
281 if (p->sink->dobj.private) {
282 ret = sof_route_setup(sdev, widget, p->sink);
289 for_each_dapm_widgets(list, i, widget) {
290 if (!widget->dobj.private)
293 snd_soc_dapm_widget_for_each_source_path(widget, p) {
294 if (!widget_in_list(list, p->source))
297 if (p->source->dobj.private) {
298 ret = sof_route_setup(sdev, p->source, widget);
310 sof_unprepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
311 struct snd_soc_dapm_widget_list *list)
313 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
314 struct snd_sof_widget *swidget = widget->dobj.private;
315 const struct sof_ipc_tplg_widget_ops *widget_ops;
316 struct snd_soc_dapm_path *p;
318 /* skip if the widget is in use or if it is already unprepared */
319 if (!swidget || !swidget->prepared || swidget->use_count > 0)
322 widget_ops = tplg_ops ? tplg_ops->widget : NULL;
323 if (widget_ops && widget_ops[widget->id].ipc_unprepare)
324 /* unprepare the source widget */
325 widget_ops[widget->id].ipc_unprepare(swidget);
327 swidget->prepared = false;
330 /* unprepare all widgets in the sink paths */
331 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
332 if (!widget_in_list(list, p->sink))
334 if (!p->walking && p->sink->dobj.private) {
336 sof_unprepare_widgets_in_path(sdev, p->sink, list);
343 sof_prepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
344 struct snd_pcm_hw_params *fe_params,
345 struct snd_sof_platform_stream_params *platform_params,
346 struct snd_pcm_hw_params *pipeline_params, int dir,
347 struct snd_soc_dapm_widget_list *list)
349 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
350 struct snd_sof_widget *swidget = widget->dobj.private;
351 const struct sof_ipc_tplg_widget_ops *widget_ops;
352 struct snd_soc_dapm_path *p;
355 widget_ops = tplg_ops ? tplg_ops->widget : NULL;
359 if (!swidget || !widget_ops[widget->id].ipc_prepare || swidget->prepared)
362 /* prepare the source widget */
363 ret = widget_ops[widget->id].ipc_prepare(swidget, fe_params, platform_params,
364 pipeline_params, dir);
366 dev_err(sdev->dev, "failed to prepare widget %s\n", widget->name);
370 swidget->prepared = true;
373 /* prepare all widgets in the sink paths */
374 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
375 if (!widget_in_list(list, p->sink))
377 if (!p->walking && p->sink->dobj.private) {
379 ret = sof_prepare_widgets_in_path(sdev, p->sink, fe_params,
380 platform_params, pipeline_params, dir,
384 /* unprepare the source widget */
385 if (widget_ops[widget->id].ipc_unprepare &&
386 swidget && swidget->prepared) {
387 widget_ops[widget->id].ipc_unprepare(swidget);
388 swidget->prepared = false;
399 * free all widgets in the sink path starting from the source widget
400 * (DAI type for capture, AIF type for playback)
402 static int sof_free_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
403 int dir, struct snd_sof_pcm *spcm)
405 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
406 struct snd_soc_dapm_path *p;
410 if (widget->dobj.private) {
411 err = sof_widget_free(sdev, widget->dobj.private);
416 /* free all widgets in the sink paths even in case of error to keep use counts balanced */
417 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
419 if (!widget_in_list(list, p->sink))
424 err = sof_free_widgets_in_path(sdev, p->sink, dir, spcm);
435 * set up all widgets in the sink path starting from the source widget
436 * (DAI type for capture, AIF type for playback).
437 * The error path in this function ensures that all successfully set up widgets getting freed.
439 static int sof_set_up_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
440 int dir, struct snd_sof_pcm *spcm)
442 struct snd_sof_pcm_stream_pipeline_list *pipeline_list = &spcm->stream[dir].pipeline_list;
443 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
444 struct snd_sof_widget *swidget = widget->dobj.private;
445 struct snd_sof_pipeline *spipe;
446 struct snd_soc_dapm_path *p;
452 ret = sof_widget_setup(sdev, widget->dobj.private);
456 /* skip populating the pipe_widgets array if it is NULL */
457 if (!pipeline_list->pipelines)
461 * Add the widget's pipe_widget to the list of pipelines to be triggered if not
462 * already in the list. This will result in the pipelines getting added in the
463 * order source to sink.
465 for (i = 0; i < pipeline_list->count; i++) {
466 spipe = pipeline_list->pipelines[i];
467 if (spipe == swidget->spipe)
471 if (i == pipeline_list->count) {
472 pipeline_list->count++;
473 pipeline_list->pipelines[i] = swidget->spipe;
478 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
480 if (!widget_in_list(list, p->sink))
485 ret = sof_set_up_widgets_in_path(sdev, p->sink, dir, spcm);
489 sof_widget_free(sdev, swidget);
499 sof_walk_widgets_in_order(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
500 struct snd_pcm_hw_params *fe_params,
501 struct snd_sof_platform_stream_params *platform_params, int dir,
502 enum sof_widget_op op)
504 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
505 struct snd_soc_dapm_widget *widget;
513 for_each_dapm_widgets(list, i, widget) {
514 /* starting widget for playback is AIF type */
515 if (dir == SNDRV_PCM_STREAM_PLAYBACK && widget->id != snd_soc_dapm_aif_in)
518 /* starting widget for capture is DAI type */
519 if (dir == SNDRV_PCM_STREAM_CAPTURE && widget->id != snd_soc_dapm_dai_out)
523 case SOF_WIDGET_SETUP:
524 ret = sof_set_up_widgets_in_path(sdev, widget, dir, spcm);
527 case SOF_WIDGET_FREE:
528 ret = sof_free_widgets_in_path(sdev, widget, dir, spcm);
531 case SOF_WIDGET_PREPARE:
533 struct snd_pcm_hw_params pipeline_params;
537 * When walking the list of connected widgets, the pipeline_params for each
538 * widget is modified by the source widget in the path. Use a local
539 * copy of the runtime params as the pipeline_params so that the runtime
540 * params does not get overwritten.
542 memcpy(&pipeline_params, fe_params, sizeof(*fe_params));
544 ret = sof_prepare_widgets_in_path(sdev, widget, fe_params, platform_params,
545 &pipeline_params, dir, list);
548 case SOF_WIDGET_UNPREPARE:
549 sof_unprepare_widgets_in_path(sdev, widget, list);
552 dev_err(sdev->dev, "Invalid widget op %d\n", op);
556 dev_err(sdev->dev, "Failed to %s connected widgets\n", str);
564 int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
565 struct snd_pcm_hw_params *fe_params,
566 struct snd_sof_platform_stream_params *platform_params,
569 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
570 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
571 struct snd_soc_dapm_widget *widget;
574 /* nothing to set up */
579 * Prepare widgets for set up. The prepare step is used to allocate memory, assign
580 * instance ID and pick the widget configuration based on the runtime PCM params.
582 ret = sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params,
583 dir, SOF_WIDGET_PREPARE);
587 /* Set up is used to send the IPC to the DSP to create the widget */
588 ret = sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params,
589 dir, SOF_WIDGET_SETUP);
591 ret = sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params,
592 dir, SOF_WIDGET_UNPREPARE);
597 * error in setting pipeline connections will result in route status being reset for
598 * routes that were successfully set up when the widgets are freed.
600 ret = sof_setup_pipeline_connections(sdev, list, dir);
604 /* complete pipelines */
605 for_each_dapm_widgets(list, i, widget) {
606 struct snd_sof_widget *swidget = widget->dobj.private;
607 struct snd_sof_widget *pipe_widget;
608 struct snd_sof_pipeline *spipe;
613 spipe = swidget->spipe;
615 dev_err(sdev->dev, "no pipeline found for %s\n",
616 swidget->widget->name);
621 pipe_widget = spipe->pipe_widget;
623 dev_err(sdev->dev, "error: no pipeline widget found for %s\n",
624 swidget->widget->name);
632 if (tplg_ops && tplg_ops->pipeline_complete) {
633 spipe->complete = tplg_ops->pipeline_complete(sdev, pipe_widget);
634 if (spipe->complete < 0) {
635 ret = spipe->complete;
644 sof_walk_widgets_in_order(sdev, spcm, fe_params, platform_params, dir,
646 sof_walk_widgets_in_order(sdev, spcm, NULL, NULL, dir, SOF_WIDGET_UNPREPARE);
651 int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir)
653 struct snd_sof_pcm_stream_pipeline_list *pipeline_list = &spcm->stream[dir].pipeline_list;
654 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
657 /* nothing to free */
661 /* send IPC to free widget in the DSP */
662 ret = sof_walk_widgets_in_order(sdev, spcm, NULL, NULL, dir, SOF_WIDGET_FREE);
664 /* unprepare the widget */
665 sof_walk_widgets_in_order(sdev, spcm, NULL, NULL, dir, SOF_WIDGET_UNPREPARE);
667 snd_soc_dapm_dai_free_widgets(&list);
668 spcm->stream[dir].list = NULL;
670 pipeline_list->count = 0;
676 * helper to determine if there are only D0i3 compatible
679 bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev)
681 struct snd_pcm_substream *substream;
682 struct snd_sof_pcm *spcm;
683 bool d0i3_compatible_active = false;
686 list_for_each_entry(spcm, &sdev->pcm_list, list) {
687 for_each_pcm_streams(dir) {
688 substream = spcm->stream[dir].substream;
689 if (!substream || !substream->runtime)
693 * substream->runtime being not NULL indicates
694 * that the stream is open. No need to check the
697 if (!spcm->stream[dir].d0i3_compatible)
700 d0i3_compatible_active = true;
704 return d0i3_compatible_active;
706 EXPORT_SYMBOL(snd_sof_dsp_only_d0i3_compatible_stream_active);
708 bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev)
710 struct snd_sof_pcm *spcm;
712 list_for_each_entry(spcm, &sdev->pcm_list, list) {
713 if (spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].suspend_ignored ||
714 spcm->stream[SNDRV_PCM_STREAM_CAPTURE].suspend_ignored)
721 int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
722 struct snd_sof_pcm *spcm, int dir, bool free_widget_list)
724 const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
727 /* Send PCM_FREE IPC to reset pipeline */
728 if (pcm_ops && pcm_ops->hw_free && spcm->prepared[substream->stream]) {
729 ret = pcm_ops->hw_free(sdev->component, substream);
734 spcm->prepared[substream->stream] = false;
737 ret = snd_sof_pcm_platform_hw_free(sdev, substream);
741 /* free widget list */
742 if (free_widget_list) {
743 ret = sof_widget_list_free(sdev, spcm, dir);
745 dev_err(sdev->dev, "failed to free widgets during suspend\n");
752 * Generic object lookup APIs.
755 struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
758 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
759 struct snd_sof_pcm *spcm;
761 list_for_each_entry(spcm, &sdev->pcm_list, list) {
762 /* match with PCM dai name */
763 if (strcmp(spcm->pcm.dai_name, name) == 0)
766 /* match with playback caps name if set */
767 if (*spcm->pcm.caps[0].name &&
768 !strcmp(spcm->pcm.caps[0].name, name))
771 /* match with capture caps name if set */
772 if (*spcm->pcm.caps[1].name &&
773 !strcmp(spcm->pcm.caps[1].name, name))
780 struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
781 unsigned int comp_id,
784 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
785 struct snd_sof_pcm *spcm;
788 list_for_each_entry(spcm, &sdev->pcm_list, list) {
789 for_each_pcm_streams(dir) {
790 if (spcm->stream[dir].comp_id == comp_id) {
800 struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
803 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
804 struct snd_sof_widget *swidget;
806 list_for_each_entry(swidget, &sdev->widget_list, list) {
807 if (strcmp(name, swidget->widget->name) == 0)
814 /* find widget by stream name and direction */
815 struct snd_sof_widget *
816 snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
817 const char *pcm_name, int dir)
819 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
820 struct snd_sof_widget *swidget;
821 enum snd_soc_dapm_type type;
823 if (dir == SNDRV_PCM_STREAM_PLAYBACK)
824 type = snd_soc_dapm_aif_in;
826 type = snd_soc_dapm_aif_out;
828 list_for_each_entry(swidget, &sdev->widget_list, list) {
829 if (!strcmp(pcm_name, swidget->widget->sname) &&
837 struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
840 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
841 struct snd_sof_dai *dai;
843 list_for_each_entry(dai, &sdev->dai_list, list) {
844 if (dai->name && (strcmp(name, dai->name) == 0))
851 static int sof_dai_get_clk(struct snd_soc_pcm_runtime *rtd, int clk_type)
853 struct snd_soc_component *component =
854 snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
855 struct snd_sof_dai *dai =
856 snd_sof_find_dai(component, (char *)rtd->dai_link->name);
857 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
858 const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
860 /* use the tplg configured mclk if existed */
864 if (tplg_ops && tplg_ops->dai_get_clk)
865 return tplg_ops->dai_get_clk(sdev, dai, clk_type);
871 * Helper to get SSP MCLK from a pcm_runtime.
872 * Return 0 if not exist.
874 int sof_dai_get_mclk(struct snd_soc_pcm_runtime *rtd)
876 return sof_dai_get_clk(rtd, SOF_DAI_CLK_INTEL_SSP_MCLK);
878 EXPORT_SYMBOL(sof_dai_get_mclk);
881 * Helper to get SSP BCLK from a pcm_runtime.
882 * Return 0 if not exist.
884 int sof_dai_get_bclk(struct snd_soc_pcm_runtime *rtd)
886 return sof_dai_get_clk(rtd, SOF_DAI_CLK_INTEL_SSP_BCLK);
888 EXPORT_SYMBOL(sof_dai_get_bclk);
890 static struct snd_sof_of_mach *sof_of_machine_select(struct snd_sof_dev *sdev)
892 struct snd_sof_pdata *sof_pdata = sdev->pdata;
893 const struct sof_dev_desc *desc = sof_pdata->desc;
894 struct snd_sof_of_mach *mach = desc->of_machines;
899 for (; mach->compatible; mach++) {
900 if (of_machine_is_compatible(mach->compatible)) {
901 sof_pdata->tplg_filename = mach->sof_tplg_filename;
902 if (mach->fw_filename)
903 sof_pdata->fw_filename = mach->fw_filename;
913 * SOF Driver enumeration.
915 int sof_machine_check(struct snd_sof_dev *sdev)
917 struct snd_sof_pdata *sof_pdata = sdev->pdata;
918 const struct sof_dev_desc *desc = sof_pdata->desc;
919 struct snd_soc_acpi_mach *mach;
921 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_FORCE_NOCODEC_MODE)) {
922 const struct snd_sof_of_mach *of_mach;
924 if (IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC_DEBUG_SUPPORT) &&
925 sof_debug_check_flag(SOF_DBG_FORCE_NOCODEC))
929 mach = snd_sof_machine_select(sdev);
931 sof_pdata->machine = mach;
932 snd_sof_set_mach_params(mach, sdev);
936 of_mach = sof_of_machine_select(sdev);
938 sof_pdata->of_machine = of_mach;
942 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC)) {
943 dev_err(sdev->dev, "error: no matching ASoC machine driver found - aborting probe\n");
947 dev_warn(sdev->dev, "Force to use nocodec mode\n");
951 /* select nocodec mode */
952 dev_warn(sdev->dev, "Using nocodec machine driver\n");
953 mach = devm_kzalloc(sdev->dev, sizeof(*mach), GFP_KERNEL);
957 mach->drv_name = "sof-nocodec";
958 if (!sof_pdata->tplg_filename)
959 sof_pdata->tplg_filename = desc->nocodec_tplg_filename;
961 sof_pdata->machine = mach;
962 snd_sof_set_mach_params(mach, sdev);
966 EXPORT_SYMBOL(sof_machine_check);
968 int sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
970 struct snd_sof_pdata *plat_data = pdata;
971 const char *drv_name;
975 drv_name = plat_data->machine->drv_name;
976 mach = plat_data->machine;
977 size = sizeof(*plat_data->machine);
979 /* register machine driver, pass machine info as pdata */
980 plat_data->pdev_mach =
981 platform_device_register_data(sdev->dev, drv_name,
982 PLATFORM_DEVID_NONE, mach, size);
983 if (IS_ERR(plat_data->pdev_mach))
984 return PTR_ERR(plat_data->pdev_mach);
986 dev_dbg(sdev->dev, "created machine %s\n",
987 dev_name(&plat_data->pdev_mach->dev));
991 EXPORT_SYMBOL(sof_machine_register);
993 void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
995 struct snd_sof_pdata *plat_data = pdata;
997 if (!IS_ERR_OR_NULL(plat_data->pdev_mach))
998 platform_device_unregister(plat_data->pdev_mach);
1000 EXPORT_SYMBOL(sof_machine_unregister);