Skip to content

Commit ec4a10c

Browse files
wensbroonie
authored andcommitted
ASoC: mediatek: use reserved memory or enable buffer pre-allocation
In commit 32c9c06 ("ASoC: mediatek: disable buffer pre-allocation") buffer pre-allocation was disabled to accommodate newer platforms that have a limited reserved memory region for the audio frontend. Turns out disabling pre-allocation across the board impacts platforms that don't have this reserved memory region. Buffer allocation failures have been observed on MT8173 and MT8183 based Chromebooks under low memory conditions, which results in no audio playback for the user. Since some MediaTek platforms already have dedicated reserved memory pools for the audio frontend, the plan is to enable this for all of them. This requires device tree changes. As a fallback, reinstate the original policy of pre-allocating audio buffers at probe time of the reserved memory pool cannot be found or used. This patch covers the MT8173, MT8183, MT8186 and MT8192 platforms for now, the reason being that existing MediaTek platform drivers that supported reserved memory were all platforms that mainly supported ChromeOS, and is also the set of devices that I can verify. Fixes: 32c9c06 ("ASoC: mediatek: disable buffer pre-allocation") Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> Link: https://patch.msgid.link/20250612074901.4023253-7-wenst@chromium.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent cd12d3a commit ec4a10c

6 files changed

Lines changed: 32 additions & 1 deletion

File tree

sound/soc/mediatek/common/mtk-afe-platform-driver.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ int mtk_afe_pcm_new(struct snd_soc_component *component,
120120
struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
121121

122122
size = afe->mtk_afe_hardware->buffer_bytes_max;
123-
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev, 0, size);
123+
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev,
124+
afe->preallocate_buffers ? size : 0,
125+
size);
124126

125127
return 0;
126128
}

sound/soc/mediatek/common/mtk-base-afe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct mtk_base_afe {
117117
struct mtk_base_afe_irq *irqs;
118118
int irqs_size;
119119
int memif_32bit_supported;
120+
bool preallocate_buffers;
120121

121122
struct list_head sub_dais;
122123
struct snd_soc_dai_driver *dai_drivers;

sound/soc/mediatek/mt8173/mt8173-afe-pcm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/module.h>
1414
#include <linux/of.h>
1515
#include <linux/of_address.h>
16+
#include <linux/of_reserved_mem.h>
1617
#include <linux/dma-mapping.h>
1718
#include <linux/pm_runtime.h>
1819
#include <sound/soc.h>
@@ -1070,6 +1071,12 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
10701071

10711072
afe->dev = &pdev->dev;
10721073

1074+
ret = of_reserved_mem_device_init(&pdev->dev);
1075+
if (ret) {
1076+
dev_info(&pdev->dev, "no reserved memory found, pre-allocating buffers instead\n");
1077+
afe->preallocate_buffers = true;
1078+
}
1079+
10731080
irq_id = platform_get_irq(pdev, 0);
10741081
if (irq_id <= 0)
10751082
return irq_id < 0 ? irq_id : -ENXIO;

sound/soc/mediatek/mt8183/mt8183-afe-pcm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/mfd/syscon.h>
1111
#include <linux/of.h>
1212
#include <linux/of_address.h>
13+
#include <linux/of_reserved_mem.h>
1314
#include <linux/pm_runtime.h>
1415
#include <linux/reset.h>
1516

@@ -777,6 +778,12 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
777778
afe->dev = &pdev->dev;
778779
dev = afe->dev;
779780

781+
ret = of_reserved_mem_device_init(dev);
782+
if (ret) {
783+
dev_info(dev, "no reserved memory found, pre-allocating buffers instead\n");
784+
afe->preallocate_buffers = true;
785+
}
786+
780787
/* initial audio related clock */
781788
ret = mt8183_init_clock(afe);
782789
if (ret) {

sound/soc/mediatek/mt8186/mt8186-afe-pcm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/module.h>
1111
#include <linux/of.h>
1212
#include <linux/of_address.h>
13+
#include <linux/of_reserved_mem.h>
1314
#include <linux/pm_runtime.h>
1415
#include <linux/reset.h>
1516
#include <sound/soc.h>
@@ -2835,6 +2836,12 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
28352836
afe_priv = afe->platform_priv;
28362837
afe->dev = &pdev->dev;
28372838

2839+
ret = of_reserved_mem_device_init(dev);
2840+
if (ret) {
2841+
dev_info(dev, "no reserved memory found, pre-allocating buffers instead\n");
2842+
afe->preallocate_buffers = true;
2843+
}
2844+
28382845
afe->base_addr = devm_platform_ioremap_resource(pdev, 0);
28392846
if (IS_ERR(afe->base_addr))
28402847
return PTR_ERR(afe->base_addr);

sound/soc/mediatek/mt8192/mt8192-afe-pcm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/mfd/syscon.h>
1313
#include <linux/of.h>
1414
#include <linux/of_address.h>
15+
#include <linux/of_reserved_mem.h>
1516
#include <linux/pm_runtime.h>
1617
#include <linux/reset.h>
1718
#include <sound/soc.h>
@@ -2179,6 +2180,12 @@ static int mt8192_afe_pcm_dev_probe(struct platform_device *pdev)
21792180

21802181
afe->dev = dev;
21812182

2183+
ret = of_reserved_mem_device_init(dev);
2184+
if (ret) {
2185+
dev_info(dev, "no reserved memory found, pre-allocating buffers instead\n");
2186+
afe->preallocate_buffers = true;
2187+
}
2188+
21822189
/* init audio related clock */
21832190
ret = mt8192_init_clock(afe);
21842191
if (ret) {

0 commit comments

Comments
 (0)