[PATCH 3/6] ASoC: qcom: sm8250: support 32-bit MI2S slots

From: Riccardo Mereu

Date: Tue Dec 01 2026 - 08:12:38 EST


From: Riccardo Mereu <r.mereu@xxxxxxxxxx>

The MI2S backends always run at S16_LE with the bit clock fixed at
MI2S_BCLK_RATE (1.536 MHz), which only fits 48 kHz, 2 channels and
16-bit slots. That does not work for every codec: the ANX7625 DP bridge
on QRB2210 boards has its I2S channel length fixed to 32 bits, so it
needs 32-bit slots and twice the bit clock.

Board compatibles cannot carry this: the Qualcomm RB1 uses the same
qcom,qrb2210-sndcard with an LT9611 HDMI bridge on the same port, at
S16_LE. Take the setting from the dai-link node instead: with
dai-tdm-slot-width = <32> in the cpu node, the backend runs at S32_LE.
The DSP sizes the slots from the sample width, so this gives 32-bit
slots. An S16_LE front end goes out MSB first at the top of each slot,
which is the standard I2S layout.

Set the bit clock in hw_params from the rate, the physical sample width
and the channel count, instead of the fixed value at startup, and map
each MI2S DAI to its IBIT clock in one helper, so startup does not
repeat the same block for every port. Without the property, every
current user still runs at S16_LE and 1.536 MHz.

Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@xxxxxxxxxxxxxxxx>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@xxxxxxxxxxxxxxxx>
Signed-off-by: Riccardo Mereu <r.mereu@xxxxxxxxxx>
---
sound/soc/qcom/sm8250.c | 114 ++++++++++++++++++++--------------------
1 file changed, 56 insertions(+), 58 deletions(-)

diff --git a/sound/soc/qcom/sm8250.c b/sound/soc/qcom/sm8250.c
index d0015e5f5257..c4edceb71443 100644
--- a/sound/soc/qcom/sm8250.c
+++ b/sound/soc/qcom/sm8250.c
@@ -16,8 +16,6 @@
#include "usb_offload_utils.h"
#include "sdw.h"

-#define MI2S_BCLK_RATE 1536000
-
struct sm8250_snd_data {
bool stream_prepared[AFE_PORT_MAX];
struct snd_soc_card *card;
@@ -65,6 +63,28 @@ static void sm8250_snd_exit(struct snd_soc_pcm_runtime *rtd)

}

+static int sm8250_mi2s_bclk_id(int dai_id)
+{
+ switch (dai_id) {
+ case PRIMARY_MI2S_RX:
+ return Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT;
+ case SECONDARY_MI2S_RX:
+ return Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT;
+ case TERTIARY_MI2S_RX:
+ return Q6AFE_LPASS_CLK_ID_TER_MI2S_IBIT;
+ case QUINARY_MI2S_RX:
+ return Q6AFE_LPASS_CLK_ID_QUI_MI2S_IBIT;
+ case SENARY_MI2S_RX:
+ return Q6AFE_LPASS_CLK_ID_SEN_MI2S_IBIT;
+ case LPI_MI2S_RX_0:
+ return Q6AFE_LPASS_CLK_ID_INT0_MI2S_IBIT;
+ case LPI_MI2S_TX_3:
+ return Q6AFE_LPASS_CLK_ID_INT3_MI2S_IBIT;
+ default:
+ return -EINVAL;
+ }
+}
+
static int sm8250_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params)
{
@@ -73,11 +93,24 @@ static int sm8250_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_interval *channels = hw_param_interval(params,
SNDRV_PCM_HW_PARAM_CHANNELS);
struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
+ struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+ struct qcom_snd_tdm_slot_cfg cpu_cfg, codec_cfg;

rate->min = rate->max = 48000;
channels->min = channels->max = 2;
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);

+ /*
+ * The DSP sizes the MI2S slots from the sample width, so run the
+ * backend at S32_LE when the board asks for 32-bit slots.
+ */
+ if (sm8250_mi2s_bclk_id(cpu_dai->id) >= 0 &&
+ !qcom_snd_get_dai_tdm_slots(rtd, &cpu_cfg, &codec_cfg) &&
+ cpu_cfg.slot_width == 32) {
+ snd_mask_none(fmt);
+ snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
+ }
+
return 0;
}

