xref: /openbmc/linux/sound/soc/sof/pcm.c (revision 72661ff7)
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
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.
5 //
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
7 //
8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9 //
10 // PCM Layer, interface between ALSA and IPC.
11 //
12 
13 #include <linux/pm_runtime.h>
14 #include <sound/pcm_params.h>
15 #include <sound/sof.h>
16 #include "sof-priv.h"
17 #include "sof-audio.h"
18 #include "sof-utils.h"
19 #include "ops.h"
20 
21 /* Create DMA buffer page table for DSP */
22 static int create_page_table(struct snd_soc_component *component,
23 			     struct snd_pcm_substream *substream,
24 			     unsigned char *dma_area, size_t size)
25 {
26 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
27 	struct snd_sof_pcm *spcm;
28 	struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream);
29 	int stream = substream->stream;
30 
31 	spcm = snd_sof_find_spcm_dai(component, rtd);
32 	if (!spcm)
33 		return -EINVAL;
34 
35 	return snd_sof_create_page_table(component->dev, dmab,
36 		spcm->stream[stream].page_table.area, size);
37 }
38 
39 /*
40  * sof pcm period elapse work
41  */
42 static void snd_sof_pcm_period_elapsed_work(struct work_struct *work)
43 {
44 	struct snd_sof_pcm_stream *sps =
45 		container_of(work, struct snd_sof_pcm_stream,
46 			     period_elapsed_work);
47 
48 	snd_pcm_period_elapsed(sps->substream);
49 }
50 
51 void snd_sof_pcm_init_elapsed_work(struct work_struct *work)
52 {
53 	 INIT_WORK(work, snd_sof_pcm_period_elapsed_work);
54 }
55 
56 /*
57  * sof pcm period elapse, this could be called at irq thread context.
58  */
59 void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
60 {
61 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
62 	struct snd_soc_component *component =
63 		snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
64 	struct snd_sof_pcm *spcm;
65 
66 	spcm = snd_sof_find_spcm_dai(component, rtd);
67 	if (!spcm) {
68 		dev_err(component->dev,
69 			"error: period elapsed for unknown stream!\n");
70 		return;
71 	}
72 
73 	/*
74 	 * snd_pcm_period_elapsed() can be called in interrupt context
75 	 * before IRQ_HANDLED is returned. Inside snd_pcm_period_elapsed(),
76 	 * when the PCM is done draining or xrun happened, a STOP IPC will
77 	 * then be sent and this IPC will hit IPC timeout.
78 	 * To avoid sending IPC before the previous IPC is handled, we
79 	 * schedule delayed work here to call the snd_pcm_period_elapsed().
80 	 */
81 	schedule_work(&spcm->stream[substream->stream].period_elapsed_work);
82 }
83 EXPORT_SYMBOL(snd_sof_pcm_period_elapsed);
84 
85 int sof_pcm_setup_connected_widgets(struct snd_sof_dev *sdev, struct snd_soc_pcm_runtime *rtd,
86 				    struct snd_sof_pcm *spcm, int dir)
87 {
88 	struct snd_soc_dai *dai;
89 	int ret, j;
90 
91 	/* query DAPM for list of connected widgets and set them up */
92 	for_each_rtd_cpu_dais(rtd, j, dai) {
93 		struct snd_soc_dapm_widget_list *list;
94 
95 		ret = snd_soc_dapm_dai_get_connected_widgets(dai, dir, &list,
96 							     dpcm_end_walk_at_be);
97 		if (ret < 0) {
98 			dev_err(sdev->dev, "error: dai %s has no valid %s path\n", dai->name,
99 				dir == SNDRV_PCM_STREAM_PLAYBACK ? "playback" : "capture");
100 			return ret;
101 		}
102 
103 		spcm->stream[dir].list = list;
104 
105 		ret = sof_widget_list_setup(sdev, spcm, dir);
106 		if (ret < 0) {
107 			dev_err(sdev->dev, "error: failed widget list set up for pcm %d dir %d\n",
108 				spcm->pcm.pcm_id, dir);
109 			spcm->stream[dir].list = NULL;
110 			snd_soc_dapm_dai_free_widgets(&list);
111 			return ret;
112 		}
113 	}
114 
115 	return 0;
116 }
117 
118 static int sof_pcm_hw_params(struct snd_soc_component *component,
119 			     struct snd_pcm_substream *substream,
120 			     struct snd_pcm_hw_params *params)
121 {
122 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
123 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
124 	struct snd_sof_platform_stream_params platform_params = { 0 };
125 	const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
126 	struct snd_pcm_runtime *runtime = substream->runtime;
127 	struct snd_sof_pcm *spcm;
128 	int ret;
129 
130 	/* nothing to do for BE */
131 	if (rtd->dai_link->no_pcm)
132 		return 0;
133 
134 	spcm = snd_sof_find_spcm_dai(component, rtd);
135 	if (!spcm)
136 		return -EINVAL;
137 
138 	/*
139 	 * Handle repeated calls to hw_params() without free_pcm() in
140 	 * between. At least ALSA OSS emulation depends on this.
141 	 */
142 	if (pcm_ops->hw_free && spcm->prepared[substream->stream]) {
143 		ret = pcm_ops->hw_free(component, substream);
144 		if (ret < 0)
145 			return ret;
146 
147 		spcm->prepared[substream->stream] = false;
148 	}
149 
150 	dev_dbg(component->dev, "pcm: hw params stream %d dir %d\n",
151 		spcm->pcm.pcm_id, substream->stream);
152 
153 	/* if this is a repeated hw_params without hw_free, skip setting up widgets */
154 	if (!spcm->stream[substream->stream].list) {
155 		ret = sof_pcm_setup_connected_widgets(sdev, rtd, spcm, substream->stream);
156 		if (ret < 0)
157 			return ret;
158 	}
159 
160 	/* create compressed page table for audio firmware */
161 	if (runtime->buffer_changed) {
162 		ret = create_page_table(component, substream, runtime->dma_area,
163 					runtime->dma_bytes);
164 
165 		if (ret < 0)
166 			return ret;
167 	}
168 
169 	ret = snd_sof_pcm_platform_hw_params(sdev, substream, params, &platform_params);
170 	if (ret < 0) {
171 		dev_err(component->dev, "platform hw params failed\n");
172 		return ret;
173 	}
174 
175 	if (pcm_ops->hw_params) {
176 		ret = pcm_ops->hw_params(component, substream, params, &platform_params);
177 		if (ret < 0)
178 			return ret;
179 	}
180 
181 	spcm->prepared[substream->stream] = true;
182 
183 	/* save pcm hw_params */
184 	memcpy(&spcm->params[substream->stream], params, sizeof(*params));
185 
186 	return 0;
187 }
188 
189 static int sof_pcm_hw_free(struct snd_soc_component *component,
190 			   struct snd_pcm_substream *substream)
191 {
192 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
193 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
194 	const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
195 	struct snd_sof_pcm *spcm;
196 	int ret, err = 0;
197 
198 	/* nothing to do for BE */
199 	if (rtd->dai_link->no_pcm)
200 		return 0;
201 
202 	spcm = snd_sof_find_spcm_dai(component, rtd);
203 	if (!spcm)
204 		return -EINVAL;
205 
206 	dev_dbg(component->dev, "pcm: free stream %d dir %d\n",
207 		spcm->pcm.pcm_id, substream->stream);
208 
209 	/* free PCM in the DSP */
210 	if (pcm_ops->hw_free && spcm->prepared[substream->stream]) {
211 		ret = pcm_ops->hw_free(component, substream);
212 		if (ret < 0)
213 			err = ret;
214 
215 		spcm->prepared[substream->stream] = false;
216 	}
217 
218 	/* stop DMA */
219 	ret = snd_sof_pcm_platform_hw_free(sdev, substream);
220 	if (ret < 0) {
221 		dev_err(component->dev, "error: platform hw free failed\n");
222 		err = ret;
223 	}
224 
225 	/* free the DAPM widget list */
226 	ret = sof_widget_list_free(sdev, spcm, substream->stream);
227 	if (ret < 0)
228 		err = ret;
229 
230 	cancel_work_sync(&spcm->stream[substream->stream].period_elapsed_work);
231 
232 	return err;
233 }
234 
235 static int sof_pcm_prepare(struct snd_soc_component *component,
236 			   struct snd_pcm_substream *substream)
237 {
238 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
239 	struct snd_sof_pcm *spcm;
240 	int ret;
241 
242 	/* nothing to do for BE */
243 	if (rtd->dai_link->no_pcm)
244 		return 0;
245 
246 	spcm = snd_sof_find_spcm_dai(component, rtd);
247 	if (!spcm)
248 		return -EINVAL;
249 
250 	if (spcm->prepared[substream->stream])
251 		return 0;
252 
253 	dev_dbg(component->dev, "pcm: prepare stream %d dir %d\n",
254 		spcm->pcm.pcm_id, substream->stream);
255 
256 	/* set hw_params */
257 	ret = sof_pcm_hw_params(component,
258 				substream, &spcm->params[substream->stream]);
259 	if (ret < 0) {
260 		dev_err(component->dev,
261 			"error: set pcm hw_params after resume\n");
262 		return ret;
263 	}
264 
265 	return 0;
266 }
267 
268 /*
269  * FE dai link trigger actions are always executed in non-atomic context because
270  * they involve IPC's.
271  */
272 static int sof_pcm_trigger(struct snd_soc_component *component,
273 			   struct snd_pcm_substream *substream, int cmd)
274 {
275 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
276 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
277 	const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
278 	struct snd_sof_pcm *spcm;
279 	bool reset_hw_params = false;
280 	bool free_widget_list = false;
281 	bool ipc_first = false;
282 	int ret = 0;
283 
284 	/* nothing to do for BE */
285 	if (rtd->dai_link->no_pcm)
286 		return 0;
287 
288 	spcm = snd_sof_find_spcm_dai(component, rtd);
289 	if (!spcm)
290 		return -EINVAL;
291 
292 	dev_dbg(component->dev, "pcm: trigger stream %d dir %d cmd %d\n",
293 		spcm->pcm.pcm_id, substream->stream, cmd);
294 
295 	switch (cmd) {
296 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
297 		ipc_first = true;
298 		break;
299 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
300 		break;
301 	case SNDRV_PCM_TRIGGER_START:
302 		if (spcm->stream[substream->stream].suspend_ignored) {
303 			/*
304 			 * This case will be triggered when INFO_RESUME is
305 			 * not supported, no need to re-start streams that
306 			 * remained enabled in D0ix.
307 			 */
308 			spcm->stream[substream->stream].suspend_ignored = false;
309 			return 0;
310 		}
311 		break;
312 	case SNDRV_PCM_TRIGGER_SUSPEND:
313 		if (sdev->system_suspend_target == SOF_SUSPEND_S0IX &&
314 		    spcm->stream[substream->stream].d0i3_compatible) {
315 			/*
316 			 * trap the event, not sending trigger stop to
317 			 * prevent the FW pipelines from being stopped,
318 			 * and mark the flag to ignore the upcoming DAPM
319 			 * PM events.
320 			 */
321 			spcm->stream[substream->stream].suspend_ignored = true;
322 			return 0;
323 		}
324 		free_widget_list = true;
325 		fallthrough;
326 	case SNDRV_PCM_TRIGGER_STOP:
327 		ipc_first = true;
328 		reset_hw_params = true;
329 		break;
330 	default:
331 		dev_err(component->dev, "Unhandled trigger cmd %d\n", cmd);
332 		return -EINVAL;
333 	}
334 
335 	/*
336 	 * DMA and IPC sequence is different for start and stop. Need to send
337 	 * STOP IPC before stop DMA
338 	 */
339 	if (!ipc_first)
340 		snd_sof_pcm_platform_trigger(sdev, substream, cmd);
341 
342 	if (pcm_ops->trigger)
343 		ret = pcm_ops->trigger(component, substream, cmd);
344 
345 	/* need to STOP DMA even if trigger IPC failed */
346 	if (ipc_first)
347 		snd_sof_pcm_platform_trigger(sdev, substream, cmd);
348 
349 	/* free PCM if reset_hw_params is set and the STOP IPC is successful */
350 	if (!ret && reset_hw_params)
351 		ret = sof_pcm_stream_free(sdev, substream, spcm, substream->stream,
352 					  free_widget_list);
353 
354 	return ret;
355 }
356 
357 static snd_pcm_uframes_t sof_pcm_pointer(struct snd_soc_component *component,
358 					 struct snd_pcm_substream *substream)
359 {
360 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
361 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
362 	struct snd_sof_pcm *spcm;
363 	snd_pcm_uframes_t host, dai;
364 
365 	/* nothing to do for BE */
366 	if (rtd->dai_link->no_pcm)
367 		return 0;
368 
369 	/* use dsp ops pointer callback directly if set */
370 	if (sof_ops(sdev)->pcm_pointer)
371 		return sof_ops(sdev)->pcm_pointer(sdev, substream);
372 
373 	spcm = snd_sof_find_spcm_dai(component, rtd);
374 	if (!spcm)
375 		return -EINVAL;
376 
377 	/* read position from DSP */
378 	host = bytes_to_frames(substream->runtime,
379 			       spcm->stream[substream->stream].posn.host_posn);
380 	dai = bytes_to_frames(substream->runtime,
381 			      spcm->stream[substream->stream].posn.dai_posn);
382 
383 	dev_vdbg(component->dev,
384 		 "PCM: stream %d dir %d DMA position %lu DAI position %lu\n",
385 		 spcm->pcm.pcm_id, substream->stream, host, dai);
386 
387 	return host;
388 }
389 
390 static int sof_pcm_open(struct snd_soc_component *component,
391 			struct snd_pcm_substream *substream)
392 {
393 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
394 	struct snd_pcm_runtime *runtime = substream->runtime;
395 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
396 	const struct snd_sof_dsp_ops *ops = sof_ops(sdev);
397 	struct snd_sof_pcm *spcm;
398 	struct snd_soc_tplg_stream_caps *caps;
399 	int ret;
400 
401 	/* nothing to do for BE */
402 	if (rtd->dai_link->no_pcm)
403 		return 0;
404 
405 	spcm = snd_sof_find_spcm_dai(component, rtd);
406 	if (!spcm)
407 		return -EINVAL;
408 
409 	dev_dbg(component->dev, "pcm: open stream %d dir %d\n",
410 		spcm->pcm.pcm_id, substream->stream);
411 
412 
413 	caps = &spcm->pcm.caps[substream->stream];
414 
415 	/* set runtime config */
416 	runtime->hw.info = ops->hw_info; /* platform-specific */
417 
418 	/* set any runtime constraints based on topology */
419 	runtime->hw.formats = le64_to_cpu(caps->formats);
420 	runtime->hw.period_bytes_min = le32_to_cpu(caps->period_size_min);
421 	runtime->hw.period_bytes_max = le32_to_cpu(caps->period_size_max);
422 	runtime->hw.periods_min = le32_to_cpu(caps->periods_min);
423 	runtime->hw.periods_max = le32_to_cpu(caps->periods_max);
424 
425 	/*
426 	 * caps->buffer_size_min is not used since the
427 	 * snd_pcm_hardware structure only defines buffer_bytes_max
428 	 */
429 	runtime->hw.buffer_bytes_max = le32_to_cpu(caps->buffer_size_max);
430 
431 	dev_dbg(component->dev, "period min %zd max %zd bytes\n",
432 		runtime->hw.period_bytes_min,
433 		runtime->hw.period_bytes_max);
434 	dev_dbg(component->dev, "period count %d max %d\n",
435 		runtime->hw.periods_min,
436 		runtime->hw.periods_max);
437 	dev_dbg(component->dev, "buffer max %zd bytes\n",
438 		runtime->hw.buffer_bytes_max);
439 
440 	/* set wait time - TODO: come from topology */
441 	substream->wait_time = 500;
442 
443 	spcm->stream[substream->stream].posn.host_posn = 0;
444 	spcm->stream[substream->stream].posn.dai_posn = 0;
445 	spcm->stream[substream->stream].substream = substream;
446 	spcm->prepared[substream->stream] = false;
447 
448 	ret = snd_sof_pcm_platform_open(sdev, substream);
449 	if (ret < 0)
450 		dev_err(component->dev, "error: pcm open failed %d\n", ret);
451 
452 	return ret;
453 }
454 
455 static int sof_pcm_close(struct snd_soc_component *component,
456 			 struct snd_pcm_substream *substream)
457 {
458 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
459 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
460 	struct snd_sof_pcm *spcm;
461 	int err;
462 
463 	/* nothing to do for BE */
464 	if (rtd->dai_link->no_pcm)
465 		return 0;
466 
467 	spcm = snd_sof_find_spcm_dai(component, rtd);
468 	if (!spcm)
469 		return -EINVAL;
470 
471 	dev_dbg(component->dev, "pcm: close stream %d dir %d\n",
472 		spcm->pcm.pcm_id, substream->stream);
473 
474 	err = snd_sof_pcm_platform_close(sdev, substream);
475 	if (err < 0) {
476 		dev_err(component->dev, "error: pcm close failed %d\n",
477 			err);
478 		/*
479 		 * keep going, no point in preventing the close
480 		 * from happening
481 		 */
482 	}
483 
484 	return 0;
485 }
486 
487 /*
488  * Pre-allocate playback/capture audio buffer pages.
489  * no need to explicitly release memory preallocated by sof_pcm_new in pcm_free
490  * snd_pcm_lib_preallocate_free_for_all() is called by the core.
491  */
492 static int sof_pcm_new(struct snd_soc_component *component,
493 		       struct snd_soc_pcm_runtime *rtd)
494 {
495 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
496 	struct snd_sof_pcm *spcm;
497 	struct snd_pcm *pcm = rtd->pcm;
498 	struct snd_soc_tplg_stream_caps *caps;
499 	int stream = SNDRV_PCM_STREAM_PLAYBACK;
500 
501 	/* find SOF PCM for this RTD */
502 	spcm = snd_sof_find_spcm_dai(component, rtd);
503 	if (!spcm) {
504 		dev_warn(component->dev, "warn: can't find PCM with DAI ID %d\n",
505 			 rtd->dai_link->id);
506 		return 0;
507 	}
508 
509 	dev_dbg(component->dev, "creating new PCM %s\n", spcm->pcm.pcm_name);
510 
511 	/* do we need to pre-allocate playback audio buffer pages */
512 	if (!spcm->pcm.playback)
513 		goto capture;
514 
515 	caps = &spcm->pcm.caps[stream];
516 
517 	/* pre-allocate playback audio buffer pages */
518 	dev_dbg(component->dev,
519 		"spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n",
520 		caps->name, caps->buffer_size_min, caps->buffer_size_max);
521 
522 	if (!pcm->streams[stream].substream) {
523 		dev_err(component->dev, "error: NULL playback substream!\n");
524 		return -EINVAL;
525 	}
526 
527 	snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
528 				   SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
529 				   0, le32_to_cpu(caps->buffer_size_max));
530 capture:
531 	stream = SNDRV_PCM_STREAM_CAPTURE;
532 
533 	/* do we need to pre-allocate capture audio buffer pages */
534 	if (!spcm->pcm.capture)
535 		return 0;
536 
537 	caps = &spcm->pcm.caps[stream];
538 
539 	/* pre-allocate capture audio buffer pages */
540 	dev_dbg(component->dev,
541 		"spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",
542 		caps->name, caps->buffer_size_min, caps->buffer_size_max);
543 
544 	if (!pcm->streams[stream].substream) {
545 		dev_err(component->dev, "error: NULL capture substream!\n");
546 		return -EINVAL;
547 	}
548 
549 	snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
550 				   SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
551 				   0, le32_to_cpu(caps->buffer_size_max));
552 
553 	return 0;
554 }
555 
556 /* fixup the BE DAI link to match any values from topology */
557 int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params)
558 {
559 	struct snd_interval *rate = hw_param_interval(params,
560 			SNDRV_PCM_HW_PARAM_RATE);
561 	struct snd_interval *channels = hw_param_interval(params,
562 						SNDRV_PCM_HW_PARAM_CHANNELS);
563 	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
564 	struct snd_soc_component *component =
565 		snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
566 	struct snd_sof_dai *dai =
567 		snd_sof_find_dai(component, (char *)rtd->dai_link->name);
568 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
569 	const struct sof_ipc_pcm_ops *pcm_ops = sdev->ipc->ops->pcm;
570 
571 	/* no topology exists for this BE, try a common configuration */
572 	if (!dai) {
573 		dev_warn(component->dev,
574 			 "warning: no topology found for BE DAI %s config\n",
575 			 rtd->dai_link->name);
576 
577 		/*  set 48k, stereo, 16bits by default */
578 		rate->min = 48000;
579 		rate->max = 48000;
580 
581 		channels->min = 2;
582 		channels->max = 2;
583 
584 		snd_mask_none(fmt);
585 		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
586 
587 		return 0;
588 	}
589 
590 	if (pcm_ops->dai_link_fixup)
591 		return pcm_ops->dai_link_fixup(rtd, params);
592 
593 	return 0;
594 }
595 EXPORT_SYMBOL(sof_pcm_dai_link_fixup);
596 
597 static int sof_pcm_probe(struct snd_soc_component *component)
598 {
599 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
600 	struct snd_sof_pdata *plat_data = sdev->pdata;
601 	const char *tplg_filename;
602 	int ret;
603 
604 	/* load the default topology */
605 	sdev->component = component;
606 
607 	tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
608 				       "%s/%s",
609 				       plat_data->tplg_filename_prefix,
610 				       plat_data->tplg_filename);
611 	if (!tplg_filename)
612 		return -ENOMEM;
613 
614 	ret = snd_sof_load_topology(component, tplg_filename);
615 	if (ret < 0) {
616 		dev_err(component->dev, "error: failed to load DSP topology %d\n",
617 			ret);
618 		return ret;
619 	}
620 
621 	return ret;
622 }
623 
624 static void sof_pcm_remove(struct snd_soc_component *component)
625 {
626 	/* remove topology */
627 	snd_soc_tplg_component_remove(component);
628 }
629 
630 static int sof_pcm_ack(struct snd_soc_component *component,
631 		       struct snd_pcm_substream *substream)
632 {
633 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
634 
635 	return snd_sof_pcm_platform_ack(sdev, substream);
636 }
637 
638 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev)
639 {
640 	struct snd_soc_component_driver *pd = &sdev->plat_drv;
641 	struct snd_sof_pdata *plat_data = sdev->pdata;
642 	const char *drv_name;
643 
644 	drv_name = plat_data->machine->drv_name;
645 
646 	pd->name = "sof-audio-component";
647 	pd->probe = sof_pcm_probe;
648 	pd->remove = sof_pcm_remove;
649 	pd->open = sof_pcm_open;
650 	pd->close = sof_pcm_close;
651 	pd->hw_params = sof_pcm_hw_params;
652 	pd->prepare = sof_pcm_prepare;
653 	pd->hw_free = sof_pcm_hw_free;
654 	pd->trigger = sof_pcm_trigger;
655 	pd->pointer = sof_pcm_pointer;
656 	pd->ack = sof_pcm_ack;
657 
658 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
659 	pd->compress_ops = &sof_compressed_ops;
660 #endif
661 
662 	pd->pcm_construct = sof_pcm_new;
663 	pd->ignore_machine = drv_name;
664 	pd->be_hw_params_fixup = sof_pcm_dai_link_fixup;
665 	pd->be_pcm_base = SOF_BE_PCM_BASE;
666 	pd->use_dai_pcm_id = true;
667 	pd->topology_name_prefix = "sof";
668 
669 	 /* increment module refcount when a pcm is opened */
670 	pd->module_get_upon_open = 1;
671 }
672