Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: SOF: Add support for compress API for stream data/offset

snd_sof_pcm_stream keeps information about both PCM (snd_pcm_substream)
and Compress (snd_compr_stream) streams.

When PCM substream pointer is NULL this means we are dealing with a
compress stream.

Reviewed-by: Paul Olaru <paul.olaru@nxp.com>
Reviewed-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Link: https://lore.kernel.org/r/20230117122533.201708-4-daniel.baluta@oss.nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Daniel Baluta and committed by
Mark Brown
090349a9 249f186d

+37 -12
+1
sound/soc/sof/sof-priv.h
··· 115 115 u32 sampling_rate; 116 116 u16 channels; 117 117 u16 sample_container_bytes; 118 + size_t posn_offset; 118 119 }; 119 120 120 121 struct snd_sof_dev;
+36 -12
sound/soc/sof/stream-ipc.c
··· 33 33 if (!sps || !sdev->stream_box.size) { 34 34 snd_sof_dsp_mailbox_read(sdev, sdev->dsp_box.offset, p, sz); 35 35 } else { 36 - struct snd_pcm_substream *substream = sps->substream; 37 - struct sof_stream *stream = substream->runtime->private_data; 36 + size_t posn_offset; 38 37 39 - /* The stream might already be closed */ 40 - if (!stream) 41 - return -ESTRPIPE; 38 + if (sps->substream) { 39 + struct sof_stream *stream = sps->substream->runtime->private_data; 42 40 43 - snd_sof_dsp_mailbox_read(sdev, stream->posn_offset, p, sz); 41 + /* The stream might already be closed */ 42 + if (!stream) 43 + return -ESTRPIPE; 44 + 45 + posn_offset = stream->posn_offset; 46 + } else { 47 + 48 + struct sof_compr_stream *sstream = sps->cstream->runtime->private_data; 49 + 50 + if (!sstream) 51 + return -ESTRPIPE; 52 + 53 + posn_offset = sstream->posn_offset; 54 + } 55 + 56 + snd_sof_dsp_mailbox_read(sdev, posn_offset, p, sz); 44 57 } 45 58 46 59 return 0; ··· 64 51 struct snd_sof_pcm_stream *sps, 65 52 size_t posn_offset) 66 53 { 67 - struct snd_pcm_substream *substream = sps->substream; 68 - struct sof_stream *stream = substream->runtime->private_data; 69 - 70 54 /* check if offset is overflow or it is not aligned */ 71 55 if (posn_offset > sdev->stream_box.size || 72 56 posn_offset % sizeof(struct sof_ipc_stream_posn) != 0) 73 57 return -EINVAL; 74 58 75 - stream->posn_offset = sdev->stream_box.offset + posn_offset; 59 + posn_offset += sdev->stream_box.offset; 76 60 77 - dev_dbg(sdev->dev, "pcm: stream dir %d, posn mailbox offset is %zu", 78 - substream->stream, stream->posn_offset); 61 + if (sps->substream) { 62 + struct sof_stream *stream = sps->substream->runtime->private_data; 63 + 64 + stream->posn_offset = posn_offset; 65 + dev_dbg(sdev->dev, "pcm: stream dir %d, posn mailbox offset is %zu", 66 + sps->substream->stream, posn_offset); 67 + } else if (sps->cstream) { 68 + struct sof_compr_stream *sstream = sps->cstream->runtime->private_data; 69 + 70 + sstream->posn_offset = posn_offset; 71 + dev_dbg(sdev->dev, "compr: stream dir %d, posn mailbox offset is %zu", 72 + sps->cstream->direction, posn_offset); 73 + } else { 74 + dev_err(sdev->dev, "No stream opened"); 75 + return -EINVAL; 76 + } 79 77 80 78 return 0; 81 79 }