[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220822101502.17644-3-laurentiu.mihalcea@nxp.com>
Date: Mon, 22 Aug 2022 13:15:02 +0300
From: Laurentiu Mihalcea <laurentiu.mihalcea@....com>
To: alsa-devel@...a-project.org, broonie@...nel.org
Cc: pierre-louis.bossart@...ux.intel.com, lgirdwood@...il.com,
peter.ujfalusi@...ux.intel.com, ranjani.sridharan@...ux.intel.com,
yung-chuan.liao@...ux.intel.com, kai.vehmanen@...ux.intel.com,
linux-kernel@...r.kernel.org,
Laurentiu Mihalcea <laurentiu.mihalcea@....com>,
Paul Olaru <paul.olaru@....com>,
Daniel Baluta <daniel.baluta@....com>
Subject: [PATCH 2/2] 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@....com>
Reviewed-by: Daniel Baluta <daniel.baluta@....com>
Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@....com>
---
sound/soc/sof/compress.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/sound/soc/sof/compress.c b/sound/soc/sof/compress.c
index 1b0b8b43723b..81202e4b7cb9 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,
--
2.34.1
Powered by blists - more mailing lists