Skip to content

Commit 2056d7a

Browse files
Chancel Liubroonie
authored andcommitted
ASoC: fsl_rpmsg: Allocate a smaller buffer size for capture stream
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 17fa55f commit 2056d7a

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

sound/soc/fsl/fsl_rpmsg.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
/* 192kHz/32bit/2ch/60s size is 0x574e00 */
2626
#define LPA_LARGE_BUFFER_SIZE (0x6000000)
27+
/* 16kHz/32bit/8ch/1s size is 0x7D000 */
28+
#define LPA_CAPTURE_BUFFER_SIZE (0x100000)
2729

2830
static const unsigned int fsl_rpmsg_rates[] = {
2931
8000, 11025, 16000, 22050, 44100,
@@ -241,9 +243,11 @@ static int fsl_rpmsg_probe(struct platform_device *pdev)
241243

242244
if (of_property_read_bool(np, "fsl,enable-lpa")) {
243245
rpmsg->enable_lpa = 1;
244-
rpmsg->buffer_size = LPA_LARGE_BUFFER_SIZE;
246+
rpmsg->buffer_size[SNDRV_PCM_STREAM_PLAYBACK] = LPA_LARGE_BUFFER_SIZE;
247+
rpmsg->buffer_size[SNDRV_PCM_STREAM_CAPTURE] = LPA_CAPTURE_BUFFER_SIZE;
245248
} else {
246-
rpmsg->buffer_size = IMX_DEFAULT_DMABUF_SIZE;
249+
rpmsg->buffer_size[SNDRV_PCM_STREAM_PLAYBACK] = IMX_DEFAULT_DMABUF_SIZE;
250+
rpmsg->buffer_size[SNDRV_PCM_STREAM_CAPTURE] = IMX_DEFAULT_DMABUF_SIZE;
247251
}
248252

249253
/* Get the optional clocks */

sound/soc/fsl/fsl_rpmsg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ struct fsl_rpmsg {
4242
unsigned int mclk_streams;
4343
int force_lpa;
4444
int enable_lpa;
45-
int buffer_size;
45+
int buffer_size[2];
4646
};
4747
#endif /* __FSL_RPMSG_H */

sound/soc/fsl/imx-pcm-rpmsg.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static int imx_rpmsg_pcm_open(struct snd_soc_component *component,
261261
info->send_message(msg, info);
262262

263263
pcm_hardware = imx_rpmsg_pcm_hardware;
264-
pcm_hardware.buffer_bytes_max = rpmsg->buffer_size;
264+
pcm_hardware.buffer_bytes_max = rpmsg->buffer_size[substream->stream];
265265
pcm_hardware.period_bytes_max = pcm_hardware.buffer_bytes_max / 2;
266266

267267
snd_soc_set_runtime_hwparams(substream, &pcm_hardware);
@@ -597,14 +597,29 @@ static int imx_rpmsg_pcm_new(struct snd_soc_component *component,
597597
struct snd_pcm *pcm = rtd->pcm;
598598
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
599599
struct fsl_rpmsg *rpmsg = dev_get_drvdata(cpu_dai->dev);
600+
struct snd_pcm_substream *substream;
600601
int ret;
601602

602603
ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
603604
if (ret)
604605
return ret;
605606

606-
return snd_pcm_set_fixed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_WC,
607-
pcm->card->dev, rpmsg->buffer_size);
607+
substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
608+
if (substream) {
609+
ret = snd_pcm_set_fixed_buffer(substream, SNDRV_DMA_TYPE_DEV_WC, pcm->card->dev,
610+
rpmsg->buffer_size[SNDRV_PCM_STREAM_PLAYBACK]);
611+
if (ret < 0)
612+
return ret;
613+
}
614+
substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
615+
if (substream) {
616+
ret = snd_pcm_set_fixed_buffer(substream, SNDRV_DMA_TYPE_DEV_WC, pcm->card->dev,
617+
rpmsg->buffer_size[SNDRV_PCM_STREAM_CAPTURE]);
618+
if (ret < 0)
619+
return ret;
620+
}
621+
622+
return ret;
608623
}
609624

610625
static const struct snd_soc_component_driver imx_rpmsg_soc_component = {

0 commit comments

Comments
 (0)