Commit d5770dae authored by Daniel Baluta's avatar Daniel Baluta Committed by Mark Brown

ASoC: SOF: compress: Dynamically allocate pcm params struct

We need to extend sof_ipc_pcm_parmas with additional data in order
to send compress_params to SOF FW.

The extensions will be done at runtime so we need to dynamically
allocate pcm object of type struct sof_ipc_pcm_params.
Signed-off-by: default avatarDaniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: default avatarPéter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20220712141531.14599-2-daniel.baluta@oss.nxp.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 388fe2b8
......@@ -168,7 +168,7 @@ static int sof_compr_set_params(struct snd_soc_component *component,
struct snd_compr_runtime *crtd = cstream->runtime;
struct sof_ipc_pcm_params_reply ipc_params_reply;
struct snd_compr_tstamp *tstamp;
struct sof_ipc_pcm_params pcm;
struct sof_ipc_pcm_params *pcm;
struct snd_sof_pcm *spcm;
int ret;
......@@ -179,40 +179,42 @@ static int sof_compr_set_params(struct snd_soc_component *component,
if (!spcm)
return -EINVAL;
pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
if (!pcm)
return -ENOMEM;
cstream->dma_buffer.dev.type = SNDRV_DMA_TYPE_DEV_SG;
cstream->dma_buffer.dev.dev = sdev->dev;
ret = snd_compr_malloc_pages(cstream, crtd->buffer_size);
if (ret < 0)
return ret;
goto out;
ret = create_page_table(component, cstream, crtd->dma_area, crtd->dma_bytes);
if (ret < 0)
return ret;
memset(&pcm, 0, sizeof(pcm));
pcm.params.buffer.pages = PFN_UP(crtd->dma_bytes);
pcm.hdr.size = sizeof(pcm);
pcm.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS;
pcm.comp_id = spcm->stream[cstream->direction].comp_id;
pcm.params.hdr.size = sizeof(pcm.params);
pcm.params.buffer.phy_addr = spcm->stream[cstream->direction].page_table.addr;
pcm.params.buffer.size = crtd->dma_bytes;
pcm.params.direction = cstream->direction;
pcm.params.channels = params->codec.ch_out;
pcm.params.rate = params->codec.sample_rate;
pcm.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
pcm.params.frame_fmt = SOF_IPC_FRAME_S32_LE;
pcm.params.sample_container_bytes =
goto out;
pcm->params.buffer.pages = PFN_UP(crtd->dma_bytes);
pcm->hdr.size = sizeof(*pcm);
pcm->hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS;
pcm->comp_id = spcm->stream[cstream->direction].comp_id;
pcm->params.hdr.size = sizeof(pcm->params);
pcm->params.buffer.phy_addr = spcm->stream[cstream->direction].page_table.addr;
pcm->params.buffer.size = crtd->dma_bytes;
pcm->params.direction = cstream->direction;
pcm->params.channels = params->codec.ch_out;
pcm->params.rate = params->codec.sample_rate;
pcm->params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
pcm->params.frame_fmt = SOF_IPC_FRAME_S32_LE;
pcm->params.sample_container_bytes =
snd_pcm_format_physical_width(SNDRV_PCM_FORMAT_S32) >> 3;
pcm.params.host_period_bytes = params->buffer.fragment_size;
pcm->params.host_period_bytes = params->buffer.fragment_size;
ret = sof_ipc_tx_message(sdev->ipc, &pcm, sizeof(pcm),
ret = sof_ipc_tx_message(sdev->ipc, pcm, sizeof(*pcm),
&ipc_params_reply, sizeof(ipc_params_reply));
if (ret < 0) {
dev_err(component->dev, "error ipc failed\n");
return ret;
goto out;
}
tstamp->byte_offset = sdev->stream_box.offset + ipc_params_reply.posn_offset;
......@@ -220,7 +222,10 @@ static int sof_compr_set_params(struct snd_soc_component *component,
spcm->prepared[cstream->direction] = true;
return 0;
out:
kfree(pcm);
return ret;
}
static int sof_compr_get_params(struct snd_soc_component *component,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment