From bbd20a97666fb1091f1aa6e5dcdd5cb2c25b5e6e Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Fri, 15 Mar 2024 15:13:23 +0200 Subject: [PATCH] tools: topology1: imx8ulp: correct BCLK frequency 8ULP has two supported BT HFP scenarios: NBS and WBS. For NBS the frequency of FSYNC is 8k, while for WBS the frequency of FSYNC is 16k. Since the BCLK is computed as: Freq(BCLK) = TDM_SLOTS * TDM_SLOT_WIDTH * Freq(FSYNC) then that means we're going to end up with two different BCLK frequencies (one for each supported scenario). Currently, what we do is pass the frequency of FSYNC as a build argument, while keeping the frequency of BCLK constant (set to 256000, which would be the same value as the one used in WBS). This causes the following issues: 1) The Zephyr native SAI driver returns an error when trying to commit the configuration because the frequency of BCLK doesn't abide by the aforementioned formula. 2) We end up consuming twice as many samples in a given unit of time. To fix these issues, use the aforementioned formula to compute the frequency of BCLK. Signed-off-by: Laurentiu Mihalcea --- tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 | 13 ++++++++++++- tools/topology/topology1/sof-imx8ulp-btsco.m4 | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 b/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 index 3d21c2cfc..95edce40a 100644 --- a/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 +++ b/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 @@ -75,10 +75,21 @@ DAI_ADD(sof/pipe-dai-capture.m4, dnl PCM_DUPLEX_ADD(name, pcm_id, playback, capture) PCM_DUPLEX_ADD(Port0, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) +# BCLK frequency is computed using the following formula: +# Freq(BCLK) = Freq(FSYNC) * TDM_SLOTS * TDM_SLOT_WIDTH +# +# For 8ULP this yields the following frequencies +# (based on supported BT HFP configurations): +# +# 1) NBS (Freq(FSYNC) = 8k) +# Freq(BCLK) = 8k * 16 * 1 = 128000 +# +# 2) WBS (Freq(FSYNC) = 16k) +# Freq(BCLK) = 16k * 16 * 1 = 256000 dnl DAI_CONFIG(type, idx, link_id, name, sai_config) DAI_CONFIG(SAI, 6, 0, sai6-bt-sco-pcm-wb, SAI_CONFIG(I2S, SAI_CLOCK(mclk, 12288000, codec_mclk_out), - SAI_CLOCK(bclk, 256000, codec_consumer), + SAI_CLOCK(bclk, `eval(FSYNC_RATE * 16)', codec_consumer), SAI_CLOCK(fsync, `FSYNC_RATE', codec_consumer), SAI_TDM(1, 16, 1, 1), SAI_CONFIG_DATA(SAI, 6, 0))) diff --git a/tools/topology/topology1/sof-imx8ulp-btsco.m4 b/tools/topology/topology1/sof-imx8ulp-btsco.m4 index b644f8250..a99ec58e4 100644 --- a/tools/topology/topology1/sof-imx8ulp-btsco.m4 +++ b/tools/topology/topology1/sof-imx8ulp-btsco.m4 @@ -76,10 +76,21 @@ DAI_ADD(sof/pipe-dai-capture.m4, dnl PCM_DUPLEX_ADD(name, pcm_id, playback, capture) PCM_DUPLEX_ADD(Port0, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) +# BCLK frequency is computed using the following formula: +# Freq(BCLK) = Freq(SYNC) * TDM_SLOTS * TDM_SLOT_WIDTH +# +# For 8ULP this yields the following frequencies (based on +# supported BT HFP configurations): +# +# 1) NBS (Freq(FSYNC) = 8k) +# Freq(BCLK) = 8k * 16 * 1 = 128000 +# +# 2) WBS (Freq(FSYNC) = 16k) +# Freq(BCLK) = 16k * 16 * 1 = 256000 dnl DAI_CONFIG(type, idx, link_id, name, sai_config) DAI_CONFIG(SAI, 5, 0, sai5-bt-sco-pcm-wb, SAI_CONFIG(I2S, SAI_CLOCK(mclk, 12288000, codec_mclk_out), - SAI_CLOCK(bclk, 256000, codec_consumer), + SAI_CLOCK(bclk, `eval(FSYNC_RATE * 16)', codec_consumer), SAI_CLOCK(fsync, `FSYNC_RATE', codec_consumer), SAI_TDM(1, 16, 1, 1), SAI_CONFIG_DATA(SAI, 5, 0)))