From: Val Packett <val@packett.cool>
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: Val Packett <val@packett.cool>,
Bhushan Shah <bhushan.shah@machinesoul.in>,
Luca Weiss <luca.weiss@fairphone.com>,
Antoine Bernard <zalnir@proton.me>,
~postmarketos/upstreaming@lists.sr.ht,
phone-devel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 4/6] ASoC: qcom: sm8250: add TDM RX support
Date: Thu, 23 Apr 2026 01:41:04 -0300 [thread overview]
Message-ID: <20260423050801.210840-6-val@packett.cool> (raw)
In-Reply-To: <20260423050801.210840-2-val@packett.cool>
Add support for TDM RX DAIs which are used on some devices to send audio
data to speaker amplifiers.
Signed-off-by: Val Packett <val@packett.cool>
---
This is mostly just based on sdm845.c.
Is SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_DSP_B correct?
Who actually decides these, or does this file arbitrarily dictate them?
sdm845 also has some snd_soc_dai_set_tdm_slot(codec_dai, ..) calls
with "magic" constants like SPK_TDM_RX_MASK == 0x03 which seem to be
probably specific to the first external codec that was used on an
sdm845 device? So I didn't copy that, but I'm still curious as to
what even that is.
---
sound/soc/qcom/sm8250.c | 115 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 115 insertions(+)
diff --git a/sound/soc/qcom/sm8250.c b/sound/soc/qcom/sm8250.c
index a675913da943..ab1ba44baffb 100644
--- a/sound/soc/qcom/sm8250.c
+++ b/sound/soc/qcom/sm8250.c
@@ -17,6 +17,9 @@
#include "sdw.h"
#define MI2S_BCLK_RATE 1536000
+#define TDM_BCLK_RATE 6144000
+
+static unsigned int tdm_slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
struct sm8250_snd_data {
bool stream_prepared[AFE_PORT_MAX];
@@ -55,6 +58,64 @@ static void sm8250_snd_exit(struct snd_soc_pcm_runtime *rtd)
}
+static int sm8250_tdm_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 ret = 0;
+ int channels, slot_width;
+
+ switch (params_format(params)) {
+ case SNDRV_PCM_FORMAT_S16_LE:
+ slot_width = 16;
+ break;
+ default:
+ dev_err(rtd->dev, "%s: invalid param format 0x%x\n",
+ __func__, params_format(params));
+ return -EINVAL;
+ }
+
+ channels = params_channels(params);
+
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, 0x3,
+ 8, slot_width);
+ if (ret < 0) {
+ dev_err(rtd->dev, "%s: failed to set tdm slot, err:%d\n",
+ __func__, ret);
+ goto end;
+ }
+
+ ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
+ channels, tdm_slot_offset);
+ if (ret < 0) {
+ dev_err(rtd->dev, "%s: failed to set channel map, err:%d\n",
+ __func__, ret);
+ goto end;
+ }
+ } else {
+ ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xf, 0,
+ 8, slot_width);
+ if (ret < 0) {
+ dev_err(rtd->dev, "%s: failed to set tdm slot, err:%d\n",
+ __func__, ret);
+ goto end;
+ }
+
+ ret = snd_soc_dai_set_channel_map(cpu_dai, channels,
+ tdm_slot_offset, 0, NULL);
+ if (ret < 0) {
+ dev_err(rtd->dev, "%s: failed to set channel map, err:%d\n",
+ __func__, ret);
+ goto end;
+ }
+ }
+
+end:
+ return ret;
+}
+
static int sm8250_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params)
{
@@ -120,6 +181,41 @@ static int sm8250_snd_startup(struct snd_pcm_substream *substream)
snd_soc_dai_set_fmt(cpu_dai, fmt);
snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
break;
+ case PRIMARY_TDM_RX_0:
+ codec_dai_fmt |= SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_DSP_B;
+ snd_soc_dai_set_sysclk(cpu_dai,
+ Q6AFE_LPASS_CLK_ID_PRI_TDM_IBIT,
+ TDM_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
+ snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
+ break;
+ case SECONDARY_TDM_RX_0:
+ codec_dai_fmt |= SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_DSP_B;
+ snd_soc_dai_set_sysclk(cpu_dai,
+ Q6AFE_LPASS_CLK_ID_SEC_TDM_IBIT,
+ TDM_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
+ snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
+ break;
+ case TERTIARY_TDM_RX_0:
+ codec_dai_fmt |= SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_DSP_B;
+ snd_soc_dai_set_sysclk(cpu_dai,
+ Q6AFE_LPASS_CLK_ID_TER_TDM_IBIT,
+ TDM_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
+ snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
+ break;
+ case QUATERNARY_TDM_RX_0:
+ codec_dai_fmt |= SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_DSP_B;
+ snd_soc_dai_set_sysclk(cpu_dai,
+ Q6AFE_LPASS_CLK_ID_QUAD_TDM_IBIT,
+ TDM_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
+ snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
+ break;
+ case QUINARY_TDM_RX_0:
+ codec_dai_fmt |= SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_DSP_B;
+ snd_soc_dai_set_sysclk(cpu_dai,
+ Q6AFE_LPASS_CLK_ID_QUIN_TDM_IBIT,
+ TDM_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
+ snd_soc_dai_set_fmt(codec_dai, codec_dai_fmt);
+ break;
default:
break;
}
@@ -145,10 +241,29 @@ static int sm8250_snd_hw_free(struct snd_pcm_substream *substream)
return qcom_snd_sdw_hw_free(substream, &data->stream_prepared[cpu_dai->id]);
}
+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 ret = 0;
+
+ switch (cpu_dai->id) {
+ case PRIMARY_TDM_RX_0...QUINARY_TDM_TX_7:
+ ret = sm8250_tdm_snd_hw_params(substream, params);
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
static const struct snd_soc_ops sm8250_be_ops = {
.startup = sm8250_snd_startup,
.shutdown = qcom_snd_sdw_shutdown,
.hw_free = sm8250_snd_hw_free,
+ .hw_params = sm8250_snd_hw_params,
.prepare = sm8250_snd_prepare,
};
--
2.53.0
next prev parent reply other threads:[~2026-04-23 5:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 4:41 [PATCH 0/6] ASoC: qcom: fixes and improvements Val Packett
2026-04-23 4:41 ` [PATCH 1/6] ASoC: qcom: qdsp6: q6afe: fix clk vote response type mismatch Val Packett
2026-04-23 6:11 ` Luca Weiss
2026-04-24 19:57 ` Val Packett
2026-04-27 12:06 ` Srinivas Kandagatla
2026-04-23 4:41 ` [PATCH 2/6] ASoC: qcom: qdsp6: q6routing: add Senary MI2S ports Val Packett
2026-04-23 4:41 ` [PATCH 3/6] ASoC: qcom: sm8250: add Senary MI2S RX support Val Packett
2026-04-23 4:41 ` Val Packett [this message]
2026-04-23 4:41 ` [PATCH 5/6] ASoC: qcom: sm8250: shut down MI2S/TDM AFE port clocks Val Packett
2026-04-23 4:41 ` [PATCH 6/6] ASoC: qcom: sm8250: apply codec_fmt to all codec DAIs Val Packett
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=20260423050801.210840-6-val@packett.cool \
--to=val@packett.cool \
--cc=bhushan.shah@machinesoul.in \
--cc=broonie@kernel.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=luca.weiss@fairphone.com \
--cc=perex@perex.cz \
--cc=phone-devel@vger.kernel.org \
--cc=srini@kernel.org \
--cc=tiwai@suse.com \
--cc=zalnir@proton.me \
--cc=~postmarketos/upstreaming@lists.sr.ht \
/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