mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
To: alsa-devel@alsa-project.org, broonie@kernel.org
Cc: pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com,
	peter.ujfalusi@linux.intel.com,
	ranjani.sridharan@linux.intel.com,
	yung-chuan.liao@linux.intel.com, kai.vehmanen@linux.intel.com,
	linux-kernel@vger.kernel.org,
	Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>,
	Paul Olaru <paul.olaru@nxp.com>,
	Daniel Baluta <daniel.baluta@nxp.com>
Subject: [PATCH 2/2] ASoC: SOF: compress: Add copy function for capture case
Date: Mon, 22 Aug 2022 13:15:02 +0300	[thread overview]
Message-ID: <20220822101502.17644-3-laurentiu.mihalcea@nxp.com> (raw)
In-Reply-To: <20220822101502.17644-1-laurentiu.mihalcea@nxp.com>

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>
---
 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


  parent reply	other threads:[~2022-08-22 10:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-22 10:15 [PATCH 0/2] ASoC: SOF: compress: Add support for timestamp on capture Laurentiu Mihalcea
2022-08-22 10:15 ` [PATCH 1/2] ASoC: SOF: compress: Move sof_compr_copy functionality Laurentiu Mihalcea
2022-08-22 10:15 ` Laurentiu Mihalcea [this message]
2022-08-31 12:52 ` [PATCH 0/2] ASoC: SOF: compress: Add support for timestamp on capture Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220822101502.17644-3-laurentiu.mihalcea@nxp.com \
    --to=laurentiu.mihalcea@nxp.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=daniel.baluta@nxp.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul.olaru@nxp.com \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®