From 9f0fc191371843c4fc000a226b0a26b6c059aacd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 19:40:19 +0200 Subject: Merging upstream version 6.7.7. Signed-off-by: Daniel Baumann --- sound/drivers/aloop.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 4 deletions(-) (limited to 'sound/drivers') diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c index a38e602b4f..1c65e0a3b1 100644 --- a/sound/drivers/aloop.c +++ b/sound/drivers/aloop.c @@ -119,11 +119,13 @@ struct loopback_setup { unsigned int rate_shift; snd_pcm_format_t format; unsigned int rate; + snd_pcm_access_t access; unsigned int channels; struct snd_ctl_elem_id active_id; struct snd_ctl_elem_id format_id; struct snd_ctl_elem_id rate_id; struct snd_ctl_elem_id channels_id; + struct snd_ctl_elem_id access_id; }; struct loopback { @@ -158,6 +160,9 @@ struct loopback_pcm { unsigned long last_jiffies; /* If jiffies timer is used */ struct timer_list timer; + + /* size of per channel buffer in case of non-interleaved access */ + unsigned int channel_buf_n; }; static struct platform_device *devices[SNDRV_CARDS]; @@ -317,6 +322,17 @@ static int loopback_snd_timer_close_cable(struct loopback_pcm *dpcm) return 0; } +static bool is_access_interleaved(snd_pcm_access_t access) +{ + switch (access) { + case SNDRV_PCM_ACCESS_MMAP_INTERLEAVED: + case SNDRV_PCM_ACCESS_RW_INTERLEAVED: + return true; + default: + return false; + } +}; + static int loopback_check_format(struct loopback_cable *cable, int stream) { struct snd_pcm_runtime *runtime, *cruntime; @@ -335,7 +351,9 @@ static int loopback_check_format(struct loopback_cable *cable, int stream) substream->runtime; check = runtime->format != cruntime->format || runtime->rate != cruntime->rate || - runtime->channels != cruntime->channels; + runtime->channels != cruntime->channels || + is_access_interleaved(runtime->access) != + is_access_interleaved(cruntime->access); if (!check) return 0; if (stream == SNDRV_PCM_STREAM_CAPTURE) { @@ -363,6 +381,12 @@ static int loopback_check_format(struct loopback_cable *cable, int stream) &setup->channels_id); setup->channels = runtime->channels; } + if (is_access_interleaved(setup->access) != + is_access_interleaved(runtime->access)) { + snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, + &setup->access_id); + setup->access = runtime->access; + } } return 0; } @@ -472,6 +496,7 @@ static int loopback_prepare(struct snd_pcm_substream *substream) dpcm->buf_pos = 0; dpcm->pcm_buffer_size = frames_to_bytes(runtime, runtime->buffer_size); + dpcm->channel_buf_n = dpcm->pcm_buffer_size / runtime->channels; if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { /* clear capture buffer */ dpcm->silent_size = dpcm->pcm_buffer_size; @@ -522,6 +547,22 @@ static void clear_capture_buf(struct loopback_pcm *dpcm, unsigned int bytes) } } +static void copy_play_buf_part_n(struct loopback_pcm *play, struct loopback_pcm *capt, + unsigned int size, unsigned int src_off, unsigned int dst_off) +{ + unsigned int channels = capt->substream->runtime->channels; + unsigned int size_p_ch = size / channels; + unsigned int src_off_ch = src_off / channels; + unsigned int dst_off_ch = dst_off / channels; + int i; + + for (i = 0; i < channels; i++) { + memcpy(capt->substream->runtime->dma_area + capt->channel_buf_n * i + dst_off_ch, + play->substream->runtime->dma_area + play->channel_buf_n * i + src_off_ch, + size_p_ch); + } +} + static void copy_play_buf(struct loopback_pcm *play, struct loopback_pcm *capt, unsigned int bytes) @@ -556,7 +597,10 @@ static void copy_play_buf(struct loopback_pcm *play, size = play->pcm_buffer_size - src_off; if (dst_off + size > capt->pcm_buffer_size) size = capt->pcm_buffer_size - dst_off; - memcpy(dst + dst_off, src + src_off, size); + if (!is_access_interleaved(runtime->access)) + copy_play_buf_part_n(play, capt, size, src_off, dst_off); + else + memcpy(dst + dst_off, src + src_off, size); capt->silent_size = 0; bytes -= size; if (!bytes) @@ -878,7 +922,7 @@ static const struct snd_pcm_hardware loopback_pcm_hardware = { .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE | - SNDRV_PCM_INFO_RESUME), + SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_NONINTERLEAVED), .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | @@ -1495,6 +1539,29 @@ static int loopback_channels_get(struct snd_kcontrol *kcontrol, return 0; } +static int loopback_access_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + const char * const texts[] = {"Interleaved", "Non-interleaved"}; + + return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); +} + +static int loopback_access_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct loopback *loopback = snd_kcontrol_chip(kcontrol); + snd_pcm_access_t access; + + mutex_lock(&loopback->cable_lock); + access = loopback->setup[kcontrol->id.subdevice][kcontrol->id.device].access; + + ucontrol->value.enumerated.item[0] = !is_access_interleaved(access); + + mutex_unlock(&loopback->cable_lock); + return 0; +} + static const struct snd_kcontrol_new loopback_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -1541,7 +1608,15 @@ static const struct snd_kcontrol_new loopback_controls[] = { .name = "PCM Slave Channels", .info = loopback_channels_info, .get = loopback_channels_get -} +}, +#define ACCESS_IDX 6 +{ + .access = SNDRV_CTL_ELEM_ACCESS_READ, + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .name = "PCM Slave Access Mode", + .info = loopback_access_info, + .get = loopback_access_get, +}, }; static int loopback_mixer_new(struct loopback *loopback, int notify) @@ -1562,6 +1637,7 @@ static int loopback_mixer_new(struct loopback *loopback, int notify) setup->notify = notify; setup->rate_shift = NO_PITCH; setup->format = SNDRV_PCM_FORMAT_S16_LE; + setup->access = SNDRV_PCM_ACCESS_RW_INTERLEAVED; setup->rate = 48000; setup->channels = 2; for (idx = 0; idx < ARRAY_SIZE(loopback_controls); @@ -1593,6 +1669,9 @@ static int loopback_mixer_new(struct loopback *loopback, int notify) case CHANNELS_IDX: setup->channels_id = kctl->id; break; + case ACCESS_IDX: + setup->access_id = kctl->id; + break; default: break; } -- cgit v1.2.3