ASoC: SOF: compress: Add support for timestamp on capture

Merge series from Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>:

The purpose of this patch series is to add support for
timestamping on capture direction using the compress
API.

This is simply done by splitting sof_compr_copy into 2
functions: sof_compr_copy_playback and sof_compr_copy_capture.
Each of these functions handles one of the possible directions:
capture or playback and is called in sof_compr_copy based on
the stream's direction.

The only difference between sof_compr_copy_playback and
sof_compr_copy_capture is the fact that on playback case
we need to copy data from user space and on capture we
need to copy data to user space.
This commit is contained in:
Mark Brown 2022-08-31 13:40:16 +01:00
commit ce963f84a8
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View File

@ -297,18 +297,13 @@ static int sof_compr_trigger(struct snd_soc_component *component,
&reply, sizeof(reply)); &reply, sizeof(reply));
} }
static int sof_compr_copy(struct snd_soc_component *component, static int sof_compr_copy_playback(struct snd_compr_runtime *rtd,
struct snd_compr_stream *cstream, char __user *buf, size_t count)
char __user *buf, size_t count)
{ {
struct snd_compr_runtime *rtd = cstream->runtime;
unsigned int offset, n;
void *ptr; void *ptr;
unsigned int offset, n;
int ret; int ret;
if (count > rtd->buffer_size)
count = rtd->buffer_size;
div_u64_rem(rtd->total_bytes_available, rtd->buffer_size, &offset); div_u64_rem(rtd->total_bytes_available, rtd->buffer_size, &offset);
ptr = rtd->dma_area + offset; ptr = rtd->dma_area + offset;
n = rtd->buffer_size - offset; n = rtd->buffer_size - offset;
@ -323,6 +318,42 @@ static int sof_compr_copy(struct snd_soc_component *component,
return count - ret; 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)
{
struct snd_compr_runtime *rtd = cstream->runtime;
if (count > rtd->buffer_size)
count = rtd->buffer_size;
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, static int sof_compr_pointer(struct snd_soc_component *component,
struct snd_compr_stream *cstream, struct snd_compr_stream *cstream,
struct snd_compr_tstamp *tstamp) struct snd_compr_tstamp *tstamp)