aboutsummaryrefslogtreecommitdiff
path: root/sound/soc/sof/compress.c
diff options
context:
space:
mode:
authorLaurentiu Mihalcea <laurentiu.mihalcea@nxp.com>2022-08-22 13:15:02 +0300
committerMark Brown <broonie@kernel.org>2022-08-31 12:12:59 +0100
commit1a01e19278022cd2f7daa7a065ed47c5022dbad9 (patch)
treebe192525d8eff4b79ae350ed5d9b75da092504a3 /sound/soc/sof/compress.c
parent272ff8828f35658aace17e3227624fbbd68a6bcf (diff)
ASoC: SOF: compress: Add copy function for capture case
Added a new copy function used to copy data to user buffer in the case of compress capture. Reviewed-by: Paul Olaru <paul.olaru@nxp.com> Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com> Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com> Link: https://lore.kernel.org/r/20220822101502.17644-3-laurentiu.mihalcea@nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/sof/compress.c')
-rw-r--r--sound/soc/sof/compress.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/sound/soc/sof/compress.c b/sound/soc/sof/compress.c
index 2ee81096bec5..8e1a9ba111ad 100644
--- a/sound/soc/sof/compress.c
+++ b/sound/soc/sof/compress.c
@@ -318,6 +318,27 @@ static int sof_compr_copy_playback(struct snd_compr_runtime *rtd,
return count - ret;
}
+static int sof_compr_copy_capture(struct snd_compr_runtime *rtd,
+ char __user *buf, size_t count)
+{
+ void *ptr;
+ unsigned int offset, n;
+ int ret;
+
+ div_u64_rem(rtd->total_bytes_transferred, rtd->buffer_size, &offset);
+ ptr = rtd->dma_area + offset;
+ n = rtd->buffer_size - offset;
+
+ if (count < n) {
+ ret = copy_to_user(buf, ptr, count);
+ } else {
+ ret = copy_to_user(buf, ptr, n);
+ ret += copy_to_user(buf + n, rtd->dma_area, count - n);
+ }
+
+ return count - ret;
+}
+
static int sof_compr_copy(struct snd_soc_component *component,
struct snd_compr_stream *cstream,
char __user *buf, size_t count)
@@ -327,7 +348,10 @@ static int sof_compr_copy(struct snd_soc_component *component,
if (count > rtd->buffer_size)
count = rtd->buffer_size;
- return sof_compr_copy_playback(rtd, buf, count);
+ if (cstream->direction == SND_COMPRESS_PLAYBACK)
+ return sof_compr_copy_playback(rtd, buf, count);
+ else
+ return sof_compr_copy_capture(rtd, buf, count);
}
static int sof_compr_pointer(struct snd_soc_component *component,