]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ASoC: mediatek: use reserved memory or enable buffer pre-allocation
authorChen-Yu Tsai <wenst@chromium.org>
Thu, 12 Jun 2025 07:48:57 +0000 (15:48 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 10:08:41 +0000 (12:08 +0200)
[ Upstream commit ec4a10ca4a68ec97f12f4d17d7abb74db34987db ]

In commit 32c9c06adb5b ("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: 32c9c06adb5b ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/soc/mediatek/common/mtk-afe-platform-driver.c
sound/soc/mediatek/common/mtk-base-afe.h
sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
sound/soc/mediatek/mt8192/mt8192-afe-pcm.c

index 52495c930ca3bfae782f7d02160172283948bb3f..56a704ec2ea947143433265d70f3623fe1f667b6 100644 (file)
@@ -120,7 +120,9 @@ int mtk_afe_pcm_new(struct snd_soc_component *component,
        struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
 
        size = afe->mtk_afe_hardware->buffer_bytes_max;
-       snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev, 0, size);
+       snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev,
+                                      afe->preallocate_buffers ? size : 0,
+                                      size);
 
        return 0;
 }
index f51578b6c50a3567f0b1009403162681d312f8b4..a406f2e3e7a8786984ad89f4b1402d402a4e2923 100644 (file)
@@ -117,6 +117,7 @@ struct mtk_base_afe {
        struct mtk_base_afe_irq *irqs;
        int irqs_size;
        int memif_32bit_supported;
+       bool preallocate_buffers;
 
        struct list_head sub_dais;
        struct snd_soc_dai_driver *dai_drivers;
index 06269f7e37566b5e64ff6a7831566ae817861588..240b2f041a3f8b3ff9ce5a0f6f1233a2b5f9cdb8 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/dma-mapping.h>
 #include <linux/pm_runtime.h>
 #include <sound/soc.h>
@@ -1070,6 +1071,12 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
 
        afe->dev = &pdev->dev;
 
+       ret = of_reserved_mem_device_init(&pdev->dev);
+       if (ret) {
+               dev_info(&pdev->dev, "no reserved memory found, pre-allocating buffers instead\n");
+               afe->preallocate_buffers = true;
+       }
+
        irq_id = platform_get_irq(pdev, 0);
        if (irq_id <= 0)
                return irq_id < 0 ? irq_id : -ENXIO;
index 90422ed2bbcc2709138058d4ca5908c7a0da6bed..cbee5a8764c37f5c8fbd14e3ee69632ddac2be47 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/pm_runtime.h>
 #include <linux/reset.h>
 
@@ -1106,6 +1107,12 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
        afe->dev = &pdev->dev;
        dev = afe->dev;
 
+       ret = of_reserved_mem_device_init(dev);
+       if (ret) {
+               dev_info(dev, "no reserved memory found, pre-allocating buffers instead\n");
+               afe->preallocate_buffers = true;
+       }
+
        /* initial audio related clock */
        ret = mt8183_init_clock(afe);
        if (ret) {
index b86159f70a33a2b18b4c4867584c617d579d8963..9ee431304a431bb5d1b01cd00a824d8d03dbc187 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/pm_runtime.h>
 #include <linux/reset.h>
 #include <sound/soc.h>
@@ -2835,6 +2836,12 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
        afe_priv = afe->platform_priv;
        afe->dev = &pdev->dev;
 
+       ret = of_reserved_mem_device_init(dev);
+       if (ret) {
+               dev_info(dev, "no reserved memory found, pre-allocating buffers instead\n");
+               afe->preallocate_buffers = true;
+       }
+
        afe->base_addr = devm_platform_ioremap_resource(pdev, 0);
        if (IS_ERR(afe->base_addr))
                return PTR_ERR(afe->base_addr);
index d0520e7e1d79aed065fcd592c20481be6a8db747..364e43da0e2416561e2e0e48f4c68dd8a8dc6dd3 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/mfd/syscon.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/pm_runtime.h>
 #include <linux/reset.h>
 #include <sound/soc.h>
@@ -2196,6 +2197,12 @@ static int mt8192_afe_pcm_dev_probe(struct platform_device *pdev)
        afe->dev = &pdev->dev;
        dev = afe->dev;
 
+       ret = of_reserved_mem_device_init(dev);
+       if (ret) {
+               dev_info(dev, "no reserved memory found, pre-allocating buffers instead\n");
+               afe->preallocate_buffers = true;
+       }
+
        /* init audio related clock */
        ret = mt8192_init_clock(afe);
        if (ret) {