1 // SPDX-License-Identifier: (GPL-2.0 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) 2018 Intel Corporation. All rights reserved.
8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
10 // PCM Layer, interface between ALSA and IPC.
13 #include <linux/pm_runtime.h>
14 #include <sound/pcm_params.h>
15 #include <sound/sof.h>
19 #define DRV_NAME "sof-audio-component"
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)
26 struct snd_soc_pcm_runtime *rtd = substream->private_data;
27 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
28 struct snd_sof_pcm *spcm;
29 struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream);
30 int stream = substream->stream;
32 spcm = snd_sof_find_spcm_dai(sdev, rtd);
36 return snd_sof_create_page_table(sdev, dmab,
37 spcm->stream[stream].page_table.area, size);
40 static int sof_pcm_dsp_params(struct snd_sof_pcm *spcm, struct snd_pcm_substream *substream,
41 const struct sof_ipc_pcm_params_reply *reply)
43 struct snd_sof_dev *sdev = spcm->sdev;
45 int ret = snd_sof_ipc_pcm_params(sdev, substream, reply);
48 dev_err(sdev->dev, "error: got wrong reply for PCM %d\n",
55 * sof pcm period elapse work
57 static void sof_pcm_period_elapsed_work(struct work_struct *work)
59 struct snd_sof_pcm_stream *sps =
60 container_of(work, struct snd_sof_pcm_stream,
63 snd_pcm_period_elapsed(sps->substream);
67 * sof pcm period elapse, this could be called at irq thread context.
69 void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
71 struct snd_soc_pcm_runtime *rtd = substream->private_data;
72 struct snd_soc_component *component =
73 snd_soc_rtdcom_lookup(rtd, DRV_NAME);
74 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
75 struct snd_sof_pcm *spcm;
77 spcm = snd_sof_find_spcm_dai(sdev, rtd);
80 "error: period elapsed for unknown stream!\n");
85 * snd_pcm_period_elapsed() can be called in interrupt context
86 * before IRQ_HANDLED is returned. Inside snd_pcm_period_elapsed(),
87 * when the PCM is done draining or xrun happened, a STOP IPC will
88 * then be sent and this IPC will hit IPC timeout.
89 * To avoid sending IPC before the previous IPC is handled, we
90 * schedule delayed work here to call the snd_pcm_period_elapsed().
92 schedule_work(&spcm->stream[substream->stream].period_elapsed_work);
94 EXPORT_SYMBOL(snd_sof_pcm_period_elapsed);
96 /* this may get called several times by oss emulation */
97 static int sof_pcm_hw_params(struct snd_soc_component *component,
98 struct snd_pcm_substream *substream,
99 struct snd_pcm_hw_params *params)
101 struct snd_soc_pcm_runtime *rtd = substream->private_data;
102 struct snd_pcm_runtime *runtime = substream->runtime;
103 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
104 struct snd_sof_pcm *spcm;
105 struct sof_ipc_pcm_params pcm;
106 struct sof_ipc_pcm_params_reply ipc_params_reply;
109 /* nothing to do for BE */
110 if (rtd->dai_link->no_pcm)
113 spcm = snd_sof_find_spcm_dai(sdev, rtd);
117 dev_dbg(sdev->dev, "pcm: hw params stream %d dir %d\n",
118 spcm->pcm.pcm_id, substream->stream);
120 memset(&pcm, 0, sizeof(pcm));
122 /* allocate audio buffer pages */
123 ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
125 dev_err(sdev->dev, "error: could not allocate %d bytes for PCM %d\n",
126 params_buffer_bytes(params), spcm->pcm.pcm_id);
131 * ret == 1 means the buffer is changed
132 * create compressed page table for audio firmware
133 * ret == 0 means the buffer is not changed
134 * so no need to regenerate the page table
136 ret = create_page_table(component, substream, runtime->dma_area,
142 /* number of pages should be rounded up */
143 pcm.params.buffer.pages = PFN_UP(runtime->dma_bytes);
145 /* set IPC PCM parameters */
146 pcm.hdr.size = sizeof(pcm);
147 pcm.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS;
148 pcm.comp_id = spcm->stream[substream->stream].comp_id;
149 pcm.params.hdr.size = sizeof(pcm.params);
150 pcm.params.buffer.phy_addr =
151 spcm->stream[substream->stream].page_table.addr;
152 pcm.params.buffer.size = runtime->dma_bytes;
153 pcm.params.direction = substream->stream;
154 pcm.params.sample_valid_bytes = params_width(params) >> 3;
155 pcm.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
156 pcm.params.rate = params_rate(params);
157 pcm.params.channels = params_channels(params);
158 pcm.params.host_period_bytes = params_period_bytes(params);
161 ret = snd_pcm_format_physical_width(params_format(params));
164 pcm.params.sample_container_bytes = ret >> 3;
167 switch (params_format(params)) {
168 case SNDRV_PCM_FORMAT_S16:
169 pcm.params.frame_fmt = SOF_IPC_FRAME_S16_LE;
171 case SNDRV_PCM_FORMAT_S24:
172 pcm.params.frame_fmt = SOF_IPC_FRAME_S24_4LE;
174 case SNDRV_PCM_FORMAT_S32:
175 pcm.params.frame_fmt = SOF_IPC_FRAME_S32_LE;
177 case SNDRV_PCM_FORMAT_FLOAT:
178 pcm.params.frame_fmt = SOF_IPC_FRAME_FLOAT;
184 /* firmware already configured host stream */
185 ret = snd_sof_pcm_platform_hw_params(sdev,
190 dev_err(sdev->dev, "error: platform hw params failed\n");
194 dev_dbg(sdev->dev, "stream_tag %d", pcm.params.stream_tag);
196 /* send IPC to the DSP */
197 ret = sof_ipc_tx_message(sdev->ipc, pcm.hdr.cmd, &pcm, sizeof(pcm),
198 &ipc_params_reply, sizeof(ipc_params_reply));
200 dev_err(sdev->dev, "error: hw params ipc failed for stream %d\n",
201 pcm.params.stream_tag);
205 ret = sof_pcm_dsp_params(spcm, substream, &ipc_params_reply);
209 spcm->prepared[substream->stream] = true;
211 /* save pcm hw_params */
212 memcpy(&spcm->params[substream->stream], params, sizeof(*params));
217 static int sof_pcm_dsp_pcm_free(struct snd_pcm_substream *substream,
218 struct snd_sof_dev *sdev,
219 struct snd_sof_pcm *spcm)
221 struct sof_ipc_stream stream;
222 struct sof_ipc_reply reply;
225 stream.hdr.size = sizeof(stream);
226 stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_FREE;
227 stream.comp_id = spcm->stream[substream->stream].comp_id;
229 /* send IPC to the DSP */
230 ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
231 sizeof(stream), &reply, sizeof(reply));
233 spcm->prepared[substream->stream] = false;
238 static int sof_pcm_hw_free(struct snd_soc_component *component,
239 struct snd_pcm_substream *substream)
241 struct snd_soc_pcm_runtime *rtd = substream->private_data;
242 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
243 struct snd_sof_pcm *spcm;
246 /* nothing to do for BE */
247 if (rtd->dai_link->no_pcm)
250 spcm = snd_sof_find_spcm_dai(sdev, rtd);
254 dev_dbg(sdev->dev, "pcm: free stream %d dir %d\n", spcm->pcm.pcm_id,
257 if (spcm->prepared[substream->stream]) {
258 ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm);
263 snd_pcm_lib_free_pages(substream);
265 cancel_work_sync(&spcm->stream[substream->stream].period_elapsed_work);
267 ret = snd_sof_pcm_platform_hw_free(sdev, substream);
269 dev_err(sdev->dev, "error: platform hw free failed\n");
276 static int sof_pcm_prepare(struct snd_soc_component *component,
277 struct snd_pcm_substream *substream)
279 struct snd_soc_pcm_runtime *rtd = substream->private_data;
280 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
281 struct snd_sof_pcm *spcm;
284 /* nothing to do for BE */
285 if (rtd->dai_link->no_pcm)
288 spcm = snd_sof_find_spcm_dai(sdev, rtd);
292 if (spcm->prepared[substream->stream])
295 dev_dbg(sdev->dev, "pcm: prepare stream %d dir %d\n", spcm->pcm.pcm_id,
299 ret = sof_pcm_hw_params(component,
300 substream, &spcm->params[substream->stream]);
302 dev_err(sdev->dev, "error: set pcm hw_params after resume\n");
310 * FE dai link trigger actions are always executed in non-atomic context because
311 * they involve IPC's.
313 static int sof_pcm_trigger(struct snd_soc_component *component,
314 struct snd_pcm_substream *substream, int cmd)
316 struct snd_soc_pcm_runtime *rtd = substream->private_data;
317 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
318 struct snd_sof_pcm *spcm;
319 struct sof_ipc_stream stream;
320 struct sof_ipc_reply reply;
321 bool reset_hw_params = false;
322 bool ipc_first = false;
325 /* nothing to do for BE */
326 if (rtd->dai_link->no_pcm)
329 spcm = snd_sof_find_spcm_dai(sdev, rtd);
333 dev_dbg(sdev->dev, "pcm: trigger stream %d dir %d cmd %d\n",
334 spcm->pcm.pcm_id, substream->stream, cmd);
336 stream.hdr.size = sizeof(stream);
337 stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG;
338 stream.comp_id = spcm->stream[substream->stream].comp_id;
341 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
342 stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_PAUSE;
345 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
346 stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_RELEASE;
348 case SNDRV_PCM_TRIGGER_RESUME:
349 if (spcm->stream[substream->stream].suspend_ignored) {
351 * this case will be triggered when INFO_RESUME is
352 * supported, no need to resume streams that remained
355 spcm->stream[substream->stream].suspend_ignored = false;
359 /* set up hw_params */
360 ret = sof_pcm_prepare(component, substream);
363 "error: failed to set up hw_params upon resume\n");
368 case SNDRV_PCM_TRIGGER_START:
369 if (spcm->stream[substream->stream].suspend_ignored) {
371 * This case will be triggered when INFO_RESUME is
372 * not supported, no need to re-start streams that
373 * remained enabled in D0ix.
375 spcm->stream[substream->stream].suspend_ignored = false;
378 stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_START;
380 case SNDRV_PCM_TRIGGER_SUSPEND:
381 if (sdev->s0_suspend &&
382 spcm->stream[substream->stream].d0i3_compatible) {
384 * trap the event, not sending trigger stop to
385 * prevent the FW pipelines from being stopped,
386 * and mark the flag to ignore the upcoming DAPM
389 spcm->stream[substream->stream].suspend_ignored = true;
393 case SNDRV_PCM_TRIGGER_STOP:
394 stream.hdr.cmd |= SOF_IPC_STREAM_TRIG_STOP;
396 reset_hw_params = true;
399 dev_err(sdev->dev, "error: unhandled trigger cmd %d\n", cmd);
404 * DMA and IPC sequence is different for start and stop. Need to send
405 * STOP IPC before stop DMA
408 snd_sof_pcm_platform_trigger(sdev, substream, cmd);
410 /* send IPC to the DSP */
411 ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream,
412 sizeof(stream), &reply, sizeof(reply));
414 /* need to STOP DMA even if STOP IPC failed */
416 snd_sof_pcm_platform_trigger(sdev, substream, cmd);
418 /* free PCM if reset_hw_params is set and the STOP IPC is successful */
419 if (!ret && reset_hw_params)
420 ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm);
425 static snd_pcm_uframes_t sof_pcm_pointer(struct snd_soc_component *component,
426 struct snd_pcm_substream *substream)
428 struct snd_soc_pcm_runtime *rtd = substream->private_data;
429 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
430 struct snd_sof_pcm *spcm;
431 snd_pcm_uframes_t host, dai;
433 /* nothing to do for BE */
434 if (rtd->dai_link->no_pcm)
437 /* use dsp ops pointer callback directly if set */
438 if (sof_ops(sdev)->pcm_pointer)
439 return sof_ops(sdev)->pcm_pointer(sdev, substream);
441 spcm = snd_sof_find_spcm_dai(sdev, rtd);
445 /* read position from DSP */
446 host = bytes_to_frames(substream->runtime,
447 spcm->stream[substream->stream].posn.host_posn);
448 dai = bytes_to_frames(substream->runtime,
449 spcm->stream[substream->stream].posn.dai_posn);
451 dev_dbg(sdev->dev, "PCM: stream %d dir %d DMA position %lu DAI position %lu\n",
452 spcm->pcm.pcm_id, substream->stream, host, dai);
457 #ifdef CONFIG_SND_DMA_SGBUF
458 static struct page *sof_pcm_page(struct snd_soc_component *component,
459 struct snd_pcm_substream *substream,
460 unsigned long offset)
462 return snd_pcm_sgbuf_ops_page(substream, offset);
465 #define sof_pcm_page NULL
466 #endif /* CONFIG_SND_DMA_SGBUF */
468 static int sof_pcm_open(struct snd_soc_component *component,
469 struct snd_pcm_substream *substream)
471 struct snd_soc_pcm_runtime *rtd = substream->private_data;
472 struct snd_pcm_runtime *runtime = substream->runtime;
473 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
474 const struct snd_sof_dsp_ops *ops = sof_ops(sdev);
475 struct snd_sof_pcm *spcm;
476 struct snd_soc_tplg_stream_caps *caps;
479 /* nothing to do for BE */
480 if (rtd->dai_link->no_pcm)
483 spcm = snd_sof_find_spcm_dai(sdev, rtd);
487 dev_dbg(sdev->dev, "pcm: open stream %d dir %d\n", spcm->pcm.pcm_id,
490 INIT_WORK(&spcm->stream[substream->stream].period_elapsed_work,
491 sof_pcm_period_elapsed_work);
493 caps = &spcm->pcm.caps[substream->stream];
495 /* set any runtime constraints based on topology */
496 snd_pcm_hw_constraint_step(substream->runtime, 0,
497 SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
498 le32_to_cpu(caps->period_size_min));
499 snd_pcm_hw_constraint_step(substream->runtime, 0,
500 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
501 le32_to_cpu(caps->period_size_min));
503 /* set runtime config */
504 runtime->hw.info = ops->hw_info; /* platform-specific */
506 runtime->hw.formats = le64_to_cpu(caps->formats);
507 runtime->hw.period_bytes_min = le32_to_cpu(caps->period_size_min);
508 runtime->hw.period_bytes_max = le32_to_cpu(caps->period_size_max);
509 runtime->hw.periods_min = le32_to_cpu(caps->periods_min);
510 runtime->hw.periods_max = le32_to_cpu(caps->periods_max);
513 * caps->buffer_size_min is not used since the
514 * snd_pcm_hardware structure only defines buffer_bytes_max
516 runtime->hw.buffer_bytes_max = le32_to_cpu(caps->buffer_size_max);
518 dev_dbg(sdev->dev, "period min %zd max %zd bytes\n",
519 runtime->hw.period_bytes_min,
520 runtime->hw.period_bytes_max);
521 dev_dbg(sdev->dev, "period count %d max %d\n",
522 runtime->hw.periods_min,
523 runtime->hw.periods_max);
524 dev_dbg(sdev->dev, "buffer max %zd bytes\n",
525 runtime->hw.buffer_bytes_max);
527 /* set wait time - TODO: come from topology */
528 substream->wait_time = 500;
530 spcm->stream[substream->stream].posn.host_posn = 0;
531 spcm->stream[substream->stream].posn.dai_posn = 0;
532 spcm->stream[substream->stream].substream = substream;
533 spcm->prepared[substream->stream] = false;
535 ret = snd_sof_pcm_platform_open(sdev, substream);
537 dev_err(sdev->dev, "error: pcm open failed %d\n", ret);
542 static int sof_pcm_close(struct snd_soc_component *component,
543 struct snd_pcm_substream *substream)
545 struct snd_soc_pcm_runtime *rtd = substream->private_data;
546 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
547 struct snd_sof_pcm *spcm;
550 /* nothing to do for BE */
551 if (rtd->dai_link->no_pcm)
554 spcm = snd_sof_find_spcm_dai(sdev, rtd);
558 dev_dbg(sdev->dev, "pcm: close stream %d dir %d\n", spcm->pcm.pcm_id,
561 err = snd_sof_pcm_platform_close(sdev, substream);
563 dev_err(sdev->dev, "error: pcm close failed %d\n",
566 * keep going, no point in preventing the close
575 * Pre-allocate playback/capture audio buffer pages.
576 * no need to explicitly release memory preallocated by sof_pcm_new in pcm_free
577 * snd_pcm_lib_preallocate_free_for_all() is called by the core.
579 static int sof_pcm_new(struct snd_soc_component *component,
580 struct snd_soc_pcm_runtime *rtd)
582 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
583 struct snd_sof_pcm *spcm;
584 struct snd_pcm *pcm = rtd->pcm;
585 struct snd_soc_tplg_stream_caps *caps;
586 int stream = SNDRV_PCM_STREAM_PLAYBACK;
588 /* find SOF PCM for this RTD */
589 spcm = snd_sof_find_spcm_dai(sdev, rtd);
591 dev_warn(sdev->dev, "warn: can't find PCM with DAI ID %d\n",
596 dev_dbg(sdev->dev, "creating new PCM %s\n", spcm->pcm.pcm_name);
598 /* do we need to pre-allocate playback audio buffer pages */
599 if (!spcm->pcm.playback)
602 caps = &spcm->pcm.caps[stream];
604 /* pre-allocate playback audio buffer pages */
605 dev_dbg(sdev->dev, "spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n",
606 caps->name, caps->buffer_size_min, caps->buffer_size_max);
608 snd_pcm_lib_preallocate_pages(pcm->streams[stream].substream,
609 SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
610 le32_to_cpu(caps->buffer_size_min),
611 le32_to_cpu(caps->buffer_size_max));
613 stream = SNDRV_PCM_STREAM_CAPTURE;
615 /* do we need to pre-allocate capture audio buffer pages */
616 if (!spcm->pcm.capture)
619 caps = &spcm->pcm.caps[stream];
621 /* pre-allocate capture audio buffer pages */
622 dev_dbg(sdev->dev, "spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",
623 caps->name, caps->buffer_size_min, caps->buffer_size_max);
625 snd_pcm_lib_preallocate_pages(pcm->streams[stream].substream,
626 SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
627 le32_to_cpu(caps->buffer_size_min),
628 le32_to_cpu(caps->buffer_size_max));
633 /* fixup the BE DAI link to match any values from topology */
634 static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
635 struct snd_pcm_hw_params *params)
637 struct snd_interval *rate = hw_param_interval(params,
638 SNDRV_PCM_HW_PARAM_RATE);
639 struct snd_interval *channels = hw_param_interval(params,
640 SNDRV_PCM_HW_PARAM_CHANNELS);
641 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
642 struct snd_soc_component *component =
643 snd_soc_rtdcom_lookup(rtd, DRV_NAME);
644 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
645 struct snd_sof_dai *dai =
646 snd_sof_find_dai(sdev, (char *)rtd->dai_link->name);
648 /* no topology exists for this BE, try a common configuration */
650 dev_warn(sdev->dev, "warning: no topology found for BE DAI %s config\n",
651 rtd->dai_link->name);
653 /* set 48k, stereo, 16bits by default */
661 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
666 /* read format from topology */
669 switch (dai->comp_dai.config.frame_fmt) {
670 case SOF_IPC_FRAME_S16_LE:
671 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
673 case SOF_IPC_FRAME_S24_4LE:
674 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
676 case SOF_IPC_FRAME_S32_LE:
677 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
680 dev_err(sdev->dev, "error: No available DAI format!\n");
684 /* read rate and channels from topology */
685 switch (dai->dai_config->type) {
686 case SOF_DAI_INTEL_SSP:
687 rate->min = dai->dai_config->ssp.fsync_rate;
688 rate->max = dai->dai_config->ssp.fsync_rate;
689 channels->min = dai->dai_config->ssp.tdm_slots;
690 channels->max = dai->dai_config->ssp.tdm_slots;
693 "rate_min: %d rate_max: %d\n", rate->min, rate->max);
695 "channels_min: %d channels_max: %d\n",
696 channels->min, channels->max);
699 case SOF_DAI_INTEL_DMIC:
700 /* DMIC only supports 16 or 32 bit formats */
701 if (dai->comp_dai.config.frame_fmt == SOF_IPC_FRAME_S24_4LE) {
703 "error: invalid fmt %d for DAI type %d\n",
704 dai->comp_dai.config.frame_fmt,
705 dai->dai_config->type);
708 case SOF_DAI_INTEL_HDA:
709 /* do nothing for HDA dai_link */
711 case SOF_DAI_INTEL_ALH:
712 /* do nothing for ALH dai_link */
714 case SOF_DAI_IMX_ESAI:
715 channels->min = dai->dai_config->esai.tdm_slots;
716 channels->max = dai->dai_config->esai.tdm_slots;
719 "channels_min: %d channels_max: %d\n",
720 channels->min, channels->max);
723 dev_err(sdev->dev, "error: invalid DAI type %d\n",
724 dai->dai_config->type);
731 static int sof_pcm_probe(struct snd_soc_component *component)
733 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
734 struct snd_sof_pdata *plat_data = sdev->pdata;
735 const char *tplg_filename;
738 /* load the default topology */
739 sdev->component = component;
741 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
743 plat_data->tplg_filename_prefix,
744 plat_data->tplg_filename);
748 ret = snd_sof_load_topology(sdev, tplg_filename);
750 dev_err(sdev->dev, "error: failed to load DSP topology %d\n",
756 * Some platforms in SOF, ex: BYT, may not have their platform PM
757 * callbacks set. Increment the usage count so as to
758 * prevent the device from entering runtime suspend.
760 if (!sof_ops(sdev)->runtime_suspend || !sof_ops(sdev)->runtime_resume)
761 pm_runtime_get_noresume(sdev->dev);
766 static void sof_pcm_remove(struct snd_soc_component *component)
768 /* remove topology */
769 snd_soc_tplg_component_remove(component, SND_SOC_TPLG_INDEX_ALL);
772 void snd_sof_new_platform_drv(struct snd_sof_dev *sdev)
774 struct snd_soc_component_driver *pd = &sdev->plat_drv;
775 struct snd_sof_pdata *plat_data = sdev->pdata;
776 const char *drv_name;
778 drv_name = plat_data->machine->drv_name;
780 pd->name = "sof-audio-component";
781 pd->probe = sof_pcm_probe;
782 pd->remove = sof_pcm_remove;
783 pd->open = sof_pcm_open;
784 pd->close = sof_pcm_close;
785 pd->ioctl = snd_soc_pcm_lib_ioctl;
786 pd->hw_params = sof_pcm_hw_params;
787 pd->prepare = sof_pcm_prepare;
788 pd->hw_free = sof_pcm_hw_free;
789 pd->trigger = sof_pcm_trigger;
790 pd->pointer = sof_pcm_pointer;
791 pd->page = sof_pcm_page;
793 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
794 pd->compr_ops = &sof_compressed_ops;
796 pd->pcm_construct = sof_pcm_new;
797 pd->ignore_machine = drv_name;
798 pd->be_hw_params_fixup = sof_pcm_dai_link_fixup;
799 pd->be_pcm_base = SOF_BE_PCM_BASE;
800 pd->use_dai_pcm_id = true;
801 pd->topology_name_prefix = "sof";
803 /* increment module refcount when a pcm is opened */
804 pd->module_get_upon_open = 1;