mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 12:21:22 -05:00
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 <chancel.liu@nxp.com> Link: https://patch.msgid.link/20250421105701.2273588-2-chancel.liu@nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user