From nobody Sat Nov 30 06:25:39 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDD0519E981; Wed, 11 Sep 2024 12:29:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726057801; cv=none; b=LXSs/AQGlFdNnMSfRnjfxVzylAH+6ueSE/9gM6euoVKqLXg/pQYOkBMi5LrO+7ldD/2WNa6uOeNexefWF6MEdvilViDujYd2ox9zqNVOI7/PCdUAvMihUiPEwAfat2w5tkOtnFOeDoFoyzJ9zXYHCMQwLSRp0pNw3PxNjVvDUm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726057801; c=relaxed/simple; bh=otB2gyp0DjafuKuP6eN9+hCMx0oFkm3tLV8V7z0L5wk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EZCGQ5Gr2zEX4r0fQ/soRqnaQwC2NJ6PDEtE+hRiXT+ORtGp17SpUBNdS1Cz3bdjcVFEtnHBZFLPq3owawLlSO2su234XSux5F3nwKAOInE5OoE/S/3JqtW2DDJD6ty5LziXbbGCReA+y4QrtDaHheS9VqXcqyWHn0jPwH9jZRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=Kefj+On9; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="Kefj+On9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1726057799; x=1757593799; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=otB2gyp0DjafuKuP6eN9+hCMx0oFkm3tLV8V7z0L5wk=; b=Kefj+On9wIgYy5WLKoquKHOgKhMFz9cDDqv4VqyeDYL/xotdtcJEGdJu 6VoRalIHkDWqt7tJ+JCH9xcfgPx8Nge5Mzn91QEhGZFmvmDSuPoyV25vi X8KpwbaoCeqB9Bg8ixRC091wuH1CrZvlMEkllWNB4oUbnD0KuYXqGBO9s /A4Zf2nYpql0h27tXOUE0ipdqWYHwGs3mQk0J9WTuyKdM5AqdWaPb93Df 5RDrBN8b9nuQaKXLEIi7l2Zz4QE5XRvb3GnDswcJp/zref08yz/qEtAz/ hbR9Si0w0lOIjDa7X1ph/QwHNMuzC00mwUP1QYOMkMVunyc7wTEitbyod A==; 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> 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" 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 =20 +/* + * ---- 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; } =20 -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 =3D period_size; + int s_size =3D 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; } =20 static struct snd_pcm_chmap_elem mchp_pdmc_std_chmaps[] =3D { @@ -547,14 +559,18 @@ static int mchp_pdmc_hw_params(struct snd_pcm_substre= am *substream, unsigned int channels =3D params_channels(params); unsigned int osr =3D 0, osr_start; unsigned int fs =3D params_rate(params); + int sample_bytes =3D params_physical_width(params) / 8; + int period_bytes =3D params_period_size(params) * + params_channels(params) * sample_bytes; + int maxburst; u32 mr_val =3D 0; u32 cfgr_val =3D 0; int i; int ret; =20 - dev_dbg(comp->dev, "%s() rate=3D%u format=3D%#x width=3D%u channels=3D%u\= n", + dev_dbg(comp->dev, "%s() rate=3D%u format=3D%#x width=3D%u channels=3D%u = period_bytes=3D%d\n", __func__, params_rate(params), params_format(params), - params_width(params), params_channels(params)); + params_width(params), params_channels(params), period_bytes); =20 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, =20 mr_val |=3D FIELD_PREP(MCHP_PDMC_MR_SINCORDER_MASK, dd->sinc_order); =20 - dd->addr.maxburst =3D mchp_pdmc_period_to_maxburst(snd_pcm_lib_period_byt= es(substream)); + maxburst =3D mchp_pdmc_period_to_maxburst(period_bytes, sample_bytes); + dd->addr.maxburst =3D maxburst; mr_val |=3D FIELD_PREP(MCHP_PDMC_MR_CHUNK_MASK, dd->addr.maxburst); dev_dbg(comp->dev, "maxburst set to %d\n", dd->addr.maxburst); =20 --=20 2.34.1 From nobody Sat Nov 30 06:25:39 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 094F1192B9F; Wed, 11 Sep 2024 12:30:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726057815; cv=none; b=D5fStNVL0yfa0FRLk8+fUiBeWkqZ2TPrFwoJ0yUBLmsMAk9JUmU48Ea/bOYbSHgLU2cmnETjuYe+0IkXeKcLYGoWbqVsW2cBR5wUGhigjAdQZI4aLoOchN1fvIyaUNZvA/OpWK9jnGliz4xRa2ASX5v44jIrz4YsJeu9ONCDfz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726057815; c=relaxed/simple; bh=TxWkOdseiNx1bafVcVq7iqdfmlO4X8zdBrM+WKyic7w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KSZsPDTr5Y9q50DPTM59JoTFUnMCVVo0mnWTpbxFv18WSJvVokkwR4ZFjyAGNwsrcE5DP/F6DvDwk7ufmPdq8BASsLOWRegaC+2BOe/ED14NQUFlW55lFfOl+YHO3dXdMhNvkh+Vf2DBRBK544B2didkRmZ1MgnysITubNv8/pU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=Kru/eQBk; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="Kru/eQBk" 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> 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" 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 = =3D { }; =20 static struct snd_soc_dai_driver mchp_pdmc_dai =3D { + .name =3D "mchp-pdmc", .capture =3D { .stream_name =3D "Capture", .channels_min =3D 1, --=20 2.34.1 From nobody Sat Nov 30 06:25:39 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 422EE19E963; Wed, 11 Sep 2024 12:30:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726057803; cv=none; b=FyyXHwI2Yk4vg9ezvVosHcKWc7hor7pVj2AEBnLyC6UvW8xV/VYhW/47yigxLTEDzwoI06AybAb+1xjz5D9kLELXBM8Tv1/gFyh4xTlIC3f6Y0Z1RtmCVbIhCUbNMBGtETZSd94OoZQnELHdvfNnkdLd/K6gyzajFYYhU/nVRvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726057803; c=relaxed/simple; bh=PiygWBMWWgmiBJlhMmEQ0JypGcuuZJZ1K9IpKWur6s8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kcm1tJZYkV0ajhfPg8IlrNr4rZtp76cepkvbGia7e5qKLMjue6QO4lGRWBA1SJHeKa9vRJOMG61sgxCuDcQVTeld8wxgJvaQnmFK4QqvC8ulqbfBzqCts1J7cn+vyWhB//SbeY95pRdpz6Y72+oM1Qw3W9woOyZPgvh9jkAYyWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=DXsvZCPq; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="DXsvZCPq" 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=PiygWBMWWgmiBJlhMmEQ0JypGcuuZJZ1K9IpKWur6s8=; b=DXsvZCPqJxaqvezyGvUIy7EaiDeQMuIVPoLaD+48VYGpvMY73H3kaj8p 0wPx7CXpk29LGdxvADoJfjw20wLzqxlZRL5LAVC2DCXc510O1j0TwSXIj Ql2VlbOnA8d+WMsGkwpoGcQulneyl/Qvqy/c2+QezezxkamyHnyOgVUbE x3qzy56DxvnIoykw34oMImCVcpXBuN7UjDh9GUjFESEQrpBE449aAbL+l atApXjQsESvQq4+0TIR6drYElZPdVWvH/OxpL2l+DHqLmsAKJJpFC9OZA a3kJn0LCAAl8NExcZgpFn/970+XI1ontZBvjpv1J0pqF2vX8msMUYlwQD Q==; 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> 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" 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 =20 #include #include @@ -113,6 +114,7 @@ struct mchp_pdmc_chmap { =20 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; }; =20 static const char *const mchp_pdmc_sinc_filter_order_text[] =3D { @@ -167,10 +170,19 @@ static int mchp_pdmc_sinc_order_put(struct snd_kcontr= ol *kcontrol, return -EINVAL; =20 val =3D snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; - if (val =3D=3D dd->sinc_order) + + spin_lock(&dd->busy_lock); + if (dd->busy) { + spin_unlock((&dd->busy_lock)); + return -EBUSY; + } + if (val =3D=3D dd->sinc_order) { + spin_unlock((&dd->busy_lock)); return 0; + } =20 dd->sinc_order =3D val; + spin_unlock((&dd->busy_lock)); =20 return 1; } @@ -193,10 +205,18 @@ static int mchp_pdmc_af_put(struct snd_kcontrol *kcon= trol, struct mchp_pdmc *dd =3D snd_soc_component_get_drvdata(component); bool af =3D uvalue->value.integer.value[0] ? true : false; =20 - if (dd->audio_filter_en =3D=3D af) + spin_lock(&dd->busy_lock); + if (dd->busy) { + spin_unlock((&dd->busy_lock)); + return -EBUSY; + } + if (dd->audio_filter_en =3D=3D af) { + spin_unlock((&dd->busy_lock)); return 0; + } =20 dd->audio_filter_en =3D af; + spin_unlock((&dd->busy_lock)); =20 return 1; } @@ -379,52 +399,10 @@ static const struct snd_kcontrol_new mchp_pdmc_snd_co= ntrols[] =3D { }, }; =20 -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 =3D 0; i < ARRAY_SIZE(mchp_pdmc_snd_controls); i++) { - const struct snd_kcontrol_new *control =3D &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 =3D 0; - id.iface =3D control->iface; - id.device =3D control->device; - id.subdevice =3D control->subdevice; - id.index =3D control->index; - err =3D 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 =3D { .name =3D "mchp-pdmc", .controls =3D mchp_pdmc_snd_controls, .num_controls =3D ARRAY_SIZE(mchp_pdmc_snd_controls), - .open =3D &mchp_pdmc_open, - .close =3D &mchp_pdmc_close, - .legacy_dai_naming =3D 1, - .trigger_start =3D SND_SOC_TRIGGER_ORDER_LDC, }; =20 static const unsigned int mchp_pdmc_1mic[] =3D {1}; @@ -587,6 +565,13 @@ static int mchp_pdmc_hw_params(struct snd_pcm_substrea= m *substream, cfgr_val |=3D MCHP_PDMC_CFGR_BSSEL(i); } =20 + /* + * 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 =3D 1; + spin_unlock((&dd->busy_lock)); for (osr_start =3D dd->audio_filter_en ? 64 : 8; osr_start <=3D 256 && best_diff_rate; osr_start *=3D 2) { long round_rate; @@ -1099,6 +1084,7 @@ static int mchp_pdmc_probe(struct platform_device *pd= ev) */ dd->audio_filter_en =3D true; dd->sinc_order =3D 3; + spin_lock_init(&dd->busy_lock); =20 dd->addr.addr =3D (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 =3D platform_get_drvdata(pdev); =20 + spin_lock(&dd->busy_lock); + dd->busy =3D 0; + spin_unlock((&dd->busy_lock)); + if (!pm_runtime_status_suspended(dd->dev)) mchp_pdmc_runtime_suspend(dd->dev); =20 --=20 2.34.1