From: Riccardo Mereu <r.mereu.kernel@arduino.cc>
To: Srinivas Kandagatla <srini@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>
Cc: linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org,
dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, Riccardo Mereu <r.mereu@arduino.cc>,
Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Subject: [PATCH 3/6] ASoC: qcom: sm8250: support 32-bit MI2S slots
Date: Tue, 1 Dec 2026 14:12:06 +0100 [thread overview]
Message-ID: <20261201131212.161224-4-r.mereu.kernel@arduino.cc> (raw)
In-Reply-To: <20261201131212.161224-1-r.mereu.kernel@arduino.cc>
From: Riccardo Mereu <r.mereu@arduino.cc>
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@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Signed-off-by: Riccardo Mereu <r.mereu@arduino.cc>
---
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.
next prev parent reply other threads:[~2026-12-01 13:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 13:12 [PATCH 0/6] arm64: qcom: Arduino UNO Q: DisplayPort audio playback Riccardo Mereu
2026-12-01 13:12 ` [PATCH 1/6] ASoC: qcom: common: setup fe dais before be dais Riccardo Mereu
2026-12-01 13:12 ` [PATCH 2/6] ASoC: codecs: pm4125: add compander channels to the RX channel table Riccardo Mereu
2026-12-01 13:12 ` Riccardo Mereu [this message]
2026-12-01 13:12 ` [PATCH 4/6] dt-bindings: display: bridge: analogix,anx7625: add #sound-dai-cells Riccardo Mereu
2026-12-01 13:12 ` [PATCH 5/6] drm/bridge: anx7625: accept 32-bit I2S sample width Riccardo Mereu
2026-12-01 13:12 ` [PATCH 6/6] arm64: dts: qcom: qrb2210-arduino-imola: add DP audio playback Riccardo Mereu
2026-12-01 14:29 ` Konrad Dybcio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201131212.161224-4-r.mereu.kernel@arduino.cc \
--to=r.mereu.kernel@arduino.cc \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=r.mereu@arduino.cc \
--cc=srini@kernel.org \
--cc=srinivas.kandagatla@oss.qualcomm.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®