From patchwork Wed Sep 11 12:29:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Simion X-Patchwork-Id: 13800472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D3222EE499F for ; Wed, 11 Sep 2024 12:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RTD3sAu2eP+Xn6tP3/e6OLx7DgHyX3bqWs5jg9GraUY=; b=Hbw1A+EYgoMcSVjSTs2yc1CVpi vOiQ5Ckm39Aqxa214AUCJBIFkZVB7YK9Y7FX0ANybNuQIV8vUupt1poYy/WcbopZ84vE01AqEXT71 qAqaPkZJnmqTdRsc1+OWVOAu8yjziqjc0g6iu5hTcI9S8M8/87uJ3brmW6J66A7qETF9pz2qihq/x cyVvAbXKpvQOlosC5YpQjTNEb2eFpOvYypnR0IHz/f/qDd8lNgA8KBRmB428Xll7xcaA9ifeJ549q dCoClEcC1Bz1OUvPxJyUZBEHYw2+DHbwptIOiWGYpv8G3HDc7x3Aw3ICy7ZGij6iSo8NS5mgDORHn Nl8wkQxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soMY8-00000009VSl-1Lpb; Wed, 11 Sep 2024 12:34:20 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soMTw-00000009U2m-3stX for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 12:30:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1726057801; x=1757593801; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=otB2gyp0DjafuKuP6eN9+hCMx0oFkm3tLV8V7z0L5wk=; b=d5ZEpH++ow0iDv7lwMnwMPL2J7BAaxVPymUkdSRZ/uOvBKmOJ1pg6zS3 kBH0JBBFW27zE3iWokqM3vQQ9qbeC2qDfTWVsye39LTDy4TgTfxENWfaB KWAB3fQHxOntfFt7iTmdQJjM5M4e+mmvSlFjtYwRpMkn3lfkyad2ycbNi gLjHTJt4yyen+OzyrbFnEDRGSU6KxBlIH5/W5Oy1BMWnpPSv9YKt9A1BD HoDHzCNKRRitZQXrecoecnwgCfEBg9mRYTv7Xt7TwsfXtHrQXHNfwWyx5 VfWLInq9o8V92EQbN19ugwfYm9rkFzdeScM8YvX3wAdyyW9pWXLEC9Pu2 w==; X-CSE-ConnectionGUID: 9vUpuscIQ26YBlU3BRadaQ== X-CSE-MsgGUID: icmd1AtdT1CZxL1xIvnPOg== X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="32269431" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Sep 2024 05:29:57 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 11 Sep 2024 05:29:17 -0700 Received: from ROB-ULT-M76677.microchip.com (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 11 Sep 2024 05:29:14 -0700 From: Andrei Simion To: , , , , , , CC: , , , , Codrin Ciubotariu , Andrei Simion Subject: [PATCH 1/3] ASoC: atmel: mchp-pdmc: Improve maxburst calculation for better performance Date: Wed, 11 Sep 2024 15:29:07 +0300 Message-ID: <20240911122909.133399-2-andrei.simion@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911122909.133399-1-andrei.simion@microchip.com> References: <20240911122909.133399-1-andrei.simion@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_053001_197062_594913B1 X-CRM114-Status: GOOD ( 15.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Codrin Ciubotariu Improve the DMA descriptor calculation by dividing the period size by the product of sample size and DMA chunk size, rather than just DMA chunk size. Ensure that all DMA descriptors start from a well-aligned address to improve the reliability and efficiency of DMA operations and avoid potential issues related to misaligned descriptors. [andrei.simion@microchip.com: Adjust the commit title. Reword the commit message. Add MACROS for each DMA size chunk supported by mchp-pdmc. Add DMA_BURST_ALIGNED preprocesor function to check the alignment of the DMA burst.] Signed-off-by: Codrin Ciubotariu Signed-off-by: Andrei Simion --- sound/soc/atmel/mchp-pdmc.c | 39 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/sound/soc/atmel/mchp-pdmc.c b/sound/soc/atmel/mchp-pdmc.c index 260074018da9..7a5585839c1d 100644 --- a/sound/soc/atmel/mchp-pdmc.c +++ b/sound/soc/atmel/mchp-pdmc.c @@ -90,6 +90,15 @@ #define MCHP_PDMC_DS_NO 2 #define MCHP_PDMC_EDGE_NO 2 +/* + * ---- DMA chunk size allowed ---- + */ +#define MCHP_PDMC_DMA_8_WORD_CHUNK 8 +#define MCHP_PDMC_DMA_4_WORD_CHUNK 4 +#define MCHP_PDMC_DMA_2_WORD_CHUNK 2 +#define MCHP_PDMC_DMA_1_WORD_CHUNK 1 +#define DMA_BURST_ALIGNED(_p, _s, _w) !(_p % (_s * _w)) + struct mic_map { int ds_pos; int clk_edge; @@ -511,15 +520,18 @@ static u32 mchp_pdmc_mr_set_osr(int audio_filter_en, unsigned int osr) return 0; } -static inline int mchp_pdmc_period_to_maxburst(int period_size) +static inline int mchp_pdmc_period_to_maxburst(int period_size, int sample_size) { - if (!(period_size % 8)) - return 8; - if (!(period_size % 4)) - return 4; - if (!(period_size % 2)) - return 2; - return 1; + int p_size = period_size; + int s_size = sample_size; + + if (DMA_BURST_ALIGNED(p_size, s_size, MCHP_PDMC_DMA_8_WORD_CHUNK)) + return MCHP_PDMC_DMA_8_WORD_CHUNK; + if (DMA_BURST_ALIGNED(p_size, s_size, MCHP_PDMC_DMA_4_WORD_CHUNK)) + return MCHP_PDMC_DMA_4_WORD_CHUNK; + if (DMA_BURST_ALIGNED(p_size, s_size, MCHP_PDMC_DMA_2_WORD_CHUNK)) + return MCHP_PDMC_DMA_2_WORD_CHUNK; + return MCHP_PDMC_DMA_1_WORD_CHUNK; } static struct snd_pcm_chmap_elem mchp_pdmc_std_chmaps[] = { @@ -547,14 +559,18 @@ static int mchp_pdmc_hw_params(struct snd_pcm_substream *substream, unsigned int channels = params_channels(params); unsigned int osr = 0, osr_start; unsigned int fs = params_rate(params); + int sample_bytes = params_physical_width(params) / 8; + int period_bytes = params_period_size(params) * + params_channels(params) * sample_bytes; + int maxburst; u32 mr_val = 0; u32 cfgr_val = 0; int i; int ret; - dev_dbg(comp->dev, "%s() rate=%u format=%#x width=%u channels=%u\n", + dev_dbg(comp->dev, "%s() rate=%u format=%#x width=%u channels=%u period_bytes=%d\n", __func__, params_rate(params), params_format(params), - params_width(params), params_channels(params)); + params_width(params), params_channels(params), period_bytes); if (channels > dd->mic_no) { dev_err(comp->dev, "more channels %u than microphones %d\n", @@ -608,7 +624,8 @@ static int mchp_pdmc_hw_params(struct snd_pcm_substream *substream, mr_val |= FIELD_PREP(MCHP_PDMC_MR_SINCORDER_MASK, dd->sinc_order); - dd->addr.maxburst = mchp_pdmc_period_to_maxburst(snd_pcm_lib_period_bytes(substream)); + maxburst = mchp_pdmc_period_to_maxburst(period_bytes, sample_bytes); + dd->addr.maxburst = maxburst; mr_val |= FIELD_PREP(MCHP_PDMC_MR_CHUNK_MASK, dd->addr.maxburst); dev_dbg(comp->dev, "maxburst set to %d\n", dd->addr.maxburst); From patchwork Wed Sep 11 12:29:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Simion X-Patchwork-Id: 13800474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA2DFEE499F for ; Wed, 11 Sep 2024 12:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=soDjxag3iXzZlQCSguMGVq7vpxVhUFUstOkNf9idVds=; b=ZE9X2r3D3+XdYTXbqS08jiP0Et QcpZ1TL1pOeoyHyMp+K4USv7dD+Ckldc3hteQF788PYb2Von2gkzDXrXUySvPPEU5oDLxCWK0RTZ0 vcvbp1ZSr3k1eBLDINLzKcMKCmPS84EJszm5uKbONV2ejy4V4HjzWTlpStjuLMLbD6T3Q+9sEy9Lm /Qg/oRJpQzXG7tQ+mTbYBrKlwid5hnVj25drNQI9zciPMAzE9PlK6d+QjoLAIAyF3uD7yxlB8g++6 Jl/+NNUpIJogGUy3xeALNxnUI9T1U3TyCEOHjgfH8SxhXj7NLZSBqkVSBV7nu/yeCt1zydrL0HeUA yljOiTsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soMaA-00000009W0M-12KG; Wed, 11 Sep 2024 12:36:26 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soMUA-00000009UAE-089f for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 12:30:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1726057813; x=1757593813; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TxWkOdseiNx1bafVcVq7iqdfmlO4X8zdBrM+WKyic7w=; b=Kru/eQBkePBS2sgtOSfuHlWurKFLZTri/MWt1p+TtoTNnTInlGWw1PY+ p3XkKMOdNsByOgpBiJ1qEAlgIIXGDDT2dyU8JUR9kZuaa5leCMSSX+cxN F9zIOd3ihTKhFQdIxoESf+zyNFvgX5mKvQT+BRSWrmmuRxURJQGe43cAK Z3zTR/yCeBlZPVL63iMqeCrxd4S9wK6RFjPCWDCLIPvrIr1eWh3IHOY/u 5n/lm/woD8R/O1jl8gyQRvyAJtCBd76zozUcXryckmfWyRjXF11KmPH62 Cl4GVqnMSyKvYGWqBZ/PaSW+ZoypG95DB2Q4dou4vrdekoUZZHeqleM7D g==; X-CSE-ConnectionGUID: TYXepcQqR+aekZWbFABIig== X-CSE-MsgGUID: h6+wpwAeSbmE8OyH4DEEtQ== X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="31538368" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Sep 2024 05:30:13 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 11 Sep 2024 05:29:20 -0700 Received: from ROB-ULT-M76677.microchip.com (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 11 Sep 2024 05:29:17 -0700 From: Andrei Simion To: , , , , , , CC: , , , , Codrin Ciubotariu , Andrei Simion Subject: [PATCH 2/3] ASoC: atmel: mchp-pdmc: Add snd_soc_dai_driver name Date: Wed, 11 Sep 2024 15:29:08 +0300 Message-ID: <20240911122909.133399-3-andrei.simion@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911122909.133399-1-andrei.simion@microchip.com> References: <20240911122909.133399-1-andrei.simion@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_053014_160177_6C11EFFD X-CRM114-Status: GOOD ( 10.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Codrin Ciubotariu Set snd_soc_dai_driver name to improve controller's display of the DAI name. Signed-off-by: Codrin Ciubotariu Signed-off-by: Andrei Simion --- sound/soc/atmel/mchp-pdmc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/soc/atmel/mchp-pdmc.c b/sound/soc/atmel/mchp-pdmc.c index 7a5585839c1d..d97d153ee375 100644 --- a/sound/soc/atmel/mchp-pdmc.c +++ b/sound/soc/atmel/mchp-pdmc.c @@ -777,6 +777,7 @@ static const struct snd_soc_dai_ops mchp_pdmc_dai_ops = { }; static struct snd_soc_dai_driver mchp_pdmc_dai = { + .name = "mchp-pdmc", .capture = { .stream_name = "Capture", .channels_min = 1, From patchwork Wed Sep 11 12:29:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Simion X-Patchwork-Id: 13800473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A7EBEE499F for ; Wed, 11 Sep 2024 12:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YJ+7NjzpvoMw54LiN1YA4Fv4+Yp2g55wQPsBhncAXMQ=; b=1d5r6brpCUFEuuhoFsi8c2X/qA /MKGgcLA1+WeEtP/qJK24W/Jl6H0Qr/InefJ7skGZJP/CTOonwBBfAavCBUfZhXNUYdM2T0Zhx1AS ojIhHJdIGGiO22l5DsCbmMgW/AhrIgSYEYttKkLNxNjCRkrFO/gsb6IN5+Fu/GikFVW2e1vK52nzy fqhwS3IJo7njCa+vclYYq4x2ce1ajhH4ggJdYdLjKrjfBGvUW0yy+T43kjeX6eVxCsOq8isD3C2Rp Kx00C/I5RHdT/jFkxVh4gyW6B0oqZIYgKrWgsFrsqBTlJbzPZiAGpBSjoF1daaUCoeQzdBQ6LXAbr MYarTiWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soMZ9-00000009Vkz-412n; Wed, 11 Sep 2024 12:35:23 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soMTz-00000009U2m-0zZo for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 12:30:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1726057803; x=1757593803; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PiygWBMWWgmiBJlhMmEQ0JypGcuuZJZ1K9IpKWur6s8=; b=xqtxpnb7k4yNICQLyb0HBUpqE38bIzlGC226uPNaUA7/tId0dr5pGD9o SZyX/k1+UNECZzy7kmnSOjAu/7/BBAwhyzwYphFIU2pH8PrNnyQTPdcI4 vVu2tIaSOCfcrlxDymq3NypuZwTsCuf3wFpNEQMqYxtRRgb1bGGMQ1nor 3yOt7N4D5J2xO9YnSIRDu0eTk19mDqpp1g5d7rT36JD0TpCPW6GRlXJEj R+t/dWsi2FTD1EOtq5BJtpEH5dYDucjgR7gBxkvDFN6YOsCYYfXps1VhQ TAjAT+UyV+tY7OyBp/OiHL03WK1xuwmeT4ziwKK6xNqU3f1ooDHgol7SB A==; X-CSE-ConnectionGUID: 9vUpuscIQ26YBlU3BRadaQ== X-CSE-MsgGUID: rcOEGGVATUaFBm20lYIsUg== X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="32269432" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Sep 2024 05:29:58 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 11 Sep 2024 05:29:23 -0700 Received: from ROB-ULT-M76677.microchip.com (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 11 Sep 2024 05:29:20 -0700 From: Andrei Simion To: , , , , , , CC: , , , , Codrin Ciubotariu , Andrei Simion Subject: [PATCH 3/3] ASoC: atmel: mchp-pdmc: Retain Non-Runtime Controls Date: Wed, 11 Sep 2024 15:29:09 +0300 Message-ID: <20240911122909.133399-4-andrei.simion@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911122909.133399-1-andrei.simion@microchip.com> References: <20240911122909.133399-1-andrei.simion@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_053003_675090_6CF95FAD X-CRM114-Status: GOOD ( 21.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Codrin Ciubotariu Avoid removing these controls, as doing so can cause issues if the stream is initiated from another control. Ensure these controls remain intact when the stream is started or finished. Instead of removing them, return an -EBUSY error code to indicate that the controller is busy, especially when the audio filter and the SINC filter are in use. [andrei.simion@microchip.com: Reword the commit title and the commit message. Adapt the code from kernel v6.1 -> v6.6 -> latest kernel version.] Signed-off-by: Codrin Ciubotariu Signed-off-by: Andrei Simion --- sound/soc/atmel/mchp-pdmc.c | 78 ++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/sound/soc/atmel/mchp-pdmc.c b/sound/soc/atmel/mchp-pdmc.c index d97d153ee375..758b3c550b97 100644 --- a/sound/soc/atmel/mchp-pdmc.c +++ b/sound/soc/atmel/mchp-pdmc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -113,6 +114,7 @@ struct mchp_pdmc_chmap { struct mchp_pdmc { struct mic_map channel_mic_map[MCHP_PDMC_MAX_CHANNELS]; + spinlock_t busy_lock; /* lock protecting busy */ struct device *dev; struct snd_dmaengine_dai_dma_data addr; struct regmap *regmap; @@ -124,6 +126,7 @@ struct mchp_pdmc { int mic_no; int sinc_order; bool audio_filter_en; + u8 busy:1; }; static const char *const mchp_pdmc_sinc_filter_order_text[] = { @@ -167,10 +170,19 @@ static int mchp_pdmc_sinc_order_put(struct snd_kcontrol *kcontrol, return -EINVAL; val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; - if (val == dd->sinc_order) + + spin_lock(&dd->busy_lock); + if (dd->busy) { + spin_unlock((&dd->busy_lock)); + return -EBUSY; + } + if (val == dd->sinc_order) { + spin_unlock((&dd->busy_lock)); return 0; + } dd->sinc_order = val; + spin_unlock((&dd->busy_lock)); return 1; } @@ -193,10 +205,18 @@ static int mchp_pdmc_af_put(struct snd_kcontrol *kcontrol, struct mchp_pdmc *dd = snd_soc_component_get_drvdata(component); bool af = uvalue->value.integer.value[0] ? true : false; - if (dd->audio_filter_en == af) + spin_lock(&dd->busy_lock); + if (dd->busy) { + spin_unlock((&dd->busy_lock)); + return -EBUSY; + } + if (dd->audio_filter_en == af) { + spin_unlock((&dd->busy_lock)); return 0; + } dd->audio_filter_en = af; + spin_unlock((&dd->busy_lock)); return 1; } @@ -379,52 +399,10 @@ static const struct snd_kcontrol_new mchp_pdmc_snd_controls[] = { }, }; -static int mchp_pdmc_close(struct snd_soc_component *component, - struct snd_pcm_substream *substream) -{ - return snd_soc_add_component_controls(component, mchp_pdmc_snd_controls, - ARRAY_SIZE(mchp_pdmc_snd_controls)); -} - -static int mchp_pdmc_open(struct snd_soc_component *component, - struct snd_pcm_substream *substream) -{ - int i; - - /* remove controls that can't be changed at runtime */ - for (i = 0; i < ARRAY_SIZE(mchp_pdmc_snd_controls); i++) { - const struct snd_kcontrol_new *control = &mchp_pdmc_snd_controls[i]; - struct snd_ctl_elem_id id; - int err; - - if (component->name_prefix) - snprintf(id.name, sizeof(id.name), "%s %s", component->name_prefix, - control->name); - else - strscpy(id.name, control->name, sizeof(id.name)); - - id.numid = 0; - id.iface = control->iface; - id.device = control->device; - id.subdevice = control->subdevice; - id.index = control->index; - err = snd_ctl_remove_id(component->card->snd_card, &id); - if (err < 0) - dev_err(component->dev, "%d: Failed to remove %s\n", err, - control->name); - } - - return 0; -} - static const struct snd_soc_component_driver mchp_pdmc_dai_component = { .name = "mchp-pdmc", .controls = mchp_pdmc_snd_controls, .num_controls = ARRAY_SIZE(mchp_pdmc_snd_controls), - .open = &mchp_pdmc_open, - .close = &mchp_pdmc_close, - .legacy_dai_naming = 1, - .trigger_start = SND_SOC_TRIGGER_ORDER_LDC, }; static const unsigned int mchp_pdmc_1mic[] = {1}; @@ -587,6 +565,13 @@ static int mchp_pdmc_hw_params(struct snd_pcm_substream *substream, cfgr_val |= MCHP_PDMC_CFGR_BSSEL(i); } + /* + * from these point forward, we consider the controller busy, so the + * audio filter and SINC order can't be changed + */ + spin_lock(&dd->busy_lock); + dd->busy = 1; + spin_unlock((&dd->busy_lock)); for (osr_start = dd->audio_filter_en ? 64 : 8; osr_start <= 256 && best_diff_rate; osr_start *= 2) { long round_rate; @@ -1099,6 +1084,7 @@ static int mchp_pdmc_probe(struct platform_device *pdev) */ dd->audio_filter_en = true; dd->sinc_order = 3; + spin_lock_init(&dd->busy_lock); dd->addr.addr = (dma_addr_t)res->start + MCHP_PDMC_RHR; platform_set_drvdata(pdev, dd); @@ -1143,6 +1129,10 @@ static void mchp_pdmc_remove(struct platform_device *pdev) { struct mchp_pdmc *dd = platform_get_drvdata(pdev); + spin_lock(&dd->busy_lock); + dd->busy = 0; + spin_unlock((&dd->busy_lock)); + if (!pm_runtime_status_suspended(dd->dev)) mchp_pdmc_runtime_suspend(dd->dev);