@@ -89,70 +122,34 @@ static int sm8250_snd_startup(struct snd_pcm_substream *substream)
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);

- switch (cpu_dai->id) {
- case PRIMARY_MI2S_RX:
- codec_dai_fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S;
- snd_soc_dai_set_sysclk(cpu_dai,
- Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT,
- MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
- snd_soc_dai_set_fmt(cpu_dai, fmt);
- snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
- break;
- case SECONDARY_MI2S_RX:
- codec_dai_fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S;
- snd_soc_dai_set_sysclk(cpu_dai,
- Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT,
- MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
- snd_soc_dai_set_fmt(cpu_dai, fmt);
- snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
- break;
- case TERTIARY_MI2S_RX:
+ if (sm8250_mi2s_bclk_id(cpu_dai->id) >= 0) {
codec_dai_fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S;
- snd_soc_dai_set_sysclk(cpu_dai,
- Q6AFE_LPASS_CLK_ID_TER_MI2S_IBIT,
- MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
snd_soc_dai_set_fmt(cpu_dai, fmt);
snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
- break;
- case QUINARY_MI2S_RX:
- codec_dai_fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S;
- snd_soc_dai_set_sysclk(cpu_dai,
- Q6AFE_LPASS_CLK_ID_QUI_MI2S_IBIT,
- MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
- snd_soc_dai_set_fmt(cpu_dai, fmt);
- snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
- break;
- case SENARY_MI2S_RX:
- codec_dai_fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S;
- snd_soc_dai_set_sysclk(cpu_dai,
- Q6AFE_LPASS_CLK_ID_SEN_MI2S_IBIT,
- MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
- snd_soc_dai_set_fmt(cpu_dai, fmt);
- snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
- break;
- case LPI_MI2S_RX_0:
- codec_dai_fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S;
- snd_soc_dai_set_sysclk(cpu_dai,
- Q6AFE_LPASS_CLK_ID_INT0_MI2S_IBIT,
- MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
- snd_soc_dai_set_fmt(cpu_dai, fmt);
- snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
- break;
- case LPI_MI2S_TX_3:
- codec_dai_fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_I2S;
- snd_soc_dai_set_sysclk(cpu_dai,
- Q6AFE_LPASS_CLK_ID_INT3_MI2S_IBIT,
- MI2S_BCLK_RATE, SNDRV_PCM_STREAM_CAPTURE);
- snd_soc_dai_set_fmt(cpu_dai, fmt);
- snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
- break;
- default:
- break;
}

return qcom_snd_sdw_startup(substream);
}

+static int sm8250_snd_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
+ struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+ int clk_id, bclk;
+
+ clk_id = sm8250_mi2s_bclk_id(cpu_dai->id);
+ if (clk_id < 0)
+ return 0;
+
+ /* The DSP clocks out whole slots, so use the physical sample width */
+ bclk = snd_soc_calc_bclk(params_rate(params),
+ params_physical_width(params),
+ params_channels(params), 1);
+
+ return snd_soc_dai_set_sysclk(cpu_dai, clk_id, bclk, substream->stream);
+}
+
static int sm8250_snd_prepare(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
@@ -173,6 +170,7 @@ static int sm8250_snd_hw_free(struct snd_pcm_substream *substream)

static const struct snd_soc_ops sm8250_be_ops = {
.startup = sm8250_snd_startup,
+ .hw_params = sm8250_snd_hw_params,
.shutdown = qcom_snd_sdw_shutdown,
.hw_free = sm8250_snd_hw_free,
.prepare = sm8250_snd_prepare,
--
2.56.1


--





Privacy and Confidentiality Notice: This email and all attachments are
confidential and for the designated recipient(s) only. They may also be
privileged. If you are not the intended recipient or among the intended
recipients, you may not use, read, retransmit, disseminate, store/copy the
information in any medium or take any action in reliance upon it. Please
notify the sender that you have received it in error and immediately delete
the entire communication, including any attachments.