Skip to content

Commit edea927

Browse files
Olivier Moysanbroonie
authored andcommitted
ASoC: stm32: sai: skip useless iterations on kernel rate loop
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: 2cfe1ff ("ASoC: stm32: sai: add stm32mp25 support") Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com> Link: https://patch.msgid.link/20250430165210.321273-2-olivier.moysan@foss.st.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent b443265 commit edea927

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

sound/soc/stm/stm32_sai_sub.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,11 @@ static int stm32_sai_set_parent_rate(struct stm32_sai_sub_data *sai,
409409
unsigned int rate)
410410
{
411411
struct platform_device *pdev = sai->pdev;
412-
unsigned int sai_ck_rate, sai_ck_max_rate, sai_curr_rate, sai_new_rate;
412+
unsigned int sai_ck_rate, sai_ck_max_rate, sai_ck_min_rate, sai_curr_rate, sai_new_rate;
413413
int div, ret;
414414

415415
/*
416-
* Set maximum expected kernel clock frequency
416+
* Set minimum and maximum expected kernel clock frequency
417417
* - mclk on or spdif:
418418
* f_sai_ck = MCKDIV * mclk-fs * fs
419419
* 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,
423423
* Set constraint MCKDIV * FRL <= 256, to ensure MCKDIV is in available range
424424
* f_sai_ck = sai_ck_max_rate * pow_of_two(FRL) / 256
425425
*/
426+
sai_ck_min_rate = rate * 256;
426427
if (!(rate % SAI_RATE_11K))
427428
sai_ck_max_rate = SAI_MAX_SAMPLE_RATE_11K * 256;
428429
else
429430
sai_ck_max_rate = SAI_MAX_SAMPLE_RATE_8K * 256;
430431

431-
if (!sai->sai_mclk && !STM_SAI_PROTOCOL_IS_SPDIF(sai))
432+
if (!sai->sai_mclk && !STM_SAI_PROTOCOL_IS_SPDIF(sai)) {
433+
sai_ck_min_rate = rate * sai->fs_length;
432434
sai_ck_max_rate /= DIV_ROUND_CLOSEST(256, roundup_pow_of_two(sai->fs_length));
435+
}
433436

434437
/*
435438
* 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_sub_data *sai,
472475
/* Try a lower frequency */
473476
div++;
474477
sai_ck_rate = sai_ck_max_rate / div;
475-
} while (sai_ck_rate > rate);
478+
} while (sai_ck_rate >= sai_ck_min_rate);
476479

477480
/* No accurate rate found */
478481
dev_err(&pdev->dev, "Failed to find an accurate rate");

0 commit comments

Comments
 (0)