]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ASoC: fsl_rpmsg: Allocate a smaller buffer size for capture stream
authorChancel Liu <chancel.liu@nxp.com>
Mon, 21 Apr 2025 10:57:01 +0000 (19:57 +0900)
committerMark Brown <broonie@kernel.org>
Thu, 1 May 2025 20:38:54 +0000 (05:38 +0900)
If both playback and capture streams have large buffer size in low power
audio case, the total size will exceed the maximum buffer size for this
sound card.

Capture stream doesn't need so large buffer size in fact. So calculate
a reasonable smaller buffer size and allocate it for capture stream.

Signed-off-by: Chancel Liu <chancel.liu@nxp.com>
Link: https://patch.msgid.link/20250421105701.2273588-2-chancel.liu@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/fsl/fsl_rpmsg.c
sound/soc/fsl/fsl_rpmsg.h
sound/soc/fsl/imx-pcm-rpmsg.c

index 4e3ca05bedd6e43a638e1f861b584d7c6105daa3..5708b3a9878dc03de02fc69356fc0fff0113ca0c 100644 (file)
@@ -24,6 +24,8 @@
 
 /* 192kHz/32bit/2ch/60s size is 0x574e00 */
 #define LPA_LARGE_BUFFER_SIZE  (0x6000000)
+/* 16kHz/32bit/8ch/1s size is 0x7D000 */
+#define LPA_CAPTURE_BUFFER_SIZE (0x100000)
 
 static const unsigned int fsl_rpmsg_rates[] = {
        8000, 11025, 16000, 22050, 44100,
@@ -241,9 +243,11 @@ static int fsl_rpmsg_probe(struct platform_device *pdev)
 
        if (of_property_read_bool(np, "fsl,enable-lpa")) {
                rpmsg->enable_lpa = 1;
-               rpmsg->buffer_size = LPA_LARGE_BUFFER_SIZE;
+               rpmsg->buffer_size[SNDRV_PCM_STREAM_PLAYBACK] = LPA_LARGE_BUFFER_SIZE;
+               rpmsg->buffer_size[SNDRV_PCM_STREAM_CAPTURE] = LPA_CAPTURE_BUFFER_SIZE;
        } else {
-               rpmsg->buffer_size = IMX_DEFAULT_DMABUF_SIZE;
+               rpmsg->buffer_size[SNDRV_PCM_STREAM_PLAYBACK] = IMX_DEFAULT_DMABUF_SIZE;
+               rpmsg->buffer_size[SNDRV_PCM_STREAM_CAPTURE] = IMX_DEFAULT_DMABUF_SIZE;
        }
 
        /* Get the optional clocks */
index b04086fbf82838fa69435475ac0b896fd7658915..1b16838085074d5bf7cacf410e4a95e579cdab96 100644 (file)
@@ -42,6 +42,6 @@ struct fsl_rpmsg {
        unsigned int mclk_streams;
        int force_lpa;
        int enable_lpa;
-       int buffer_size;
+       int buffer_size[2];
 };
 #endif /* __FSL_RPMSG_H */
index de5f87600fac2cf101f85919e8f9fba29d9fb488..8ed62d43ffd5e340c36e13e00cb62965104f3802 100644 (file)
@@ -261,7 +261,7 @@ static int imx_rpmsg_pcm_open(struct snd_soc_component *component,
        info->send_message(msg, info);
 
        pcm_hardware = imx_rpmsg_pcm_hardware;
-       pcm_hardware.buffer_bytes_max = rpmsg->buffer_size;
+       pcm_hardware.buffer_bytes_max = rpmsg->buffer_size[substream->stream];
        pcm_hardware.period_bytes_max = pcm_hardware.buffer_bytes_max / 2;
 
        snd_soc_set_runtime_hwparams(substream, &pcm_hardware);
@@ -597,14 +597,29 @@ static int imx_rpmsg_pcm_new(struct snd_soc_component *component,
        struct snd_pcm *pcm = rtd->pcm;
        struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
        struct fsl_rpmsg *rpmsg = dev_get_drvdata(cpu_dai->dev);
+       struct snd_pcm_substream *substream;
        int ret;
 
        ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
        if (ret)
                return ret;
 
-       return snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_WC,
-                                           pcm->card->dev, rpmsg->buffer_size);
+       substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
+       if (substream) {
+               ret = snd_pcm_set_fixed_buffer(substream, SNDRV_DMA_TYPE_DEV_WC, pcm->card->dev,
+                                              rpmsg->buffer_size[SNDRV_PCM_STREAM_PLAYBACK]);
+               if (ret < 0)
+                       return ret;
+       }
+       substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
+       if (substream) {
+               ret = snd_pcm_set_fixed_buffer(substream, SNDRV_DMA_TYPE_DEV_WC, pcm->card->dev,
+                                              rpmsg->buffer_size[SNDRV_PCM_STREAM_CAPTURE]);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return ret;
 }
 
 static const struct snd_soc_component_driver imx_rpmsg_soc_component = {