From nobody Sat Oct 11 04:17:30 2025 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58B2D223339 for ; Thu, 12 Jun 2025 07:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749714574; cv=none; b=SAcikZINYZZ5rX9VMxTTw5gXNQ13TNv0K6VlCqZWh+85v3d8gEiGc9UmSn2xVTQ2kC2Wuwz+HRb3CIRtJ/ayLXgQkvUPWWMw0pBQDHg6ZbYTVDLu0/hWGYJh4Bzq4eD1J3+bJHeE7whl22F4FLHadQTGSXxmHRYdo1+eiOCvExc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749714574; c=relaxed/simple; bh=vJU0lSRgVK0wAGWmZHwdmRtL/aFRS74afRHgWTg1wKs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DPDyeaxelq4Vd2N6ENW6ML8EQXT5WzBVp/6QPs+bdSksUO7pPexYaa8jq9wc6Y7F+0oROb5UwqC98tHvAmSATOOjoei6nYZ5S5wap2Vp78Uysl6mogiacC15xLFZu710/FFgarXcW9/GeH1W+1mBBfl5ptaDMhSowM33QXmf4+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=QBlgkZQ+; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QBlgkZQ+" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-235a3dd4f0dso4407105ad.0 for ; Thu, 12 Jun 2025 00:49:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1749714572; x=1750319372; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sbtP55NCyh4Df1vJCDqUAIM6R+yyfwut8FIK3Aq64wo=; b=QBlgkZQ+0zaOvA2lNogUqQaxIwNvvJ5OOY/g+nUoaEt4NWjaLATNT+C/qJlUl8JCNy FYm06PiqHVNu7syczoxcQpCKUpb8k84qc5+afquu/u947rwZOHxOVqqmpb6ZTNcpzr6Z 9ob80CO8EQNeKTzPsotEzPsDTcKejQmy7crIA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749714572; x=1750319372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sbtP55NCyh4Df1vJCDqUAIM6R+yyfwut8FIK3Aq64wo=; b=r5nDWcICO6H0YQxhLOJfNgTxXOzq89O/nwxUQmUQ9x6FIFGuIN+1WdoJZaIpnaC5fU LQbCKn8vAr0TC4MDvQ1XbdoTEta/0DzzC7ov2qgZR3Lplt5uXR2BVKXr3e6xnXKf9C72 r1l8I/05fr3nEFeRCJkIjNHeUcMhHgH6S/ELPYoj99JzF9hLyvKZxylJC8lywZt3o/b7 aKsvxFfBJxKtsebOFsT9ghoftsGJ9N4qlUAxvLAZ2JPMAFc1tcXiiOwRqd554XY8hw0g oqvDpnfV3z5o8dza9N0lER6Ul2xkQuwXQXOb0loKsprFAseWc5PIk8CN07hA5MXzqjQ+ Zlqg== X-Forwarded-Encrypted: i=1; AJvYcCVGLeY1F9eSoEkSQHS5+PccZgIG8ZXAuefbrH2/ViKLQ24rtHyslm3c4v5mRCk8wAd/V58REyqu9n6kVos=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+ZkPGMDRjWc32PilRl88aeK78lAt6wxU8hBTNuK0BYeiSxgm+ oITt7cikyfrDDNDIPvHxUVGlV5z5+mMSQii0i0d8gp9lGdpBxM5IHvWfwDY8ni5d5A== X-Gm-Gg: ASbGncsbKGHMhBsOu4jjwV1cokNYnBT4LKFk8rEQA+nRXsr9sY15TkFyXKhLVambxTc ddZnFjJ7TZS6OxY/ISV8qnNngVIRuGmKA4iuTL5tHk6dUdgsufpz08/Fg9r+dU2VWC4o2AnD4/z Rb0Ij1Ij/P/0L1ktjsL51w8bdHc0zAQRZlRbT1BZOmQ5XsWMSwCM7UMZ1En1VUOXNPp7QOAnTmG uRnDza2XjXA9ImFKTSCdp+p5c/XLzuS2B8fVYOgk4C8F8F/Q/K+m8ejGa8NOX+7wLn5wbXpDO3E P3diBWNn6Tz4Rs8aVKFkcyXwSs5rK6CNsw6TGiKwB4/RUTvxJ02JiRg1vcbqzUqGfVhbtm2PVFY MD6g= X-Google-Smtp-Source: AGHT+IHaJlXxYg2mu49lXSk0cZU/cv8JMuXBWfPAapKkAyg9tvhMsqA+YooEcad1wogppx7rwBhFeA== X-Received: by 2002:a17:903:1b10:b0:234:d2fb:2d28 with SMTP id d9443c01a7336-23641aa2385mr85824375ad.2.1749714572600; Thu, 12 Jun 2025 00:49:32 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:5b9:e73a:2e58:5a47]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2364e63d42esm7893295ad.74.2025.06.12.00.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jun 2025 00:49:32 -0700 (PDT) From: Chen-Yu Tsai To: Liam Girdwood , Mark Brown Cc: Chen-Yu Tsai , Jaroslav Kysela , Takashi Iwai , Matthias Brugger , AngeloGioacchino Del Regno , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jiaxin Yu , linux-sound@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/9] ASoC: mediatek: use reserved memory or enable buffer pre-allocation Date: Thu, 12 Jun 2025 15:48:57 +0800 Message-ID: <20250612074901.4023253-7-wenst@chromium.org> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog In-Reply-To: <20250612074901.4023253-1-wenst@chromium.org> References: <20250612074901.4023253-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Chen-Yu Tsai --- sound/soc/mediatek/common/mtk-afe-platform-driver.c | 4 +++- sound/soc/mediatek/common/mtk-base-afe.h | 1 + sound/soc/mediatek/mt8173/mt8173-afe-pcm.c | 7 +++++++ sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 7 +++++++ sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 7 +++++++ sound/soc/mediatek/mt8192/mt8192-afe-pcm.c | 7 +++++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/so= c/mediatek/common/mtk-afe-platform-driver.c index 6b6330583941..70fd05d5ff48 100644 --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c @@ -120,7 +120,9 @@ int mtk_afe_pcm_new(struct snd_soc_component *component, struct mtk_base_afe *afe =3D snd_soc_component_get_drvdata(component); =20 size =3D 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); =20 return 0; } diff --git a/sound/soc/mediatek/common/mtk-base-afe.h b/sound/soc/mediatek/= common/mtk-base-afe.h index f51578b6c50a..a406f2e3e7a8 100644 --- a/sound/soc/mediatek/common/mtk-base-afe.h +++ b/sound/soc/mediatek/common/mtk-base-afe.h @@ -117,6 +117,7 @@ struct mtk_base_afe { struct mtk_base_afe_irq *irqs; int irqs_size; int memif_32bit_supported; + bool preallocate_buffers; =20 struct list_head sub_dais; struct snd_soc_dai_driver *dai_drivers; diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c b/sound/soc/mediate= k/mt8173/mt8173-afe-pcm.c index 04ed0cfec174..f93d6348fdf8 100644 --- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c +++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1070,6 +1071,12 @@ static int mt8173_afe_pcm_dev_probe(struct platform_= device *pdev) =20 afe->dev =3D &pdev->dev; =20 + ret =3D of_reserved_mem_device_init(&pdev->dev); + if (ret) { + dev_info(&pdev->dev, "no reserved memory found, pre-allocating buffers i= nstead\n"); + afe->preallocate_buffers =3D true; + } + irq_id =3D platform_get_irq(pdev, 0); if (irq_id <=3D 0) return irq_id < 0 ? irq_id : -ENXIO; diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c b/sound/soc/mediate= k/mt8183/mt8183-afe-pcm.c index e8884354995c..9b6b45c646e6 100644 --- a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c +++ b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include =20 @@ -777,6 +778,12 @@ static int mt8183_afe_pcm_dev_probe(struct platform_de= vice *pdev) afe->dev =3D &pdev->dev; dev =3D afe->dev; =20 + ret =3D of_reserved_mem_device_init(dev); + if (ret) { + dev_info(dev, "no reserved memory found, pre-allocating buffers instead\= n"); + afe->preallocate_buffers =3D true; + } + /* initial audio related clock */ ret =3D mt8183_init_clock(afe); if (ret) { diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediate= k/mt8186/mt8186-afe-pcm.c index db7c93401bee..c73b4664e53e 100644 --- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c +++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -2835,6 +2836,12 @@ static int mt8186_afe_pcm_dev_probe(struct platform_= device *pdev) afe_priv =3D afe->platform_priv; afe->dev =3D &pdev->dev; =20 + ret =3D of_reserved_mem_device_init(dev); + if (ret) { + dev_info(dev, "no reserved memory found, pre-allocating buffers instead\= n"); + afe->preallocate_buffers =3D true; + } + afe->base_addr =3D devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(afe->base_addr)) return PTR_ERR(afe->base_addr); diff --git a/sound/soc/mediatek/mt8192/mt8192-afe-pcm.c b/sound/soc/mediate= k/mt8192/mt8192-afe-pcm.c index fd6af74d7995..3d32fe46118e 100644 --- a/sound/soc/mediatek/mt8192/mt8192-afe-pcm.c +++ b/sound/soc/mediatek/mt8192/mt8192-afe-pcm.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -2179,6 +2180,12 @@ static int mt8192_afe_pcm_dev_probe(struct platform_= device *pdev) =20 afe->dev =3D dev; =20 + ret =3D of_reserved_mem_device_init(dev); + if (ret) { + dev_info(dev, "no reserved memory found, pre-allocating buffers instead\= n"); + afe->preallocate_buffers =3D true; + } + /* init audio related clock */ ret =3D mt8192_init_clock(afe); if (ret) { --=20 2.50.0.rc1.591.g9c95f17f64-goog