From nobody Mon Feb 9 09:43:07 2026 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 945FC248F5B; Wed, 30 Apr 2025 16:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746032136; cv=none; b=MsPw6LHCZ15Szw9t+JVJGjZjtbFMw1ZsBi5rHIAs5QMvO70LizuEha0TAJwweg5NRRu87AJGYCURWHUaRx2REXCnGVpsFqosGNfEwcHjwgwCNEEprZ+6CulcxW9/UbNvl2am8lbT4q2FFts0pdqONoIyEKzxRgwuDwnCRMFS1Ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746032136; c=relaxed/simple; bh=rsgOWhO2pu5zyjIx/PgkLniM/48Uoogtx/sgdnziwVE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DJTxI4LU75+HDMhT9flBljDrBStdl6j67GpXYoGECLvuh9oS7/Hqt3h9TPaxrcmta6kITMNfRaU6fGKzcKbmhmsxu+5TWcmQ52hniH28zXCM/WggEYNUt0HIPJY+zyKKqA4xNX6p+5LXm7yXuImotLd7wsEplLwMGz7XcOc1y0s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=4zoqto9U; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="4zoqto9U" Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53UCgokD017061; Wed, 30 Apr 2025 18:55:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= vpyb+c9mE+Q+2Mh2tz1ExittWKkMDszFfcq8RuscDGI=; b=4zoqto9UJncUOg75 9z2dpfdzXwjTwUtgbx5g+D/oHwmZR+OoCcV7CvNGUAtuM4Kz1ZxYf9fDE9r0klZv qoz7orVwMJbwyPBBJWXePQiSOub9SY/8AILGNkN5cAZZaDgNKjQkn1MtMactH1PZ lIUCjIpDukcjdZXzluY3Fgd6n6jNxywtz6UAFvDWZBCsxUXVKl4V6aiVpeM6pR4O 5t9WT1SMSWyCMadALu1xveazPI3v2BR7Njr7mtX3UQgt2G/Kr/U9WtUc1BI0P4p3 9bODKuCCMAQ3oZ6+I+owWWU/mihkysKCYePfSYGu82xD1H3jHgr0f/YmJZ4IHZxR VpF54g== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 46b6tnm8e7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Apr 2025 18:55:14 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id A812A4004A; Wed, 30 Apr 2025 18:54:09 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 1992DA47AC0; Wed, 30 Apr 2025 18:53:30 +0200 (CEST) Received: from localhost (10.252.20.195) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 30 Apr 2025 18:53:29 +0200 From: Olivier Moysan To: Olivier Moysan , Arnaud Pouliquen , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Maxime Coquelin , Alexandre Torgue CC: , , , Subject: [PATCH 1/2] ASoC: stm32: sai: skip useless iterations on kernel rate loop Date: Wed, 30 Apr 2025 18:52:08 +0200 Message-ID: <20250430165210.321273-2-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250430165210.321273-1-olivier.moysan@foss.st.com> References: <20250430165210.321273-1-olivier.moysan@foss.st.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 X-ClientProxiedBy: EQNCAS1NODE3.st.com (10.75.129.80) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-04-30_05,2025-04-24_02,2025-02-21_01 Content-Type: text/plain; charset="utf-8" the frequency of the kernel clock must be greater than or equal to the bitclock rate. When searching for a convenient kernel clock rate in stm32_sai_set_parent_rate() function, it is useless to continue the loop below bitclock rate, as it will result in a invalid kernel clock rate. Change the loop output condition. Fixes: b1d2e4067dc6 ("ASoC: stm32: sai: add stm32mp25 support") Signed-off-by: Olivier Moysan --- sound/soc/stm/stm32_sai_sub.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index e8c1abf1ae0a..4d018b4bc3f0 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -409,11 +409,11 @@ static int stm32_sai_set_parent_rate(struct stm32_sai= _sub_data *sai, unsigned int rate) { struct platform_device *pdev =3D sai->pdev; - unsigned int sai_ck_rate, sai_ck_max_rate, sai_curr_rate, sai_new_rate; + unsigned int sai_ck_rate, sai_ck_max_rate, sai_ck_min_rate, sai_curr_rate= , sai_new_rate; int div, ret; =20 /* - * Set maximum expected kernel clock frequency + * Set minimum and maximum expected kernel clock frequency * - mclk on or spdif: * f_sai_ck =3D MCKDIV * mclk-fs * fs * Here typical 256 ratio is assumed for mclk-fs @@ -423,13 +423,16 @@ static int stm32_sai_set_parent_rate(struct stm32_sai= _sub_data *sai, * Set constraint MCKDIV * FRL <=3D 256, to ensure MCKDIV is in availab= le range * f_sai_ck =3D sai_ck_max_rate * pow_of_two(FRL) / 256 */ + sai_ck_min_rate =3D rate * 256; if (!(rate % SAI_RATE_11K)) sai_ck_max_rate =3D SAI_MAX_SAMPLE_RATE_11K * 256; else sai_ck_max_rate =3D SAI_MAX_SAMPLE_RATE_8K * 256; =20 - if (!sai->sai_mclk && !STM_SAI_PROTOCOL_IS_SPDIF(sai)) + if (!sai->sai_mclk && !STM_SAI_PROTOCOL_IS_SPDIF(sai)) { + sai_ck_min_rate =3D rate * sai->fs_length; sai_ck_max_rate /=3D DIV_ROUND_CLOSEST(256, roundup_pow_of_two(sai->fs_l= ength)); + } =20 /* * Request exclusivity, as the clock is shared by SAI sub-blocks and by @@ -472,7 +475,7 @@ static int stm32_sai_set_parent_rate(struct stm32_sai_s= ub_data *sai, /* Try a lower frequency */ div++; sai_ck_rate =3D sai_ck_max_rate / div; - } while (sai_ck_rate > rate); + } while (sai_ck_rate >=3D sai_ck_min_rate); =20 /* No accurate rate found */ dev_err(&pdev->dev, "Failed to find an accurate rate"); --=20 2.25.1 From nobody Mon Feb 9 09:43:07 2026 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 9458B14AD2D; Wed, 30 Apr 2025 16:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746032135; cv=none; b=OEFc2kH7FIXhtPnGGrrDmAQVyrwnxu7Q+KSyMb4Q/bvDXmR4SQR7vpYNu3Hbl0VzJ/u1SXKNPgGSuUeiROdiDuO+OvZThyZ8VI6f/Y9/P8fVCVGkJQF2UG8ohf0v3vPjjSYqQ/HDrKSyXW3b5hCkBkqzR4IJPEuz/N/Im2UOQzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746032135; c=relaxed/simple; bh=L0RKKwiQ7GyKl4xfqFhpjFxweQu23Zgw/+jPFJXvplY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r7c0D+HDxPUid2w3SBGeePH6qH0H7SkUYJ00rg0H1FmAOuIn2NyBEk/kM76WMPj5CZuZqBszxhwImpcjbbmLFimSja8m6mpkVuwhkjMx/wl1q1RF4Fd7g2ExDD7t7o6MqwPy6B73m0BuMD/v6UnsqypDJC3pmSwWPK21J7GPmCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b=eMYfExz/; arc=none smtp.client-ip=91.207.212.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=foss.st.com header.i=@foss.st.com header.b="eMYfExz/" Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53UCTNne004579; Wed, 30 Apr 2025 18:55:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= iKq3Hl0BrIcuMMTCUIpmWVs6NCKyQQcOHdChQ0yRkYc=; b=eMYfExz/m4143DkQ BKXwK1tP2QdWw06akhjwl+6K6BisWJZaY2k7gFM8yttwy0kRfYZQVkIbI5u1ZnV5 Shf8jMi3fOEYuMBAlkC3PfkqXpk2JsiOBR8Y1V8pCtGQKmaJJvJHfyO/iyrVXzyX 7VEZ9Gx3d+Jps9z7uP4WlO20VfS11DNy4dstDzTnTWEbZkjuKL41Rek+LuRDeBEH L4iFMXLHVnFwvVoX1VblH1hEExiBz7zVJb3x9cdnekm0KsWv7SyvmvdlrhvINpOw lrsXYXFsjwaDSuA4qqIyHl4QSfBXaFVmfq4KlIYwpMhOR9GINl84Uo85Fq2cXEGH etSydw== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 46b6tf483u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Apr 2025 18:55:14 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id C38C74004C; Wed, 30 Apr 2025 18:54:09 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 362E6A47ACC; Wed, 30 Apr 2025 18:53:31 +0200 (CEST) Received: from localhost (10.252.20.195) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 30 Apr 2025 18:53:30 +0200 From: Olivier Moysan To: Olivier Moysan , Arnaud Pouliquen , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Maxime Coquelin , Alexandre Torgue CC: , , , Subject: [PATCH 2/2] ASoC: stm32: sai: add a check on minimal kernel frequency Date: Wed, 30 Apr 2025 18:52:09 +0200 Message-ID: <20250430165210.321273-3-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250430165210.321273-1-olivier.moysan@foss.st.com> References: <20250430165210.321273-1-olivier.moysan@foss.st.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 X-ClientProxiedBy: EQNCAS1NODE3.st.com (10.75.129.80) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-04-30_05,2025-04-24_02,2025-02-21_01 Content-Type: text/plain; charset="utf-8" On MP2 SoCs SAI kernel clock rate is managed through stm32_sai_set_parent_rate() function. If the kernel clock rate was set previously to a low frequency, this frequency may be too low to support the newly requested audio stream rate. However the stm32_sai_rate_accurate() will only check accuracy against the maximum kernel clock rate. The function will return leaving the kernel clock rate unchanged. Add a check on minimal frequency requirement, to avoid this. Fixes: b1d2e4067dc6 ("ASoC: stm32: sai: add stm32mp25 support") Signed-off-by: Olivier Moysan --- sound/soc/stm/stm32_sai_sub.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index 4d018b4bc3f0..bf5299ba11c3 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -447,7 +447,10 @@ static int stm32_sai_set_parent_rate(struct stm32_sai_= sub_data *sai, * return immediately. */ sai_curr_rate =3D clk_get_rate(sai->sai_ck); - if (stm32_sai_rate_accurate(sai_ck_max_rate, sai_curr_rate)) + dev_dbg(&pdev->dev, "kernel clock rate: min [%u], max [%u], current [%u]", + sai_ck_min_rate, sai_ck_max_rate, sai_curr_rate); + if (stm32_sai_rate_accurate(sai_ck_max_rate, sai_curr_rate) && + sai_curr_rate >=3D sai_ck_min_rate) return 0; =20 /* --=20 2.25.1