* [PATCH 0/2] ASoC: stm32: sai: fix kernel rate configuration
@ 2025-04-30 16:52 Olivier Moysan
2025-04-30 16:52 ` [PATCH 1/2] ASoC: stm32: sai: skip useless iterations on kernel rate loop Olivier Moysan
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Olivier Moysan @ 2025-04-30 16:52 UTC (permalink / raw)
To: Olivier Moysan, Arnaud Pouliquen, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, Maxime Coquelin, Alexandre Torgue
Cc: linux-sound, linux-stm32, linux-arm-kernel, linux-kernel
This patchset adds some checks on kernel minimum rate requirements.
This avoids potential clock rate misconfiguration, when setting the
kernel frequency on STM32MP2 SoCs.
Olivier Moysan (2):
ASoC: stm32: sai: skip useless iterations on kernel rate loop
ASoC: stm32: sai: add a check on minimal kernel frequency
sound/soc/stm/stm32_sai_sub.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
base-commit: a9bfaf85aaf2dabf541eb7a4895db025d6d8eb1c
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] ASoC: stm32: sai: skip useless iterations on kernel rate loop
2025-04-30 16:52 [PATCH 0/2] ASoC: stm32: sai: fix kernel rate configuration Olivier Moysan
@ 2025-04-30 16:52 ` Olivier Moysan
2025-04-30 23:06 ` Mark Brown
2025-04-30 16:52 ` [PATCH 2/2] ASoC: stm32: sai: add a check on minimal kernel frequency Olivier Moysan
2025-05-01 6:38 ` [PATCH 0/2] ASoC: stm32: sai: fix kernel rate configuration Mark Brown
2 siblings, 1 reply; 5+ messages in thread
From: Olivier Moysan @ 2025-04-30 16:52 UTC (permalink / raw)
To: Olivier Moysan, Arnaud Pouliquen, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, Maxime Coquelin, Alexandre Torgue
Cc: linux-sound, linux-stm32, linux-arm-kernel, linux-kernel
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 <olivier.moysan@foss.st.com>
---
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 = 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;
/*
- * Set maximum expected kernel clock frequency
+ * Set minimum and maximum expected kernel clock frequency
* - mclk on or spdif:
* f_sai_ck = 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 <= 256, to ensure MCKDIV is in available range
* f_sai_ck = sai_ck_max_rate * pow_of_two(FRL) / 256
*/
+ sai_ck_min_rate = rate * 256;
if (!(rate % SAI_RATE_11K))
sai_ck_max_rate = SAI_MAX_SAMPLE_RATE_11K * 256;
else
sai_ck_max_rate = SAI_MAX_SAMPLE_RATE_8K * 256;
- if (!sai->sai_mclk && !STM_SAI_PROTOCOL_IS_SPDIF(sai))
+ if (!sai->sai_mclk && !STM_SAI_PROTOCOL_IS_SPDIF(sai)) {
+ sai_ck_min_rate = rate * sai->fs_length;
sai_ck_max_rate /= DIV_ROUND_CLOSEST(256, roundup_pow_of_two(sai->fs_length));
+ }
/*
* 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,
/* Try a lower frequency */
div++;
sai_ck_rate = sai_ck_max_rate / div;
- } while (sai_ck_rate > rate);
+ } while (sai_ck_rate >= sai_ck_min_rate);
/* No accurate rate found */
dev_err(&pdev->dev, "Failed to find an accurate rate");
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] ASoC: stm32: sai: add a check on minimal kernel frequency
2025-04-30 16:52 [PATCH 0/2] ASoC: stm32: sai: fix kernel rate configuration Olivier Moysan
2025-04-30 16:52 ` [PATCH 1/2] ASoC: stm32: sai: skip useless iterations on kernel rate loop Olivier Moysan
@ 2025-04-30 16:52 ` Olivier Moysan
2025-05-01 6:38 ` [PATCH 0/2] ASoC: stm32: sai: fix kernel rate configuration Mark Brown
2 siblings, 0 replies; 5+ messages in thread
From: Olivier Moysan @ 2025-04-30 16:52 UTC (permalink / raw)
To: Olivier Moysan, Arnaud Pouliquen, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, Maxime Coquelin, Alexandre Torgue
Cc: linux-sound, linux-stm32, linux-arm-kernel, linux-kernel
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 <olivier.moysan@foss.st.com>
---
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 = 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 >= sai_ck_min_rate)
return 0;
/*
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] ASoC: stm32: sai: skip useless iterations on kernel rate loop
2025-04-30 16:52 ` [PATCH 1/2] ASoC: stm32: sai: skip useless iterations on kernel rate loop Olivier Moysan
@ 2025-04-30 23:06 ` Mark Brown
0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2025-04-30 23:06 UTC (permalink / raw)
To: Olivier Moysan
Cc: Arnaud Pouliquen, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Maxime Coquelin, Alexandre Torgue, linux-sound, linux-stm32,
linux-arm-kernel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 195 bytes --]
On Wed, Apr 30, 2025 at 06:52:08PM +0200, Olivier Moysan wrote:
> Fixes: b1d2e4067dc6 ("ASoC: stm32: sai: add stm32mp25 support")
This commit isn't in mainline, I think you meant 2cfe1ff22555.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] ASoC: stm32: sai: fix kernel rate configuration
2025-04-30 16:52 [PATCH 0/2] ASoC: stm32: sai: fix kernel rate configuration Olivier Moysan
2025-04-30 16:52 ` [PATCH 1/2] ASoC: stm32: sai: skip useless iterations on kernel rate loop Olivier Moysan
2025-04-30 16:52 ` [PATCH 2/2] ASoC: stm32: sai: add a check on minimal kernel frequency Olivier Moysan
@ 2025-05-01 6:38 ` Mark Brown
2 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2025-05-01 6:38 UTC (permalink / raw)
To: Arnaud Pouliquen, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Maxime Coquelin, Alexandre Torgue, Olivier Moysan
Cc: linux-sound, linux-stm32, linux-arm-kernel, linux-kernel
On Wed, 30 Apr 2025 18:52:07 +0200, Olivier Moysan wrote:
> This patchset adds some checks on kernel minimum rate requirements.
> This avoids potential clock rate misconfiguration, when setting the
> kernel frequency on STM32MP2 SoCs.
>
> Olivier Moysan (2):
> ASoC: stm32: sai: skip useless iterations on kernel rate loop
> ASoC: stm32: sai: add a check on minimal kernel frequency
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/2] ASoC: stm32: sai: skip useless iterations on kernel rate loop
commit: edea92770a3b6454dc796fc5436a3315bb402181
[2/2] ASoC: stm32: sai: add a check on minimal kernel frequency
commit: cce34d113e2a592806abcdc02c7f8513775d8b20
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-01 6:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 16:52 [PATCH 0/2] ASoC: stm32: sai: fix kernel rate configuration Olivier Moysan
2025-04-30 16:52 ` [PATCH 1/2] ASoC: stm32: sai: skip useless iterations on kernel rate loop Olivier Moysan
2025-04-30 23:06 ` Mark Brown
2025-04-30 16:52 ` [PATCH 2/2] ASoC: stm32: sai: add a check on minimal kernel frequency Olivier Moysan
2025-05-01 6:38 ` [PATCH 0/2] ASoC: stm32: sai: fix kernel rate configuration Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox