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 = sdev->ipc->ops->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->route_free)
25 tplg_ops->route_free(sdev, sroute);
27 sroute->setup = false;
31 int sof_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
33 const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
37 if (!swidget->private)
40 trace_sof_widget_free(swidget);
42 /* only free when use_count is 0 */
43 if (--swidget->use_count)
46 /* reset route setup status for all routes that contain this widget */
47 sof_reset_route_setup_status(sdev, swidget);
49 /* continue to disable core even if IPC fails */
50 if (tplg_ops->widget_free)
51 err = tplg_ops->widget_free(sdev, swidget);
54 * disable widget core. continue to route setup status and complete flag
55 * even if this fails and return the appropriate error
57 ret = snd_sof_dsp_core_put(sdev, swidget->core);
59 dev_err(sdev->dev, "error: failed to disable target core: %d for widget %s\n",
60 swidget->core, swidget->widget->name);
66 * free the scheduler widget (same as pipe_widget) associated with the current swidget.
67 * skip for static pipelines
69 if (swidget->dynamic_pipeline_widget && swidget->id != snd_soc_dapm_scheduler) {
70 ret = sof_widget_free(sdev, swidget->pipe_widget);
73 swidget->pipe_widget->complete = 0;
77 dev_dbg(sdev->dev, "widget %s freed\n", swidget->widget->name);
81 EXPORT_SYMBOL(sof_widget_free);
83 int sof_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
85 const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
88 /* skip if there is no private data */
89 if (!swidget->private)
92 trace_sof_widget_setup(swidget);
94 /* widget already set up */
95 if (++swidget->use_count > 1)
99 * The scheduler widget for a pipeline is not part of the connected DAPM
100 * widget list and it needs to be set up before the widgets in the pipeline
101 * are set up. The use_count for the scheduler widget is incremented for every
102 * widget in a given pipeline to ensure that it is freed only after the last
103 * widget in the pipeline is freed. Skip setting up scheduler widget for static pipelines.
105 if (swidget->dynamic_pipeline_widget && swidget->id != snd_soc_dapm_scheduler) {
106 if (!swidget->pipe_widget) {
107 dev_err(sdev->dev, "No scheduler widget set for %s\n",
108 swidget->widget->name);
113 ret = sof_widget_setup(sdev, swidget->pipe_widget);
118 /* enable widget core */
119 ret = snd_sof_dsp_core_get(sdev, swidget->core);
121 dev_err(sdev->dev, "error: failed to enable target core for widget %s\n",
122 swidget->widget->name);
123 goto pipe_widget_free;
126 /* setup widget in the DSP */
127 if (tplg_ops->widget_setup) {
128 ret = tplg_ops->widget_setup(sdev, swidget);
133 /* send config for DAI components */
134 if (WIDGET_IS_DAI(swidget->id)) {
135 unsigned int flags = SOF_DAI_CONFIG_FLAGS_NONE;
137 if (tplg_ops->dai_config) {
138 ret = tplg_ops->dai_config(sdev, swidget, flags, NULL);
144 /* restore kcontrols for widget */
145 if (tplg_ops->control->widget_kcontrol_setup) {
146 ret = tplg_ops->control->widget_kcontrol_setup(sdev, swidget);
151 dev_dbg(sdev->dev, "widget %s setup complete\n", swidget->widget->name);
156 /* widget use_count and core ref_count will both be decremented by sof_widget_free() */
157 sof_widget_free(sdev, swidget);
159 snd_sof_dsp_core_put(sdev, swidget->core);
161 if (swidget->id != snd_soc_dapm_scheduler)
162 sof_widget_free(sdev, swidget->pipe_widget);
164 swidget->use_count--;
167 EXPORT_SYMBOL(sof_widget_setup);
169 int sof_route_setup(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *wsource,
170 struct snd_soc_dapm_widget *wsink)
172 const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg;
173 struct snd_sof_widget *src_widget = wsource->dobj.private;
174 struct snd_sof_widget *sink_widget = wsink->dobj.private;
175 struct snd_sof_route *sroute;
176 bool route_found = false;
179 /* ignore routes involving virtual widgets in topology */
180 switch (src_widget->id) {
181 case snd_soc_dapm_out_drv:
182 case snd_soc_dapm_output:
183 case snd_soc_dapm_input:
189 switch (sink_widget->id) {
190 case snd_soc_dapm_out_drv:
191 case snd_soc_dapm_output:
192 case snd_soc_dapm_input:
198 /* find route matching source and sink widgets */
199 list_for_each_entry(sroute, &sdev->route_list, list)
200 if (sroute->src_widget == src_widget && sroute->sink_widget == sink_widget) {
206 dev_err(sdev->dev, "error: cannot find SOF route for source %s -> %s sink\n",
207 wsource->name, wsink->name);
211 /* nothing to do if route is already set up */
215 ret = ipc_tplg_ops->route_setup(sdev, sroute);
219 sroute->setup = true;
223 static int sof_setup_pipeline_connections(struct snd_sof_dev *sdev,
224 struct snd_soc_dapm_widget_list *list, int dir)
226 struct snd_soc_dapm_widget *widget;
227 struct snd_soc_dapm_path *p;
232 * Set up connections between widgets in the sink/source paths based on direction.
233 * Some non-SOF widgets exist in topology either for compatibility or for the
234 * purpose of connecting a pipeline from a host to a DAI in order to receive the DAPM
235 * events. But they are not handled by the firmware. So ignore them.
237 if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
238 for_each_dapm_widgets(list, i, widget) {
239 if (!widget->dobj.private)
242 snd_soc_dapm_widget_for_each_sink_path(widget, p)
243 if (p->sink->dobj.private) {
244 ret = sof_route_setup(sdev, widget, p->sink);
250 for_each_dapm_widgets(list, i, widget) {
251 if (!widget->dobj.private)
254 snd_soc_dapm_widget_for_each_source_path(widget, p)
255 if (p->source->dobj.private) {
256 ret = sof_route_setup(sdev, p->source, widget);
267 sof_unprepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget)
269 const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg;
270 const struct sof_ipc_tplg_widget_ops *widget_ops = ipc_tplg_ops->widget;
271 struct snd_sof_widget *swidget = widget->dobj.private;
272 struct snd_soc_dapm_path *p;
274 /* skip if the widget is in use or if it is already unprepared */
275 if (!swidget || !swidget->prepared || swidget->use_count > 0)
278 if (widget_ops[widget->id].ipc_unprepare)
279 /* unprepare the source widget */
280 widget_ops[widget->id].ipc_unprepare(swidget);
282 swidget->prepared = false;
285 /* unprepare all widgets in the sink paths */
286 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
287 if (!p->walking && p->sink->dobj.private) {
289 sof_unprepare_widgets_in_path(sdev, p->sink);
296 sof_prepare_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
297 struct snd_pcm_hw_params *fe_params,
298 struct snd_sof_platform_stream_params *platform_params,
299 struct snd_pcm_hw_params *pipeline_params, int dir)
301 const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg;
302 const struct sof_ipc_tplg_widget_ops *widget_ops = ipc_tplg_ops->widget;
303 struct snd_sof_widget *swidget = widget->dobj.private;
304 struct snd_soc_dapm_path *p;
307 if (!swidget || !widget_ops[widget->id].ipc_prepare || swidget->prepared)
310 /* prepare the source widget */
311 ret = widget_ops[widget->id].ipc_prepare(swidget, fe_params, platform_params,
312 pipeline_params, dir);
314 dev_err(sdev->dev, "failed to prepare widget %s\n", widget->name);
318 swidget->prepared = true;
321 /* prepare all widgets in the sink paths */
322 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
323 if (!p->walking && p->sink->dobj.private) {
325 ret = sof_prepare_widgets_in_path(sdev, p->sink, fe_params,
326 platform_params, pipeline_params, dir);
329 /* unprepare the source widget */
330 if (widget_ops[widget->id].ipc_unprepare &&
331 swidget && swidget->prepared) {
332 widget_ops[widget->id].ipc_unprepare(swidget);
333 swidget->prepared = false;
344 * free all widgets in the sink path starting from the source widget
345 * (DAI type for capture, AIF type for playback)
347 static int sof_free_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
350 struct snd_soc_dapm_path *p;
354 /* free all widgets even in case of error to keep use counts balanced */
355 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
356 if (!p->walking && p->sink->dobj.private && widget->dobj.private) {
358 if (WIDGET_IS_AIF_OR_DAI(widget->id)) {
359 err = sof_widget_free(sdev, widget->dobj.private);
364 err = sof_widget_free(sdev, p->sink->dobj.private);
368 err = sof_free_widgets_in_path(sdev, p->sink, dir);
379 * set up all widgets in the sink path starting from the source widget
380 * (DAI type for capture, AIF type for playback).
381 * The error path in this function ensures that all successfully set up widgets getting freed.
383 static int sof_set_up_widgets_in_path(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget *widget,
386 struct snd_soc_dapm_path *p;
389 snd_soc_dapm_widget_for_each_sink_path(widget, p) {
390 if (!p->walking && p->sink->dobj.private && widget->dobj.private) {
392 if (WIDGET_IS_AIF_OR_DAI(widget->id)) {
393 ret = sof_widget_setup(sdev, widget->dobj.private);
398 ret = sof_widget_setup(sdev, p->sink->dobj.private);
400 if (WIDGET_IS_AIF_OR_DAI(widget->id))
401 sof_widget_free(sdev, widget->dobj.private);
405 ret = sof_set_up_widgets_in_path(sdev, p->sink, dir);
407 if (WIDGET_IS_AIF_OR_DAI(widget->id))
408 sof_widget_free(sdev, widget->dobj.private);
409 sof_widget_free(sdev, p->sink->dobj.private);
422 sof_walk_widgets_in_order(struct snd_sof_dev *sdev, struct snd_soc_dapm_widget_list *list,
423 struct snd_pcm_hw_params *fe_params,
424 struct snd_sof_platform_stream_params *platform_params, int dir,
425 enum sof_widget_op op)
427 struct snd_soc_dapm_widget *widget;
432 for_each_dapm_widgets(list, i, widget) {
433 /* starting widget for playback is AIF type */
434 if (dir == SNDRV_PCM_STREAM_PLAYBACK && widget->id != snd_soc_dapm_aif_in)
437 /* starting widget for capture is DAI type */
438 if (dir == SNDRV_PCM_STREAM_CAPTURE && widget->id != snd_soc_dapm_dai_out)
442 case SOF_WIDGET_SETUP:
443 ret = sof_set_up_widgets_in_path(sdev, widget, dir);
446 case SOF_WIDGET_FREE:
447 ret = sof_free_widgets_in_path(sdev, widget, dir);
450 case SOF_WIDGET_PREPARE:
452 struct snd_pcm_hw_params pipeline_params;
456 * When walking the list of connected widgets, the pipeline_params for each
457 * widget is modified by the source widget in the path. Use a local
458 * copy of the runtime params as the pipeline_params so that the runtime
459 * params does not get overwritten.
461 memcpy(&pipeline_params, fe_params, sizeof(*fe_params));
463 ret = sof_prepare_widgets_in_path(sdev, widget, fe_params,
464 platform_params, &pipeline_params, dir);
467 case SOF_WIDGET_UNPREPARE:
468 sof_unprepare_widgets_in_path(sdev, widget);
471 dev_err(sdev->dev, "Invalid widget op %d\n", op);
475 dev_err(sdev->dev, "Failed to %s connected widgets\n", str);
483 int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,
484 struct snd_pcm_hw_params *fe_params,
485 struct snd_sof_platform_stream_params *platform_params,
488 const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg;
489 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
490 struct snd_soc_dapm_widget *widget;
493 /* nothing to set up */
498 * Prepare widgets for set up. The prepare step is used to allocate memory, assign
499 * instance ID and pick the widget configuration based on the runtime PCM params.
501 ret = sof_walk_widgets_in_order(sdev, list, fe_params, platform_params,
502 dir, SOF_WIDGET_PREPARE);
506 /* Set up is used to send the IPC to the DSP to create the widget */
507 ret = sof_walk_widgets_in_order(sdev, list, fe_params, platform_params,
508 dir, SOF_WIDGET_SETUP);
510 ret = sof_walk_widgets_in_order(sdev, list, fe_params, platform_params,
511 dir, SOF_WIDGET_UNPREPARE);
516 * error in setting pipeline connections will result in route status being reset for
517 * routes that were successfully set up when the widgets are freed.
519 ret = sof_setup_pipeline_connections(sdev, list, dir);
523 /* complete pipelines */
524 for_each_dapm_widgets(list, i, widget) {
525 struct snd_sof_widget *swidget = widget->dobj.private;
526 struct snd_sof_widget *pipe_widget;
531 pipe_widget = swidget->pipe_widget;
533 dev_err(sdev->dev, "error: no pipeline widget found for %s\n",
534 swidget->widget->name);
539 if (pipe_widget->complete)
542 if (ipc_tplg_ops->pipeline_complete) {
543 pipe_widget->complete = ipc_tplg_ops->pipeline_complete(sdev, pipe_widget);
544 if (pipe_widget->complete < 0) {
545 ret = pipe_widget->complete;
554 sof_walk_widgets_in_order(sdev, list, fe_params, platform_params, dir,
556 sof_walk_widgets_in_order(sdev, list, NULL, NULL, dir, SOF_WIDGET_UNPREPARE);
561 int sof_widget_list_free(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, int dir)
563 struct snd_soc_dapm_widget_list *list = spcm->stream[dir].list;
566 /* nothing to free */
570 /* send IPC to free widget in the DSP */
571 ret = sof_walk_widgets_in_order(sdev, list, NULL, NULL, dir, SOF_WIDGET_FREE);
573 /* unprepare the widget */
574 sof_walk_widgets_in_order(sdev, list, NULL, NULL, dir, SOF_WIDGET_UNPREPARE);
576 snd_soc_dapm_dai_free_widgets(&list);
577 spcm->stream[dir].list = NULL;
583 * helper to determine if there are only D0i3 compatible
586 bool snd_sof_dsp_only_d0i3_compatible_stream_active(struct snd_sof_dev *sdev)
588 struct snd_pcm_substream *substream;
589 struct snd_sof_pcm *spcm;
590 bool d0i3_compatible_active = false;
593 list_for_each_entry(spcm, &sdev->pcm_list, list) {
594 for_each_pcm_streams(dir) {
595 substream = spcm->stream[dir].substream;
596 if (!substream || !substream->runtime)
600 * substream->runtime being not NULL indicates
601 * that the stream is open. No need to check the
604 if (!spcm->stream[dir].d0i3_compatible)
607 d0i3_compatible_active = true;
611 return d0i3_compatible_active;
613 EXPORT_SYMBOL(snd_sof_dsp_only_d0i3_compatible_stream_active);
615 bool snd_sof_stream_suspend_ignored(struct snd_sof_dev *sdev)
617 struct snd_sof_pcm *spcm;
619 list_for_each_entry(spcm, &sdev->pcm_list, list) {
620 if (spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].suspend_ignored ||
621 spcm->stream[SNDRV_PCM_STREAM_CAPTURE].suspend_ignored)
628 int sof_pcm_stream_free(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
629 struct snd_sof_pcm *spcm, int dir, bool free_widget_list)
631 const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
634 /* Send PCM_FREE IPC to reset pipeline */
635 if (pcm_ops->hw_free && spcm->prepared[substream->stream]) {
636 ret = pcm_ops->hw_free(sdev->component, substream);
641 spcm->prepared[substream->stream] = false;
644 ret = snd_sof_pcm_platform_hw_free(sdev, substream);
648 /* free widget list */
649 if (free_widget_list) {
650 ret = sof_widget_list_free(sdev, spcm, dir);
652 dev_err(sdev->dev, "failed to free widgets during suspend\n");
659 * Generic object lookup APIs.
662 struct snd_sof_pcm *snd_sof_find_spcm_name(struct snd_soc_component *scomp,
665 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
666 struct snd_sof_pcm *spcm;
668 list_for_each_entry(spcm, &sdev->pcm_list, list) {
669 /* match with PCM dai name */
670 if (strcmp(spcm->pcm.dai_name, name) == 0)
673 /* match with playback caps name if set */
674 if (*spcm->pcm.caps[0].name &&
675 !strcmp(spcm->pcm.caps[0].name, name))
678 /* match with capture caps name if set */
679 if (*spcm->pcm.caps[1].name &&
680 !strcmp(spcm->pcm.caps[1].name, name))
687 struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,
688 unsigned int comp_id,
691 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
692 struct snd_sof_pcm *spcm;
695 list_for_each_entry(spcm, &sdev->pcm_list, list) {
696 for_each_pcm_streams(dir) {
697 if (spcm->stream[dir].comp_id == comp_id) {
707 struct snd_sof_widget *snd_sof_find_swidget(struct snd_soc_component *scomp,
710 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
711 struct snd_sof_widget *swidget;
713 list_for_each_entry(swidget, &sdev->widget_list, list) {
714 if (strcmp(name, swidget->widget->name) == 0)
721 /* find widget by stream name and direction */
722 struct snd_sof_widget *
723 snd_sof_find_swidget_sname(struct snd_soc_component *scomp,
724 const char *pcm_name, int dir)
726 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
727 struct snd_sof_widget *swidget;
728 enum snd_soc_dapm_type type;
730 if (dir == SNDRV_PCM_STREAM_PLAYBACK)
731 type = snd_soc_dapm_aif_in;
733 type = snd_soc_dapm_aif_out;
735 list_for_each_entry(swidget, &sdev->widget_list, list) {
736 if (!strcmp(pcm_name, swidget->widget->sname) &&
744 struct snd_sof_dai *snd_sof_find_dai(struct snd_soc_component *scomp,
747 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
748 struct snd_sof_dai *dai;
750 list_for_each_entry(dai, &sdev->dai_list, list) {
751 if (dai->name && (strcmp(name, dai->name) == 0))
758 static int sof_dai_get_clk(struct snd_soc_pcm_runtime *rtd, int clk_type)
760 struct snd_soc_component *component =
761 snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
762 struct snd_sof_dai *dai =
763 snd_sof_find_dai(component, (char *)rtd->dai_link->name);
764 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
765 const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
767 /* use the tplg configured mclk if existed */
771 if (tplg_ops->dai_get_clk)
772 return tplg_ops->dai_get_clk(sdev, dai, clk_type);
778 * Helper to get SSP MCLK from a pcm_runtime.
779 * Return 0 if not exist.
781 int sof_dai_get_mclk(struct snd_soc_pcm_runtime *rtd)
783 return sof_dai_get_clk(rtd, SOF_DAI_CLK_INTEL_SSP_MCLK);
785 EXPORT_SYMBOL(sof_dai_get_mclk);
788 * Helper to get SSP BCLK from a pcm_runtime.
789 * Return 0 if not exist.
791 int sof_dai_get_bclk(struct snd_soc_pcm_runtime *rtd)
793 return sof_dai_get_clk(rtd, SOF_DAI_CLK_INTEL_SSP_BCLK);
795 EXPORT_SYMBOL(sof_dai_get_bclk);
797 static struct snd_sof_of_mach *sof_of_machine_select(struct snd_sof_dev *sdev)
799 struct snd_sof_pdata *sof_pdata = sdev->pdata;
800 const struct sof_dev_desc *desc = sof_pdata->desc;
801 struct snd_sof_of_mach *mach = desc->of_machines;
806 for (; mach->compatible; mach++) {
807 if (of_machine_is_compatible(mach->compatible)) {
808 sof_pdata->tplg_filename = mach->sof_tplg_filename;
809 if (mach->fw_filename)
810 sof_pdata->fw_filename = mach->fw_filename;
820 * SOF Driver enumeration.
822 int sof_machine_check(struct snd_sof_dev *sdev)
824 struct snd_sof_pdata *sof_pdata = sdev->pdata;
825 const struct sof_dev_desc *desc = sof_pdata->desc;
826 struct snd_soc_acpi_mach *mach;
828 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_FORCE_NOCODEC_MODE)) {
829 const struct snd_sof_of_mach *of_mach;
832 mach = snd_sof_machine_select(sdev);
834 sof_pdata->machine = mach;
836 if (sof_pdata->subsystem_id_set) {
837 mach->mach_params.subsystem_vendor = sof_pdata->subsystem_vendor;
838 mach->mach_params.subsystem_device = sof_pdata->subsystem_device;
839 mach->mach_params.subsystem_id_set = true;
842 snd_sof_set_mach_params(mach, sdev);
846 of_mach = sof_of_machine_select(sdev);
848 sof_pdata->of_machine = of_mach;
852 if (!IS_ENABLED(CONFIG_SND_SOC_SOF_NOCODEC)) {
853 dev_err(sdev->dev, "error: no matching ASoC machine driver found - aborting probe\n");
857 dev_warn(sdev->dev, "Force to use nocodec mode\n");
860 /* select nocodec mode */
861 dev_warn(sdev->dev, "Using nocodec machine driver\n");
862 mach = devm_kzalloc(sdev->dev, sizeof(*mach), GFP_KERNEL);
866 mach->drv_name = "sof-nocodec";
867 if (!sof_pdata->tplg_filename)
868 sof_pdata->tplg_filename = desc->nocodec_tplg_filename;
870 sof_pdata->machine = mach;
871 snd_sof_set_mach_params(mach, sdev);
875 EXPORT_SYMBOL(sof_machine_check);
877 int sof_machine_register(struct snd_sof_dev *sdev, void *pdata)
879 struct snd_sof_pdata *plat_data = pdata;
880 const char *drv_name;
884 drv_name = plat_data->machine->drv_name;
885 mach = plat_data->machine;
886 size = sizeof(*plat_data->machine);
888 /* register machine driver, pass machine info as pdata */
889 plat_data->pdev_mach =
890 platform_device_register_data(sdev->dev, drv_name,
891 PLATFORM_DEVID_NONE, mach, size);
892 if (IS_ERR(plat_data->pdev_mach))
893 return PTR_ERR(plat_data->pdev_mach);
895 dev_dbg(sdev->dev, "created machine %s\n",
896 dev_name(&plat_data->pdev_mach->dev));
900 EXPORT_SYMBOL(sof_machine_register);
902 void sof_machine_unregister(struct snd_sof_dev *sdev, void *pdata)
904 struct snd_sof_pdata *plat_data = pdata;
906 if (!IS_ERR_OR_NULL(plat_data->pdev_mach))
907 platform_device_unregister(plat_data->pdev_mach);
909 EXPORT_SYMBOL(sof_machine_unregister);