From fc2fc96d1b382b4b2dbbb9190cba75c8b7827416 Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Fri, 22 Mar 2024 17:28:05 +0200 Subject: [PATCH 1/3] tools: topology1: imx8ulp: rename `RATE` to `FSYNC_RATE` Rename the `RATE` parameter to `FSYNC_RATE` in order to remove ambiguity regarding what the parameter is. Signed-off-by: Laurentiu Mihalcea --- tools/topology/topology1/CMakeLists.txt | 8 ++++---- tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 | 6 +++--- tools/topology/topology1/sof-imx8ulp-btsco.m4 | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/topology/topology1/CMakeLists.txt b/tools/topology/topology1/CMakeLists.txt index 8869a8bd7d1b..348c6e927630 100644 --- a/tools/topology/topology1/CMakeLists.txt +++ b/tools/topology/topology1/CMakeLists.txt @@ -59,10 +59,10 @@ set(TPLGS ## end i.MX8MP topologies ## i.MX8ULP topologies - "sof-imx8ulp-btsco\;sof-imx8ulp-btsco\;-DRATE=8000" - "sof-imx8ulp-btsco\;sof-imx8ulp-btsco-16k\;-DRATE=16000" - "sof-imx8ulp-9x9-btsco\;sof-imx8ulp-9x9-btsco\;-DRATE=8000" - "sof-imx8ulp-9x9-btsco\;sof-imx8ulp-9x9-btsco-16k\;-DRATE=16000" + "sof-imx8ulp-btsco\;sof-imx8ulp-btsco\;-DFSYNC_RATE=8000" + "sof-imx8ulp-btsco\;sof-imx8ulp-btsco-16k\;-DFSYNC_RATE=16000" + "sof-imx8ulp-9x9-btsco\;sof-imx8ulp-9x9-btsco\;-DFSYNC_RATE=8000" + "sof-imx8ulp-9x9-btsco\;sof-imx8ulp-9x9-btsco-16k\;-DFSYNC_RATE=16000" ## end i.MX8ULP topologies ## i.MX93 topologies diff --git a/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 b/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 index c641942c571f..3d21c2cfca24 100644 --- a/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 +++ b/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 @@ -39,14 +39,14 @@ dnl time_domain, sched_comp) PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, 1, 0, 1, s16le, 1000, 0, 0, - `RATE', `RATE', `RATE') + `FSYNC_RATE', `FSYNC_RATE', `FSYNC_RATE') # Low Latency capture pipeline 2 on PCM 0 using max 1 channels of s16le. # Set 1000us deadline with priority 0 on core 0 PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, 2, 0, 1, s16le, 1000, 0, 0, - `RATE', `RATE', `RATE') + `FSYNC_RATE', `FSYNC_RATE', `FSYNC_RATE') # # DAIs configuration # @@ -79,6 +79,6 @@ 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(fsync, `RATE', 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 b9570a0025dc..b644f8250d75 100644 --- a/tools/topology/topology1/sof-imx8ulp-btsco.m4 +++ b/tools/topology/topology1/sof-imx8ulp-btsco.m4 @@ -39,14 +39,14 @@ dnl time_domain, sched_comp) PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, 1, 0, 1, s16le, 1000, 0, 0, - `RATE', `RATE', `RATE') + `FSYNC_RATE', `FSYNC_RATE', `FSYNC_RATE') # Low Latency capture pipeline 2 on PCM 0 using max 1 channels of s16le. # Set 1000us deadline with priority 0 on core 0 PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, 2, 0, 1, s16le, 1000, 0, 0, - `RATE', `RATE', `RATE') + `FSYNC_RATE', `FSYNC_RATE', `FSYNC_RATE') # # DAIs configuration @@ -80,6 +80,6 @@ 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(fsync, `RATE', codec_consumer), + SAI_CLOCK(fsync, `FSYNC_RATE', codec_consumer), SAI_TDM(1, 16, 1, 1), SAI_CONFIG_DATA(SAI, 5, 0))) From 54c2d852457ca2a0092f831b4f14e8e34cebd2d6 Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Fri, 15 Mar 2024 15:13:23 +0200 Subject: [PATCH 2/3] 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 3d21c2cfca24..95edce40aaa1 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 b644f8250d75..a99ec58e4f7f 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))) From 409333f9f4e46d2f5f0ae0c891b46f30639777b3 Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Fri, 22 Mar 2024 13:37:58 +0200 Subject: [PATCH 3/3] tools: topology1: imx8ulp: change protocol and BCLK polarity The BT codec used by the IW416 chip expects FSYNC to be asserted for only one BCLK. Also, FSYNC should be active HIGH. As such, change from I2S protocol to DSP_A protocol since the configurations made for this protocol inside the SAI driver are more suited. Also, by default, the BT codec drives data on BCLK rising edge and samples it on falling edge. With the DSP_A protocol, the SAI driver also has the same configuration, which is wrong since we can't drive and sample on the same edge and cycle. As such, invert BCLK polarity such that the SAI will drive on rising edge and sample on falling edge. Signed-off-by: Laurentiu Mihalcea --- tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 | 4 ++-- tools/topology/topology1/sof-imx8ulp-btsco.m4 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 b/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 index 95edce40aaa1..118579d19fc8 100644 --- a/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 +++ b/tools/topology/topology1/sof-imx8ulp-9x9-btsco.m4 @@ -88,8 +88,8 @@ PCM_DUPLEX_ADD(Port0, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) # 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, `eval(FSYNC_RATE * 16)', codec_consumer), + SAI_CONFIG(DSP_A, SAI_CLOCK(mclk, 12288000, codec_mclk_out), + SAI_CLOCK(bclk, `eval(FSYNC_RATE * 16)', codec_consumer, inverted), 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 a99ec58e4f7f..4c14910f88e4 100644 --- a/tools/topology/topology1/sof-imx8ulp-btsco.m4 +++ b/tools/topology/topology1/sof-imx8ulp-btsco.m4 @@ -89,8 +89,8 @@ PCM_DUPLEX_ADD(Port0, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) # 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, `eval(FSYNC_RATE * 16)', codec_consumer), + SAI_CONFIG(DSP_A, SAI_CLOCK(mclk, 12288000, codec_mclk_out), + SAI_CLOCK(bclk, `eval(FSYNC_RATE * 16)', codec_consumer, inverted), SAI_CLOCK(fsync, `FSYNC_RATE', codec_consumer), SAI_TDM(1, 16, 1, 1), SAI_CONFIG_DATA(SAI, 5, 0)))