summaryrefslogtreecommitdiffstats
path: root/sound/soc/sof/pcm.c
diff options
context:
space:
mode:
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>2019-12-04 15:15:51 -0600
committerMark Brown <broonie@kernel.org>2019-12-09 18:38:57 +0000
commitee1e79b72e3cf5eac42ba9de827536f91d4c04e2 (patch)
treee4def1693d15948abd5996ad4cc8965d61554265 /sound/soc/sof/pcm.c
parent03eec9b4eb897dde5985579508c978e7a29052bd (diff)
downloadlinux-stable-ee1e79b72e3cf5eac42ba9de827536f91d4c04e2.tar.gz
linux-stable-ee1e79b72e3cf5eac42ba9de827536f91d4c04e2.tar.bz2
linux-stable-ee1e79b72e3cf5eac42ba9de827536f91d4c04e2.zip
ASoC: SOF: partition audio-related parts from SOF core
Move all the audio-specific code in the core, audio-specific logic in the top-level PM callbacks and the core header files into a separate file (sof-audio.*) in preparation for adding an audio client device. In the process of moving all structure definitions for widget, routes, pcm's etc, the snd_sof_dev member in all these structs is replaced with the snd_soc_component member. Also, use the component device instead of the snd_sof_dev device wherever possible in the PCM component driver, control IO functions and the topology parser as the component device will be moved over to the client device later on. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20191204211556.12671-9-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/sof/pcm.c')
-rw-r--r--sound/soc/sof/pcm.c123
1 files changed, 63 insertions, 60 deletions
diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c
index a9c47f6bf657..54ec78799c30 100644
--- a/sound/soc/sof/pcm.c
+++ b/sound/soc/sof/pcm.c
@@ -14,38 +14,38 @@
#include <sound/pcm_params.h>
#include <sound/sof.h>
#include "sof-priv.h"
+#include "sof-audio.h"
#include "ops.h"
-#define DRV_NAME "sof-audio-component"
-
/* Create DMA buffer page table for DSP */
static int create_page_table(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
unsigned char *dma_area, size_t size)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
- struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
struct snd_sof_pcm *spcm;
struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream);
int stream = substream->stream;
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm)
return -EINVAL;
- return snd_sof_create_page_table(sdev->dev, dmab,
+ return snd_sof_create_page_table(component->dev, dmab,
spcm->stream[stream].page_table.area, size);
}
static int sof_pcm_dsp_params(struct snd_sof_pcm *spcm, struct snd_pcm_substream *substream,
const struct sof_ipc_pcm_params_reply *reply)
{
- struct snd_sof_dev *sdev = spcm->sdev;
+ struct snd_soc_component *scomp = spcm->scomp;
+ struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
+
/* validate offset */
int ret = snd_sof_ipc_pcm_params(sdev, substream, reply);
if (ret < 0)
- dev_err(sdev->dev, "error: got wrong reply for PCM %d\n",
+ dev_err(scomp->dev, "error: got wrong reply for PCM %d\n",
spcm->pcm.pcm_id);
return ret;
@@ -70,13 +70,12 @@ void snd_sof_pcm_period_elapsed(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_component *component =
- snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+ snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
struct snd_sof_pcm *spcm;
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm) {
- dev_err(sdev->dev,
+ dev_err(component->dev,
"error: period elapsed for unknown stream!\n");
return;
}
@@ -110,11 +109,11 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
if (rtd->dai_link->no_pcm)
return 0;
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm)
return -EINVAL;
- dev_dbg(sdev->dev, "pcm: hw params stream %d dir %d\n",
+ dev_dbg(component->dev, "pcm: hw params stream %d dir %d\n",
spcm->pcm.pcm_id, substream->stream);
memset(&pcm, 0, sizeof(pcm));
@@ -122,7 +121,7 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
/* allocate audio buffer pages */
ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
if (ret < 0) {
- dev_err(sdev->dev, "error: could not allocate %d bytes for PCM %d\n",
+ dev_err(component->dev, "error: could not allocate %d bytes for PCM %d\n",
params_buffer_bytes(params), spcm->pcm.pcm_id);
return ret;
}
@@ -187,17 +186,17 @@ static int sof_pcm_hw_params(struct snd_soc_component *component,
params,
&pcm.params);
if (ret < 0) {
- dev_err(sdev->dev, "error: platform hw params failed\n");
+ dev_err(component->dev, "error: platform hw params failed\n");
return ret;
}
- dev_dbg(sdev->dev, "stream_tag %d", pcm.params.stream_tag);
+ dev_dbg(component->dev, "stream_tag %d", pcm.params.stream_tag);
/* send IPC to the DSP */
ret = sof_ipc_tx_message(sdev->ipc, pcm.hdr.cmd, &pcm, sizeof(pcm),
&ipc_params_reply, sizeof(ipc_params_reply));
if (ret < 0) {
- dev_err(sdev->dev, "error: hw params ipc failed for stream %d\n",
+ dev_err(component->dev, "error: hw params ipc failed for stream %d\n",
pcm.params.stream_tag);
return ret;
}
@@ -247,12 +246,12 @@ static int sof_pcm_hw_free(struct snd_soc_component *component,
if (rtd->dai_link->no_pcm)
return 0;
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm)
return -EINVAL;
- dev_dbg(sdev->dev, "pcm: free stream %d dir %d\n", spcm->pcm.pcm_id,
- substream->stream);
+ dev_dbg(component->dev, "pcm: free stream %d dir %d\n",
+ spcm->pcm.pcm_id, substream->stream);
if (spcm->prepared[substream->stream]) {
ret = sof_pcm_dsp_pcm_free(substream, sdev, spcm);
@@ -266,7 +265,7 @@ static int sof_pcm_hw_free(struct snd_soc_component *component,
ret = snd_sof_pcm_platform_hw_free(sdev, substream);
if (ret < 0) {
- dev_err(sdev->dev, "error: platform hw free failed\n");
+ dev_err(component->dev, "error: platform hw free failed\n");
err = ret;
}
@@ -277,7 +276,6 @@ static int sof_pcm_prepare(struct snd_soc_component *component,
struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
- struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
struct snd_sof_pcm *spcm;
int ret;
@@ -285,21 +283,22 @@ static int sof_pcm_prepare(struct snd_soc_component *component,
if (rtd->dai_link->no_pcm)
return 0;
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm)
return -EINVAL;
if (spcm->prepared[substream->stream])
return 0;
- dev_dbg(sdev->dev, "pcm: prepare stream %d dir %d\n", spcm->pcm.pcm_id,
- substream->stream);
+ dev_dbg(component->dev, "pcm: prepare stream %d dir %d\n",
+ spcm->pcm.pcm_id, substream->stream);
/* set hw_params */
ret = sof_pcm_hw_params(component,
substream, &spcm->params[substream->stream]);
if (ret < 0) {
- dev_err(sdev->dev, "error: set pcm hw_params after resume\n");
+ dev_err(component->dev,
+ "error: set pcm hw_params after resume\n");
return ret;
}
@@ -326,11 +325,11 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
if (rtd->dai_link->no_pcm)
return 0;
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm)
return -EINVAL;
- dev_dbg(sdev->dev, "pcm: trigger stream %d dir %d cmd %d\n",
+ dev_dbg(component->dev, "pcm: trigger stream %d dir %d cmd %d\n",
spcm->pcm.pcm_id, substream->stream, cmd);
stream.hdr.size = sizeof(stream);
@@ -359,7 +358,7 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
/* set up hw_params */
ret = sof_pcm_prepare(component, substream);
if (ret < 0) {
- dev_err(sdev->dev,
+ dev_err(component->dev,
"error: failed to set up hw_params upon resume\n");
return ret;
}
@@ -396,7 +395,8 @@ static int sof_pcm_trigger(struct snd_soc_component *component,
reset_hw_params = true;
break;
default:
- dev_err(sdev->dev, "error: unhandled trigger cmd %d\n", cmd);
+ dev_err(component->dev, "error: unhandled trigger cmd %d\n",
+ cmd);
return -EINVAL;
}
@@ -438,7 +438,7 @@ static snd_pcm_uframes_t sof_pcm_pointer(struct snd_soc_component *component,
if (sof_ops(sdev)->pcm_pointer)
return sof_ops(sdev)->pcm_pointer(sdev, substream);
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm)
return -EINVAL;
@@ -448,7 +448,8 @@ static snd_pcm_uframes_t sof_pcm_pointer(struct snd_soc_component *component,
dai = bytes_to_frames(substream->runtime,
spcm->stream[substream->stream].posn.dai_posn);
- dev_dbg(sdev->dev, "PCM: stream %d dir %d DMA position %lu DAI position %lu\n",
+ dev_dbg(component->dev,
+ "PCM: stream %d dir %d DMA position %lu DAI position %lu\n",
spcm->pcm.pcm_id, substream->stream, host, dai);
return host;
@@ -469,12 +470,12 @@ static int sof_pcm_open(struct snd_soc_component *component,
if (rtd->dai_link->no_pcm)
return 0;
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm)
return -EINVAL;
- dev_dbg(sdev->dev, "pcm: open stream %d dir %d\n", spcm->pcm.pcm_id,
- substream->stream);
+ dev_dbg(component->dev, "pcm: open stream %d dir %d\n",
+ spcm->pcm.pcm_id, substream->stream);
INIT_WORK(&spcm->stream[substream->stream].period_elapsed_work,
sof_pcm_period_elapsed_work);
@@ -504,13 +505,13 @@ static int sof_pcm_open(struct snd_soc_component *component,
*/
runtime->hw.buffer_bytes_max = le32_to_cpu(caps->buffer_size_max);
- dev_dbg(sdev->dev, "period min %zd max %zd bytes\n",
+ dev_dbg(component->dev, "period min %zd max %zd bytes\n",
runtime->hw.period_bytes_min,
runtime->hw.period_bytes_max);
- dev_dbg(sdev->dev, "period count %d max %d\n",
+ dev_dbg(component->dev, "period count %d max %d\n",
runtime->hw.periods_min,
runtime->hw.periods_max);
- dev_dbg(sdev->dev, "buffer max %zd bytes\n",
+ dev_dbg(component->dev, "buffer max %zd bytes\n",
runtime->hw.buffer_bytes_max);
/* set wait time - TODO: come from topology */
@@ -523,7 +524,7 @@ static int sof_pcm_open(struct snd_soc_component *component,
ret = snd_sof_pcm_platform_open(sdev, substream);
if (ret < 0)
- dev_err(sdev->dev, "error: pcm open failed %d\n", ret);
+ dev_err(component->dev, "error: pcm open failed %d\n", ret);
return ret;
}
@@ -540,16 +541,16 @@ static int sof_pcm_close(struct snd_soc_component *component,
if (rtd->dai_link->no_pcm)
return 0;
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm)
return -EINVAL;
- dev_dbg(sdev->dev, "pcm: close stream %d dir %d\n", spcm->pcm.pcm_id,
- substream->stream);
+ dev_dbg(component->dev, "pcm: close stream %d dir %d\n",
+ spcm->pcm.pcm_id, substream->stream);
err = snd_sof_pcm_platform_close(sdev, substream);
if (err < 0) {
- dev_err(sdev->dev, "error: pcm close failed %d\n",
+ dev_err(component->dev, "error: pcm close failed %d\n",
err);
/*
* keep going, no point in preventing the close
@@ -575,14 +576,14 @@ static int sof_pcm_new(struct snd_soc_component *component,
int stream = SNDRV_PCM_STREAM_PLAYBACK;
/* find SOF PCM for this RTD */
- spcm = snd_sof_find_spcm_dai(sdev, rtd);
+ spcm = snd_sof_find_spcm_dai(component, rtd);
if (!spcm) {
- dev_warn(sdev->dev, "warn: can't find PCM with DAI ID %d\n",
+ dev_warn(component->dev, "warn: can't find PCM with DAI ID %d\n",
rtd->dai_link->id);
return 0;
}
- dev_dbg(sdev->dev, "creating new PCM %s\n", spcm->pcm.pcm_name);
+ dev_dbg(component->dev, "creating new PCM %s\n", spcm->pcm.pcm_name);
/* do we need to pre-allocate playback audio buffer pages */
if (!spcm->pcm.playback)
@@ -591,7 +592,8 @@ static int sof_pcm_new(struct snd_soc_component *component,
caps = &spcm->pcm.caps[stream];
/* pre-allocate playback audio buffer pages */
- dev_dbg(sdev->dev, "spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n",
+ dev_dbg(component->dev,
+ "spcm: allocate %s playback DMA buffer size 0x%x max 0x%x\n",
caps->name, caps->buffer_size_min, caps->buffer_size_max);
snd_pcm_lib_preallocate_pages(pcm->streams[stream].substream,
@@ -608,7 +610,8 @@ capture:
caps = &spcm->pcm.caps[stream];
/* pre-allocate capture audio buffer pages */
- dev_dbg(sdev->dev, "spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",
+ dev_dbg(component->dev,
+ "spcm: allocate %s capture DMA buffer size 0x%x max 0x%x\n",
caps->name, caps->buffer_size_min, caps->buffer_size_max);
snd_pcm_lib_preallocate_pages(pcm->streams[stream].substream,
@@ -629,14 +632,14 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
SNDRV_PCM_HW_PARAM_CHANNELS);
struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
struct snd_soc_component *component =
- snd_soc_rtdcom_lookup(rtd, DRV_NAME);
- struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
+ snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
struct snd_sof_dai *dai =
- snd_sof_find_dai(sdev, (char *)rtd->dai_link->name);
+ snd_sof_find_dai(component, (char *)rtd->dai_link->name);
/* no topology exists for this BE, try a common configuration */
if (!dai) {
- dev_warn(sdev->dev, "warning: no topology found for BE DAI %s config\n",
+ dev_warn(component->dev,
+ "warning: no topology found for BE DAI %s config\n",
rtd->dai_link->name);
/* set 48k, stereo, 16bits by default */
@@ -666,7 +669,7 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
break;
default:
- dev_err(sdev->dev, "error: No available DAI format!\n");
+ dev_err(component->dev, "error: No available DAI format!\n");
return -EINVAL;
}
@@ -678,9 +681,9 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
channels->min = dai->dai_config->ssp.tdm_slots;
channels->max = dai->dai_config->ssp.tdm_slots;
- dev_dbg(sdev->dev,
+ dev_dbg(component->dev,
"rate_min: %d rate_max: %d\n", rate->min, rate->max);
- dev_dbg(sdev->dev,
+ dev_dbg(component->dev,
"channels_min: %d channels_max: %d\n",
channels->min, channels->max);
@@ -688,7 +691,7 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
case SOF_DAI_INTEL_DMIC:
/* DMIC only supports 16 or 32 bit formats */
if (dai->comp_dai.config.frame_fmt == SOF_IPC_FRAME_S24_4LE) {
- dev_err(sdev->dev,
+ dev_err(component->dev,
"error: invalid fmt %d for DAI type %d\n",
dai->comp_dai.config.frame_fmt,
dai->dai_config->type);
@@ -704,12 +707,12 @@ static int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
channels->min = dai->dai_config->esai.tdm_slots;
channels->max = dai->dai_config->esai.tdm_slots;
- dev_dbg(sdev->dev,
+ dev_dbg(component->dev,
"channels_min: %d channels_max: %d\n",
channels->min, channels->max);
break;
default:
- dev_err(sdev->dev, "error: invalid DAI type %d\n",
+ dev_err(component->dev, "error: invalid DAI type %d\n",
dai->dai_config->type);
break;
}
@@ -734,9 +737,9 @@ static int sof_pcm_probe(struct snd_soc_component *component)
if (!tplg_filename)
return -ENOMEM;
- ret = snd_sof_load_topology(sdev, tplg_filename);
+ ret = snd_sof_load_topology(component, tplg_filename);
if (ret < 0) {
- dev_err(sdev->dev, "error: failed to load DSP topology %d\n",
+ dev_err(component->dev, "error: failed to load DSP topology %d\n",
ret);
return ret;
}