2020-05-01 09:58:50 -05:00
|
|
|
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
|
2019-04-12 11:05:10 -05:00
|
|
|
//
|
|
|
|
// This file is provided under a dual BSD/GPLv2 license. When using or
|
|
|
|
// redistributing this file, you may do so under either license.
|
|
|
|
//
|
2024-05-03 09:03:51 -05:00
|
|
|
// Copyright(c) 2018 Intel Corporation
|
2019-04-12 11:05:10 -05:00
|
|
|
//
|
|
|
|
// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
|
|
|
|
//
|
|
|
|
// PCM Layer, interface between ALSA and IPC.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/sof.h>
|
2022-09-19 14:21:07 +02:00
|
|
|
#include <trace/events/sof.h>
|
2022-08-05 15:04:48 +08:00
|
|
|
#include "sof-of-dev.h"
|
2019-04-12 11:05:10 -05:00
|
|
|
#include "sof-priv.h"
|
2019-12-04 15:15:51 -06:00
|
|
|
#include "sof-audio.h"
|
2022-02-10 17:05:20 +02:00
|
|
|
#include "sof-utils.h"
|
2022-02-10 17:05:25 +02:00
|
|
|
#include "ops.h"
|
2019-04-12 11:05:10 -05:00
|
|
|
|
2019-04-30 18:09:25 -05:00
|
|
|
/*
|
|
|
|
* sof pcm period elapse work
|
|
|
|
*/
|
2021-10-04 18:21:47 +03:00
|
|
|
static void snd_sof_pcm_period_elapsed_work(struct work_struct *work)
|
2019-04-30 18:09:25 -05:00
|
|
|
{
|
|
|
|
struct snd_sof_pcm_stream *sps =
|
|
|
|
container_of(work, struct snd_sof_pcm_stream,
|
|
|
|
period_elapsed_work);
|
|
|
|
|
|
|
|
snd_pcm_period_elapsed(sps->substream);
|
|
|
|
}
|
|
|
|
|
2021-10-04 18:21:47 +03:00
|
|
|
void snd_sof_pcm_init_elapsed_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
INIT_WORK(work, snd_sof_pcm_period_elapsed_work);
|
|
|
|
}
|
|
|
|
|
2019-04-30 18:09:25 -05:00
|
|
|
/*
|
|
|
|
* sof pcm period elapse, this could be called at irq thread context.
|
|
|
|
*/
|
|
|
|
void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
|
|
|
|
{
|
2023-09-26 06:25:22 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
2019-04-30 18:09:25 -05:00
|
|
|
struct snd_soc_component *component =
|
2019-12-04 15:15:51 -06:00
|
|
|
snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
|
2019-04-30 18:09:25 -05:00
|
|
|
struct snd_sof_pcm *spcm;
|
|
|
|
|
2019-12-04 15:15:51 -06:00
|
|
|
spcm = snd_sof_find_spcm_dai(component, rtd);
|
2019-04-30 18:09:25 -05:00
|
|
|
if (!spcm) {
|
2019-12-04 15:15:51 -06:00
|
|
|
dev_err(component->dev,
|
2019-04-30 18:09:25 -05:00
|
|
|
"error: period elapsed for unknown stream!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* snd_pcm_period_elapsed() can be called in interrupt context
|
|
|
|
* before IRQ_HANDLED is returned. Inside snd_pcm_period_elapsed(),
|
|
|
|
* when the PCM is done draining or xrun happened, a STOP IPC will
|
|
|
|
* then be sent and this IPC will hit IPC timeout.
|
|
|
|
* To avoid sending IPC before the previous IPC is handled, we
|
|
|
|
* schedule delayed work here to call the snd_pcm_period_elapsed().
|
|
|
|
*/
|
|
|
|
schedule_work(&spcm->stream[substream->stream].period_elapsed_work);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(snd_sof_pcm_period_elapsed);
|
|
|
|
|
2022-04-26 10:17:40 -07:00
|
|
|
static int
|
|
|
|
sof_pcm_setup_connected_widgets(struct snd_sof_dev *sdev, struct snd_soc_pcm_runtime *rtd,
|
2022-04-26 10:17:43 -07:00
|
|
|
struct snd_sof_pcm *spcm, struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_sof_platform_stream_params *platform_params, int dir)
|
2021-09-27 15:05:16 +03:00
|
|
|
{
|
|
|
|
struct snd_soc_dai *dai;
|
|
|
|
int ret, j;
|
|
|
|
|
|
|
|
/* query DAPM for list of connected widgets and set them up */
|
|
|
|
for_each_rtd_cpu_dais(rtd, j, dai) {
|
|
|
|
struct snd_soc_dapm_widget_list *list;
|
|
|
|
|
|
|
|
ret = snd_soc_dapm_dai_get_connected_widgets(dai, dir, &list,
|
|
|
|
dpcm_end_walk_at_be);
|
|
|
|
if (ret < 0) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, dir, "dai %s has no valid %s path\n",
|
|
|
|
dai->name, snd_pcm_direction_name(dir));
|
2021-09-27 15:05:16 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
spcm->stream[dir].list = list;
|
|
|
|
|
2022-04-26 10:17:43 -07:00
|
|
|
ret = sof_widget_list_setup(sdev, spcm, params, platform_params, dir);
|
2021-09-27 15:05:16 +03:00
|
|
|
if (ret < 0) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, dir, "Widget list set up failed\n");
|
2021-09-27 15:05:16 +03:00
|
|
|
spcm->stream[dir].list = NULL;
|
|
|
|
snd_soc_dapm_dai_free_widgets(&list);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-02 14:32:56 +09:00
|
|
|
static int sof_pcm_hw_params(struct snd_soc_component *component,
|
|
|
|
struct snd_pcm_substream *substream,
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_pcm_hw_params *params)
|
|
|
|
{
|
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
2023-09-26 06:25:22 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
2022-12-21 12:23:21 +02:00
|
|
|
const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
|
2022-03-09 20:27:12 -08:00
|
|
|
struct snd_sof_platform_stream_params platform_params = { 0 };
|
2022-03-17 10:50:39 -07:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_pcm *spcm;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* nothing to do for BE */
|
|
|
|
if (rtd->dai_link->no_pcm)
|
|
|
|
return 0;
|
|
|
|
|
2019-12-04 15:15:51 -06:00
|
|
|
spcm = snd_sof_find_spcm_dai(component, rtd);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (!spcm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_dbg(spcm, substream->stream, "Entry: hw_params\n");
|
|
|
|
|
2020-01-10 17:57:49 -06:00
|
|
|
/*
|
|
|
|
* Handle repeated calls to hw_params() without free_pcm() in
|
|
|
|
* between. At least ALSA OSS emulation depends on this.
|
|
|
|
*/
|
2025-06-19 13:45:51 +03:00
|
|
|
if (spcm->prepared[substream->stream] && pcm_ops && pcm_ops->hw_free) {
|
2022-03-17 10:50:38 -07:00
|
|
|
ret = pcm_ops->hw_free(component, substream);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
spcm->prepared[substream->stream] = false;
|
|
|
|
}
|
2020-01-10 17:57:49 -06:00
|
|
|
|
2022-04-26 10:17:36 -07:00
|
|
|
ret = snd_sof_pcm_platform_hw_params(sdev, substream, params, &platform_params);
|
|
|
|
if (ret < 0) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, substream->stream, "platform hw params failed\n");
|
2022-04-26 10:17:36 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-03-17 10:50:39 -07:00
|
|
|
/* if this is a repeated hw_params without hw_free, skip setting up widgets */
|
|
|
|
if (!spcm->stream[substream->stream].list) {
|
2022-04-26 10:17:43 -07:00
|
|
|
ret = sof_pcm_setup_connected_widgets(sdev, rtd, spcm, params, &platform_params,
|
|
|
|
substream->stream);
|
2022-03-17 10:50:39 -07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2019-04-12 11:05:10 -05:00
|
|
|
|
2019-12-11 18:20:19 +01:00
|
|
|
/* create compressed page table for audio firmware */
|
|
|
|
if (runtime->buffer_changed) {
|
2025-06-19 13:46:08 +03:00
|
|
|
struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream);
|
2022-03-17 10:50:39 -07:00
|
|
|
|
2025-06-19 13:46:08 +03:00
|
|
|
ret = snd_sof_create_page_table(component->dev, dmab,
|
|
|
|
spcm->stream[substream->stream].page_table.area,
|
|
|
|
runtime->dma_bytes);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-12-21 12:23:21 +02:00
|
|
|
if (pcm_ops && pcm_ops->hw_params) {
|
2022-03-17 10:50:39 -07:00
|
|
|
ret = pcm_ops->hw_params(component, substream, params, &platform_params);
|
2021-09-27 15:05:16 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-22 09:13:43 -05:00
|
|
|
spcm->prepared[substream->stream] = true;
|
|
|
|
|
2019-04-12 11:05:10 -05:00
|
|
|
/* save pcm hw_params */
|
|
|
|
memcpy(&spcm->params[substream->stream], params, sizeof(*params));
|
|
|
|
|
2022-03-17 10:50:39 -07:00
|
|
|
return 0;
|
2019-04-12 11:05:10 -05:00
|
|
|
}
|
|
|
|
|
2025-02-06 11:28:25 +02:00
|
|
|
static int sof_pcm_stream_free(struct snd_sof_dev *sdev,
|
|
|
|
struct snd_pcm_substream *substream,
|
|
|
|
struct snd_sof_pcm *spcm, int dir,
|
|
|
|
bool free_widget_list)
|
|
|
|
{
|
|
|
|
const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
|
|
|
|
int ret;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (spcm->prepared[substream->stream]) {
|
|
|
|
/* stop DMA first if needed */
|
|
|
|
if (pcm_ops && pcm_ops->platform_stop_during_hw_free)
|
|
|
|
snd_sof_pcm_platform_trigger(sdev, substream,
|
|
|
|
SNDRV_PCM_TRIGGER_STOP);
|
|
|
|
|
|
|
|
/* free PCM in the DSP */
|
|
|
|
if (pcm_ops && pcm_ops->hw_free) {
|
|
|
|
ret = pcm_ops->hw_free(sdev->component, substream);
|
|
|
|
if (ret < 0) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, substream->stream,
|
|
|
|
"pcm_ops->hw_free failed %d\n", ret);
|
2025-02-06 11:28:25 +02:00
|
|
|
err = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spcm->prepared[substream->stream] = false;
|
|
|
|
spcm->pending_stop[substream->stream] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the DMA */
|
|
|
|
ret = snd_sof_pcm_platform_hw_free(sdev, substream);
|
|
|
|
if (ret < 0) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, substream->stream,
|
|
|
|
"platform hw free failed %d\n", ret);
|
2025-02-06 11:28:25 +02:00
|
|
|
if (!err)
|
|
|
|
err = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free widget list */
|
|
|
|
if (free_widget_list) {
|
|
|
|
ret = sof_widget_list_free(sdev, spcm, dir);
|
|
|
|
if (ret < 0) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, substream->stream,
|
|
|
|
"sof_widget_list_free failed %d\n", ret);
|
2025-02-06 11:28:25 +02:00
|
|
|
if (!err)
|
|
|
|
err = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sof_pcm_free_all_streams(struct snd_sof_dev *sdev)
|
|
|
|
{
|
|
|
|
struct snd_pcm_substream *substream;
|
|
|
|
struct snd_sof_pcm *spcm;
|
|
|
|
int dir, ret;
|
|
|
|
|
|
|
|
list_for_each_entry(spcm, &sdev->pcm_list, list) {
|
|
|
|
for_each_pcm_streams(dir) {
|
|
|
|
substream = spcm->stream[dir].substream;
|
|
|
|
|
|
|
|
if (!substream || !substream->runtime ||
|
|
|
|
spcm->stream[dir].suspend_ignored)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (spcm->stream[dir].list) {
|
|
|
|
ret = sof_pcm_stream_free(sdev, substream, spcm,
|
|
|
|
dir, true);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-02 14:32:56 +09:00
|
|
|
static int sof_pcm_hw_free(struct snd_soc_component *component,
|
|
|
|
struct snd_pcm_substream *substream)
|
2019-04-12 11:05:10 -05:00
|
|
|
{
|
2023-09-26 06:25:22 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
|
|
|
struct snd_sof_pcm *spcm;
|
2024-04-02 10:18:25 -05:00
|
|
|
int ret;
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
/* nothing to do for BE */
|
|
|
|
if (rtd->dai_link->no_pcm)
|
|
|
|
return 0;
|
|
|
|
|
2019-12-04 15:15:51 -06:00
|
|
|
spcm = snd_sof_find_spcm_dai(component, rtd);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (!spcm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_dbg(spcm, substream->stream, "Entry: hw_free\n");
|
2019-04-12 11:05:10 -05:00
|
|
|
|
2024-04-02 10:18:25 -05:00
|
|
|
ret = sof_pcm_stream_free(sdev, substream, spcm, substream->stream, true);
|
2021-11-25 12:15:18 +02:00
|
|
|
|
|
|
|
cancel_work_sync(&spcm->stream[substream->stream].period_elapsed_work);
|
|
|
|
|
2024-04-02 10:18:25 -05:00
|
|
|
return ret;
|
2019-04-12 11:05:10 -05:00
|
|
|
}
|
|
|
|
|
2019-10-02 14:32:56 +09:00
|
|
|
static int sof_pcm_prepare(struct snd_soc_component *component,
|
|
|
|
struct snd_pcm_substream *substream)
|
2019-04-12 11:05:10 -05:00
|
|
|
{
|
2023-09-26 06:25:22 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
2024-04-02 10:18:27 -05:00
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_pcm *spcm;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* nothing to do for BE */
|
|
|
|
if (rtd->dai_link->no_pcm)
|
|
|
|
return 0;
|
|
|
|
|
2019-12-04 15:15:51 -06:00
|
|
|
spcm = snd_sof_find_spcm_dai(component, rtd);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (!spcm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_dbg(spcm, substream->stream, "Entry: prepare\n");
|
|
|
|
|
2024-04-02 10:18:27 -05:00
|
|
|
if (spcm->prepared[substream->stream]) {
|
|
|
|
if (!spcm->pending_stop[substream->stream])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this case should be reached in case of xruns where we absolutely
|
|
|
|
* want to free-up and reset all PCM/DMA resources
|
|
|
|
*/
|
|
|
|
ret = sof_pcm_stream_free(sdev, substream, spcm, substream->stream, true);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
/* set hw_params */
|
2019-10-02 14:32:56 +09:00
|
|
|
ret = sof_pcm_hw_params(component,
|
|
|
|
substream, &spcm->params[substream->stream]);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (ret < 0) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, substream->stream,
|
|
|
|
"failed to set hw_params after resume\n");
|
2019-04-12 11:05:10 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FE dai link trigger actions are always executed in non-atomic context because
|
|
|
|
* they involve IPC's.
|
|
|
|
*/
|
2019-10-02 14:32:56 +09:00
|
|
|
static int sof_pcm_trigger(struct snd_soc_component *component,
|
|
|
|
struct snd_pcm_substream *substream, int cmd)
|
2019-04-12 11:05:10 -05:00
|
|
|
{
|
2023-09-26 06:25:22 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
2022-12-21 12:23:21 +02:00
|
|
|
const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_pcm *spcm;
|
2019-07-22 09:13:43 -05:00
|
|
|
bool reset_hw_params = false;
|
2019-09-27 15:05:31 -05:00
|
|
|
bool ipc_first = false;
|
2022-03-17 10:50:40 -07:00
|
|
|
int ret = 0;
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
/* nothing to do for BE */
|
|
|
|
if (rtd->dai_link->no_pcm)
|
|
|
|
return 0;
|
|
|
|
|
2019-12-04 15:15:51 -06:00
|
|
|
spcm = snd_sof_find_spcm_dai(component, rtd);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (!spcm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_dbg(spcm, substream->stream, "Entry: trigger (cmd: %d)\n", cmd);
|
2019-04-12 11:05:10 -05:00
|
|
|
|
2024-04-02 10:18:26 -05:00
|
|
|
spcm->pending_stop[substream->stream] = false;
|
|
|
|
|
2019-04-12 11:05:10 -05:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
2019-09-27 15:05:31 -05:00
|
|
|
ipc_first = true;
|
2019-04-12 11:05:10 -05:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
2023-03-22 11:43:46 +02:00
|
|
|
if (pcm_ops && pcm_ops->ipc_first_on_start)
|
|
|
|
ipc_first = true;
|
2019-04-12 11:05:10 -05:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2019-10-25 17:41:18 -05:00
|
|
|
if (spcm->stream[substream->stream].suspend_ignored) {
|
|
|
|
/*
|
|
|
|
* This case will be triggered when INFO_RESUME is
|
|
|
|
* not supported, no need to re-start streams that
|
|
|
|
* remained enabled in D0ix.
|
|
|
|
*/
|
|
|
|
spcm->stream[substream->stream].suspend_ignored = false;
|
|
|
|
return 0;
|
|
|
|
}
|
2023-03-22 11:43:46 +02:00
|
|
|
|
|
|
|
if (pcm_ops && pcm_ops->ipc_first_on_start)
|
|
|
|
ipc_first = true;
|
2019-04-12 11:05:10 -05:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
2024-04-08 14:41:46 -05:00
|
|
|
/*
|
|
|
|
* If DSP D0I3 is allowed during S0iX, set the suspend_ignored flag for
|
|
|
|
* D0I3-compatible streams to keep the firmware pipeline running
|
|
|
|
*/
|
|
|
|
if (pcm_ops && pcm_ops->d0i3_supported_in_s0ix &&
|
|
|
|
sdev->system_suspend_target == SOF_SUSPEND_S0IX &&
|
2019-10-25 17:41:18 -05:00
|
|
|
spcm->stream[substream->stream].d0i3_compatible) {
|
|
|
|
spcm->stream[substream->stream].suspend_ignored = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2023-04-04 12:21:06 +03:00
|
|
|
|
|
|
|
/* On suspend the DMA must be stopped in DSPless mode */
|
|
|
|
if (sdev->dspless_mode_selected)
|
|
|
|
reset_hw_params = true;
|
|
|
|
|
2020-08-23 17:36:59 -05:00
|
|
|
fallthrough;
|
2019-04-12 11:05:10 -05:00
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
2019-09-27 15:05:31 -05:00
|
|
|
ipc_first = true;
|
2023-03-22 11:43:45 +02:00
|
|
|
if (pcm_ops && pcm_ops->reset_hw_params_during_stop)
|
|
|
|
reset_hw_params = true;
|
2019-04-12 11:05:10 -05:00
|
|
|
break;
|
|
|
|
default:
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, substream->stream, "Unhandled trigger cmd %d\n", cmd);
|
2019-04-12 11:05:10 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-09-27 15:05:31 -05:00
|
|
|
if (!ipc_first)
|
|
|
|
snd_sof_pcm_platform_trigger(sdev, substream, cmd);
|
2019-04-12 11:05:10 -05:00
|
|
|
|
2022-12-21 12:23:21 +02:00
|
|
|
if (pcm_ops && pcm_ops->trigger)
|
2022-03-17 10:50:40 -07:00
|
|
|
ret = pcm_ops->trigger(component, substream, cmd);
|
2019-04-12 11:05:10 -05:00
|
|
|
|
2023-03-22 11:43:46 +02:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
/* invoke platform trigger to start DMA only if pcm_ops is successful */
|
|
|
|
if (ipc_first && !ret)
|
|
|
|
snd_sof_pcm_platform_trigger(sdev, substream, cmd);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
2023-04-20 14:41:37 +03:00
|
|
|
/* invoke platform trigger to stop DMA even if pcm_ops isn't set or if it failed */
|
2023-05-12 14:42:25 +08:00
|
|
|
if (!pcm_ops || !pcm_ops->platform_stop_during_hw_free)
|
2023-04-20 14:41:37 +03:00
|
|
|
snd_sof_pcm_platform_trigger(sdev, substream, cmd);
|
2024-04-02 10:18:26 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* set the pending_stop flag to indicate that pipeline stop has been delayed.
|
|
|
|
* This will be used later to stop the pipelines during prepare when recovering
|
|
|
|
* from xruns.
|
|
|
|
*/
|
|
|
|
if (pcm_ops && pcm_ops->platform_stop_during_hw_free &&
|
|
|
|
cmd == SNDRV_PCM_TRIGGER_STOP)
|
|
|
|
spcm->pending_stop[substream->stream] = true;
|
2023-03-22 11:43:46 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-09-27 15:05:31 -05:00
|
|
|
|
|
|
|
/* free PCM if reset_hw_params is set and the STOP IPC is successful */
|
2022-03-30 13:19:26 -07:00
|
|
|
if (!ret && reset_hw_params)
|
2023-01-27 14:00:18 +02:00
|
|
|
ret = sof_pcm_stream_free(sdev, substream, spcm, substream->stream, false);
|
2019-04-12 11:05:10 -05:00
|
|
|
|
2019-07-22 09:13:44 -05:00
|
|
|
return ret;
|
2019-04-12 11:05:10 -05:00
|
|
|
}
|
|
|
|
|
2019-10-02 14:32:56 +09:00
|
|
|
static snd_pcm_uframes_t sof_pcm_pointer(struct snd_soc_component *component,
|
|
|
|
struct snd_pcm_substream *substream)
|
2019-04-12 11:05:10 -05:00
|
|
|
{
|
2023-09-26 06:25:22 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
2024-03-21 15:08:11 +02:00
|
|
|
const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_pcm *spcm;
|
|
|
|
snd_pcm_uframes_t host, dai;
|
2024-03-21 15:08:11 +02:00
|
|
|
int ret = -EOPNOTSUPP;
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
/* nothing to do for BE */
|
|
|
|
if (rtd->dai_link->no_pcm)
|
|
|
|
return 0;
|
|
|
|
|
2024-03-21 15:08:11 +02:00
|
|
|
if (pcm_ops && pcm_ops->pointer)
|
|
|
|
ret = pcm_ops->pointer(component, substream, &host);
|
|
|
|
|
|
|
|
if (ret != -EOPNOTSUPP)
|
|
|
|
return ret ? ret : host;
|
|
|
|
|
2019-04-12 11:05:10 -05:00
|
|
|
/* use dsp ops pointer callback directly if set */
|
|
|
|
if (sof_ops(sdev)->pcm_pointer)
|
|
|
|
return sof_ops(sdev)->pcm_pointer(sdev, substream);
|
|
|
|
|
2019-12-04 15:15:51 -06:00
|
|
|
spcm = snd_sof_find_spcm_dai(component, rtd);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (!spcm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* read position from DSP */
|
|
|
|
host = bytes_to_frames(substream->runtime,
|
|
|
|
spcm->stream[substream->stream].posn.host_posn);
|
|
|
|
dai = bytes_to_frames(substream->runtime,
|
|
|
|
spcm->stream[substream->stream].posn.dai_posn);
|
|
|
|
|
2022-09-19 14:21:07 +02:00
|
|
|
trace_sof_pcm_pointer_position(sdev, spcm, substream, host, dai);
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
|
2019-10-02 14:32:56 +09:00
|
|
|
static int sof_pcm_open(struct snd_soc_component *component,
|
|
|
|
struct snd_pcm_substream *substream)
|
2019-04-12 11:05:10 -05:00
|
|
|
{
|
2023-09-26 06:25:22 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
2024-04-26 11:03:50 +02:00
|
|
|
const struct snd_sof_dsp_ops *ops = sof_ops(sdev);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_pcm *spcm;
|
|
|
|
struct snd_soc_tplg_stream_caps *caps;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* nothing to do for BE */
|
|
|
|
if (rtd->dai_link->no_pcm)
|
|
|
|
return 0;
|
|
|
|
|
2019-12-04 15:15:51 -06:00
|
|
|
spcm = snd_sof_find_spcm_dai(component, rtd);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (!spcm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_dbg(spcm, substream->stream, "Entry: open\n");
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
caps = &spcm->pcm.caps[substream->stream];
|
|
|
|
|
|
|
|
/* set runtime config */
|
2019-10-24 16:03:17 -05:00
|
|
|
runtime->hw.info = ops->hw_info; /* platform-specific */
|
|
|
|
|
ASoC: SOF: relax PCM period and buffer size constraints
Current SOF implementation limits period and buffer sizes to multiples
of period_min. Period_min is defined in topology, but is in practise set
to align with the SOF DSP timer tick (typically 1ms).
While this approach helps user-space to avoid period sizes, which are
not aligned to the DSP timer tick, it causes problems to applications
which want to align data processing size to that of ALSA period size.
One example is JACK audio server, which limits period sizes to power of
two values.
Other ALSA drivers where audio data transfer is driven by a timer tick,
like USB, do not constraint period and buffer sizes to exact multiple of
the timer tick.
To align SOF to follow the same behaviour, drop the additional alignment
constraints. As a side-effect, this patch can cause irregularity to
period wakeup timing. This happens when application chooses settings
which were previously forbidden. For example, if application configures
period size to 2^14 bytes and audio config of S32_LE/2ch/48000Hz, one
period represents 42.667ms of audio. Without this patch, this
configuration is not allowed by SOF. With the patch applied,
configuration is allowed but the wakeups are paced by the DSP timer
tick, which is typically 1ms. Application will see period wakeups with a
42/43/42/43ms repeating pattern.
Both approaches are valid within ALSA context, but relaxing the
constraints is better aligned with existing applications and other ALSA
drivers like USB audio.
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/20201118140545.2138895-1-kai.vehmanen@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-18 16:05:44 +02:00
|
|
|
/* set any runtime constraints based on topology */
|
2019-04-12 11:05:10 -05:00
|
|
|
runtime->hw.formats = le64_to_cpu(caps->formats);
|
|
|
|
runtime->hw.period_bytes_min = le32_to_cpu(caps->period_size_min);
|
|
|
|
runtime->hw.period_bytes_max = le32_to_cpu(caps->period_size_max);
|
|
|
|
runtime->hw.periods_min = le32_to_cpu(caps->periods_min);
|
|
|
|
runtime->hw.periods_max = le32_to_cpu(caps->periods_max);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* caps->buffer_size_min is not used since the
|
|
|
|
* snd_pcm_hardware structure only defines buffer_bytes_max
|
|
|
|
*/
|
|
|
|
runtime->hw.buffer_bytes_max = le32_to_cpu(caps->buffer_size_max);
|
|
|
|
|
|
|
|
/* set wait time - TODO: come from topology */
|
|
|
|
substream->wait_time = 500;
|
|
|
|
|
|
|
|
spcm->stream[substream->stream].posn.host_posn = 0;
|
|
|
|
spcm->stream[substream->stream].posn.dai_posn = 0;
|
|
|
|
spcm->stream[substream->stream].substream = substream;
|
2019-07-22 09:13:43 -05:00
|
|
|
spcm->prepared[substream->stream] = false;
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
ret = snd_sof_pcm_platform_open(sdev, substream);
|
2025-02-06 11:28:26 +02:00
|
|
|
if (ret < 0) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, substream->stream,
|
|
|
|
"platform pcm open failed %d\n", ret);
|
2025-02-06 11:28:26 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2019-04-12 11:05:10 -05:00
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_dbg(spcm, substream->stream, "period bytes min %zd, max %zd\n",
|
|
|
|
runtime->hw.period_bytes_min, runtime->hw.period_bytes_max);
|
|
|
|
spcm_dbg(spcm, substream->stream, "period count min %d, max %d\n",
|
|
|
|
runtime->hw.periods_min, runtime->hw.periods_max);
|
|
|
|
spcm_dbg(spcm, substream->stream, "buffer bytes max %zd\n", runtime->hw.buffer_bytes_max);
|
2025-02-06 11:28:26 +02:00
|
|
|
|
|
|
|
return 0;
|
2019-04-12 11:05:10 -05:00
|
|
|
}
|
|
|
|
|
2019-10-02 14:32:56 +09:00
|
|
|
static int sof_pcm_close(struct snd_soc_component *component,
|
|
|
|
struct snd_pcm_substream *substream)
|
2019-04-12 11:05:10 -05:00
|
|
|
{
|
2023-09-26 06:25:22 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
|
|
|
struct snd_sof_pcm *spcm;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* nothing to do for BE */
|
|
|
|
if (rtd->dai_link->no_pcm)
|
|
|
|
return 0;
|
|
|
|
|
2019-12-04 15:15:51 -06:00
|
|
|
spcm = snd_sof_find_spcm_dai(component, rtd);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (!spcm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_dbg(spcm, substream->stream, "Entry: close\n");
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
err = snd_sof_pcm_platform_close(sdev, substream);
|
|
|
|
if (err < 0) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, substream->stream,
|
|
|
|
"platform pcm close failed %d\n", err);
|
2019-04-12 11:05:10 -05:00
|
|
|
/*
|
|
|
|
* keep going, no point in preventing the close
|
|
|
|
* from happening
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2025-02-05 15:52:32 +02:00
|
|
|
spcm->stream[substream->stream].substream = NULL;
|
|
|
|
|
2019-04-12 11:05:10 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pre-allocate playback/capture audio buffer pages.
|
|
|
|
* no need to explicitly release memory preallocated by sof_pcm_new in pcm_free
|
|
|
|
* snd_pcm_lib_preallocate_free_for_all() is called by the core.
|
|
|
|
*/
|
2019-10-02 14:32:56 +09:00
|
|
|
static int sof_pcm_new(struct snd_soc_component *component,
|
|
|
|
struct snd_soc_pcm_runtime *rtd)
|
2019-04-12 11:05:10 -05:00
|
|
|
{
|
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
|
|
|
struct snd_sof_pcm *spcm;
|
|
|
|
struct snd_pcm *pcm = rtd->pcm;
|
|
|
|
struct snd_soc_tplg_stream_caps *caps;
|
|
|
|
int stream = SNDRV_PCM_STREAM_PLAYBACK;
|
|
|
|
|
|
|
|
/* find SOF PCM for this RTD */
|
2019-12-04 15:15:51 -06:00
|
|
|
spcm = snd_sof_find_spcm_dai(component, rtd);
|
2019-04-12 11:05:10 -05:00
|
|
|
if (!spcm) {
|
2019-12-04 15:15:51 -06:00
|
|
|
dev_warn(component->dev, "warn: can't find PCM with DAI ID %d\n",
|
2019-04-12 11:05:10 -05:00
|
|
|
rtd->dai_link->id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
dev_dbg(spcm->scomp->dev, "pcm%u (%s): Entry: pcm_construct\n",
|
|
|
|
spcm->pcm.pcm_id, spcm->pcm.pcm_name);
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
/* do we need to pre-allocate playback audio buffer pages */
|
|
|
|
if (!spcm->pcm.playback)
|
|
|
|
goto capture;
|
|
|
|
|
|
|
|
caps = &spcm->pcm.caps[stream];
|
|
|
|
|
2020-01-24 15:36:19 -06:00
|
|
|
if (!pcm->streams[stream].substream) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, stream, "NULL playback substream!\n");
|
2020-01-24 15:36:19 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
/* pre-allocate playback audio buffer pages */
|
|
|
|
spcm_dbg(spcm, stream, "allocate %s playback DMA buffer size 0x%x max 0x%x\n",
|
|
|
|
caps->name, caps->buffer_size_min, caps->buffer_size_max);
|
|
|
|
|
2019-12-11 18:20:19 +01:00
|
|
|
snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
|
|
|
|
SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
|
2020-02-28 17:18:47 -06:00
|
|
|
0, le32_to_cpu(caps->buffer_size_max));
|
2019-04-12 11:05:10 -05:00
|
|
|
capture:
|
|
|
|
stream = SNDRV_PCM_STREAM_CAPTURE;
|
|
|
|
|
|
|
|
/* do we need to pre-allocate capture audio buffer pages */
|
|
|
|
if (!spcm->pcm.capture)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
caps = &spcm->pcm.caps[stream];
|
|
|
|
|
2020-01-24 15:36:19 -06:00
|
|
|
if (!pcm->streams[stream].substream) {
|
2025-02-06 11:28:27 +02:00
|
|
|
spcm_err(spcm, stream, "NULL capture substream!\n");
|
2020-01-24 15:36:19 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2025-02-06 11:28:27 +02:00
|
|
|
/* pre-allocate capture audio buffer pages */
|
|
|
|
spcm_dbg(spcm, stream, "allocate %s capture DMA buffer size 0x%x max 0x%x\n",
|
|
|
|
caps->name, caps->buffer_size_min, caps->buffer_size_max);
|
|
|
|
|
2019-12-11 18:20:19 +01:00
|
|
|
snd_pcm_set_managed_buffer(pcm->streams[stream].substream,
|
|
|
|
SNDRV_DMA_TYPE_DEV_SG, sdev->dev,
|
2020-02-28 17:18:47 -06:00
|
|
|
0, le32_to_cpu(caps->buffer_size_max));
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fixup the BE DAI link to match any values from topology */
|
2020-11-20 16:16:53 +02:00
|
|
|
int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params)
|
2019-04-12 11:05:10 -05:00
|
|
|
{
|
|
|
|
struct snd_interval *rate = hw_param_interval(params,
|
|
|
|
SNDRV_PCM_HW_PARAM_RATE);
|
|
|
|
struct snd_interval *channels = hw_param_interval(params,
|
|
|
|
SNDRV_PCM_HW_PARAM_CHANNELS);
|
|
|
|
struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
|
|
|
|
struct snd_soc_component *component =
|
2019-12-04 15:15:51 -06:00
|
|
|
snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
|
2019-04-12 11:05:10 -05:00
|
|
|
struct snd_sof_dai *dai =
|
2019-12-04 15:15:51 -06:00
|
|
|
snd_sof_find_dai(component, (char *)rtd->dai_link->name);
|
2021-03-26 18:51:50 +02:00
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
2022-12-21 12:23:21 +02:00
|
|
|
const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
/* no topology exists for this BE, try a common configuration */
|
|
|
|
if (!dai) {
|
2019-12-04 15:15:51 -06:00
|
|
|
dev_warn(component->dev,
|
|
|
|
"warning: no topology found for BE DAI %s config\n",
|
2019-04-12 11:05:10 -05:00
|
|
|
rtd->dai_link->name);
|
|
|
|
|
|
|
|
/* set 48k, stereo, 16bits by default */
|
|
|
|
rate->min = 48000;
|
|
|
|
rate->max = 48000;
|
|
|
|
|
|
|
|
channels->min = 2;
|
|
|
|
channels->max = 2;
|
|
|
|
|
|
|
|
snd_mask_none(fmt);
|
|
|
|
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-12-21 12:23:21 +02:00
|
|
|
if (pcm_ops && pcm_ops->dai_link_fixup)
|
2022-03-17 10:50:41 -07:00
|
|
|
return pcm_ops->dai_link_fixup(rtd, params);
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-04-09 15:01:20 -07:00
|
|
|
EXPORT_SYMBOL(sof_pcm_dai_link_fixup);
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
static int sof_pcm_probe(struct snd_soc_component *component)
|
|
|
|
{
|
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
|
|
|
struct snd_sof_pdata *plat_data = sdev->pdata;
|
|
|
|
const char *tplg_filename;
|
|
|
|
int ret;
|
|
|
|
|
2022-06-16 16:08:24 -05:00
|
|
|
/*
|
|
|
|
* make sure the device is pm_runtime_active before loading the
|
|
|
|
* topology and initiating IPC or bus transactions
|
|
|
|
*/
|
|
|
|
ret = pm_runtime_resume_and_get(component->dev);
|
|
|
|
if (ret < 0 && ret != -EACCES)
|
|
|
|
return ret;
|
|
|
|
|
2019-04-12 11:05:10 -05:00
|
|
|
/* load the default topology */
|
|
|
|
sdev->component = component;
|
|
|
|
|
|
|
|
tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
|
|
|
|
"%s/%s",
|
|
|
|
plat_data->tplg_filename_prefix,
|
|
|
|
plat_data->tplg_filename);
|
2023-05-12 13:33:14 +03:00
|
|
|
if (!tplg_filename) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto pm_error;
|
|
|
|
}
|
2019-04-12 11:05:10 -05:00
|
|
|
|
2019-12-04 15:15:51 -06:00
|
|
|
ret = snd_sof_load_topology(component, tplg_filename);
|
2023-05-12 13:33:14 +03:00
|
|
|
if (ret < 0)
|
2019-12-04 15:15:51 -06:00
|
|
|
dev_err(component->dev, "error: failed to load DSP topology %d\n",
|
2019-04-12 11:05:10 -05:00
|
|
|
ret);
|
|
|
|
|
2023-05-12 13:33:14 +03:00
|
|
|
pm_error:
|
2022-06-16 16:08:24 -05:00
|
|
|
pm_runtime_put_autosuspend(component->dev);
|
|
|
|
|
2019-04-12 11:05:10 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sof_pcm_remove(struct snd_soc_component *component)
|
|
|
|
{
|
|
|
|
/* remove topology */
|
2020-10-30 10:54:23 -04:00
|
|
|
snd_soc_tplg_component_remove(component);
|
2019-04-12 11:05:10 -05:00
|
|
|
}
|
|
|
|
|
2021-11-19 17:08:51 -06:00
|
|
|
static int sof_pcm_ack(struct snd_soc_component *component,
|
|
|
|
struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
|
|
|
|
|
|
|
return snd_sof_pcm_platform_ack(sdev, substream);
|
|
|
|
}
|
|
|
|
|
2023-02-02 15:29:51 +02:00
|
|
|
static snd_pcm_sframes_t sof_pcm_delay(struct snd_soc_component *component,
|
|
|
|
struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
|
|
|
const struct sof_ipc_pcm_ops *pcm_ops = sof_ipc_get_ops(sdev, pcm);
|
|
|
|
|
|
|
|
if (pcm_ops && pcm_ops->delay)
|
|
|
|
return pcm_ops->delay(component, substream);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-12 11:05:10 -05:00
|
|
|
void snd_sof_new_platform_drv(struct snd_sof_dev *sdev)
|
|
|
|
{
|
|
|
|
struct snd_soc_component_driver *pd = &sdev->plat_drv;
|
|
|
|
struct snd_sof_pdata *plat_data = sdev->pdata;
|
|
|
|
const char *drv_name;
|
|
|
|
|
2022-08-05 15:04:48 +08:00
|
|
|
if (plat_data->machine)
|
|
|
|
drv_name = plat_data->machine->drv_name;
|
|
|
|
else if (plat_data->of_machine)
|
|
|
|
drv_name = plat_data->of_machine->drv_name;
|
|
|
|
else
|
|
|
|
drv_name = NULL;
|
2019-04-12 11:05:10 -05:00
|
|
|
|
|
|
|
pd->name = "sof-audio-component";
|
|
|
|
pd->probe = sof_pcm_probe;
|
|
|
|
pd->remove = sof_pcm_remove;
|
2019-10-02 14:32:56 +09:00
|
|
|
pd->open = sof_pcm_open;
|
|
|
|
pd->close = sof_pcm_close;
|
|
|
|
pd->hw_params = sof_pcm_hw_params;
|
|
|
|
pd->prepare = sof_pcm_prepare;
|
|
|
|
pd->hw_free = sof_pcm_hw_free;
|
|
|
|
pd->trigger = sof_pcm_trigger;
|
|
|
|
pd->pointer = sof_pcm_pointer;
|
2021-11-19 17:08:51 -06:00
|
|
|
pd->ack = sof_pcm_ack;
|
2023-02-02 15:29:51 +02:00
|
|
|
pd->delay = sof_pcm_delay;
|
2019-10-02 14:32:56 +09:00
|
|
|
|
2022-02-23 17:38:49 +02:00
|
|
|
#if IS_ENABLED(CONFIG_SND_SOC_SOF_COMPRESS)
|
|
|
|
pd->compress_ops = &sof_compressed_ops;
|
|
|
|
#endif
|
|
|
|
|
2019-10-02 14:32:56 +09:00
|
|
|
pd->pcm_construct = sof_pcm_new;
|
2019-04-12 11:05:10 -05:00
|
|
|
pd->ignore_machine = drv_name;
|
|
|
|
pd->be_pcm_base = SOF_BE_PCM_BASE;
|
|
|
|
pd->use_dai_pcm_id = true;
|
|
|
|
pd->topology_name_prefix = "sof";
|
|
|
|
|
|
|
|
/* increment module refcount when a pcm is opened */
|
|
|
|
pd->module_get_upon_open = 1;
|
2022-06-23 13:51:43 +01:00
|
|
|
|
|
|
|
pd->legacy_dai_naming = 1;
|
2023-04-04 12:21:06 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The fixup is only needed when the DSP is in use as with the DSPless
|
|
|
|
* mode we are directly using the audio interface
|
|
|
|
*/
|
|
|
|
if (!sdev->dspless_mode_selected)
|
|
|
|
pd->be_hw_params_fixup = sof_pcm_dai_link_fixup;
|
2019-04-12 11:05:10 -05:00
|
|
|
}
|