Re: [PATCH v3 2/2] ASoC: ti: omap-mcbsp: Implement set_tdm_slot

From: Jarkko Nikula

Date: Tue Dec 01 2026 - 16:22:30 EST


Hi

On 12/1/26 2:01 AM, Joseph Telaak wrote:
As bit clock and frame provider, McBSP sizes the frame from the SRG
input, the set_clkdiv() divider and the rate. Only a machine driver can
call set_clkdiv(), so with simple-audio-card or audio-graph-card the
divider stays 1 and the bit clock runs at the full SRG input: 96 MHz on
OMAP3, a 2000-bit frame at 48 kHz.

Implement set_tdm_slot() so these cards can ask for a frame of slots x
slot_width bit clocks with dai-tdm-slot-num and dai-tdm-slot-width.
hw_params() then picks the divider for the rate. McBSP sends a frame's
words back to back, so a sample must fill its slot and the channels fill
the active slots, which must be the low ones. Both directions share the
frame, so non-empty TX and RX masks need the same number of slots, and
I2S or left-justified need two slots. Slots McBSP can't do are refused
when they are set, and a slot count I2S can't use at open. As clock
consumer, the slots are checked but have no effect.

startup() pins the channels and sample width to the slots. If the sysclk
was set outside a stream, as simple-audio-card does at init, it also
limits the rates to those the sysclk divides to within 0.1%, the IEC
60958 level II clock tolerance. hw_params() checks the stream against
the slots and the sysclk, including one a card sets in hw_params(). With
the SRG on CLKS, the fclk mux on OMAP2 and later, the sysclk must be
that clock's rate: McBSP has no MCLK output, so simple-card's mclk-fs,
which passes rate x fs, is refused instead of giving a wrong bit clock.
This is checked in hw_params(), not in set_dai_sysclk():
simple-audio-card sets the sysclk before the format and the slots.

Both directions share the sample rate generator: once a stream is
configured, until its hw_free(), the other direction must use the same
rate and the sysclk can't change, not even for that stream's next
hw_params(). Otherwise a stream on its own reprograms McBSP on each
hw_params(). The slots can't change while McBSP is configured. This
applies only when McBSP provides both clocks from the SRG, which is why
the core's symmetric_rate isn't used: as clock consumer, the directions
can run at different rates. Without slots nothing changes.

Tested on an OMAP3630 board whose McBSP4 drives the I2S input of an
ADV7513 with no MCLK, with 2 x 32-bit slots and adv7511 taking S32_LE: a
left-only and a right-only 44.1 kHz tone each play on their own side (96
MHz / 34 gives 44117.6 Hz). 48 kHz (0.8% off), S16_LE and mono are
refused, and plughw converts them. With simple-audio-card,mclk-fs set to
256, hw_params() refuses the 11.2896 and 12.288 MHz sysclks.

Signed-off-by: Joseph Telaak <joseph@xxxxxxxxxx>
---
sound/soc/ti/omap-mcbsp-priv.h | 10 ++
sound/soc/ti/omap-mcbsp.c | 348 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 354 insertions(+), 4 deletions(-)

diff --git a/sound/soc/ti/omap-mcbsp-priv.h b/sound/soc/ti/omap-mcbsp-priv.h
index 324c5d7d431d..621bb4d17879 100644
--- a/sound/soc/ti/omap-mcbsp-priv.h
+++ b/sound/soc/ti/omap-mcbsp-priv.h
@@ -275,6 +275,16 @@ struct omap_mcbsp {
unsigned int latency[2];
int clk_div;
int wlen;
+ unsigned int slots;
+ unsigned int slot_width;
+ unsigned int tx_slots;
+ unsigned int rx_slots;
+ /* Rate the slots were configured for */
+ unsigned int slot_rate;
+ /* Directions configured with slots, BIT(stream) */
+ unsigned int slot_streams;
+ /* in_freq was set outside a stream */
+ bool sysclk_static;
struct pm_qos_request pm_qos_req;
};
diff --git a/sound/soc/ti/omap-mcbsp.c b/sound/soc/ti/omap-mcbsp.c
index 6e0c7d7359f4..3e74a367dd76 100644
--- a/sound/soc/ti/omap-mcbsp.c
+++ b/sound/soc/ti/omap-mcbsp.c
...
+/*
+ * The sysclk the SRG divides, or 0 if it isn't usable. From CLKS, the fclk
+ * mux on OMAP2+, it must be that clock's rate: McBSP has no MCLK output, and
+ * simple-card's mclk-fs passes rate x fs. Other SRG inputs are taken as set.
+ */
+static unsigned int omap_mcbsp_slot_sysclk(struct omap_mcbsp *mcbsp)
+{
+ struct omap_mcbsp_reg_cfg *regs = &mcbsp->cfg_regs;
+ unsigned long fclk = clk_get_rate(mcbsp->fclk);
+
+ if (!mcbsp_omap1() && !(regs->srgr2 & CLKSM) &&
+ !(regs->pcr0 & SCLKME) && fclk && mcbsp->in_freq != fclk)
+ return 0;
+
+ return mcbsp->in_freq;
+}
I think more cleaner would be to store clk_id in omap_mcbsp_dai_set_dai_sysclk() as omap1 is already validated there and no need to check these register bits here.

+
+/*
+ * Slots only apply when McBSP provides the bit clock and the frame, and
+ * drives both bit clock pins from the SRG
+ */
+static bool omap_mcbsp_slots_on(struct omap_mcbsp *mcbsp)
+{
+ return mcbsp->slot_width &&
+ (mcbsp->fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) ==
+ SND_SOC_DAIFMT_BP_FP &&
+ (mcbsp->cfg_regs.pcr0 & (CLKXM | CLKRM)) == (CLKXM | CLKRM);
+}
Is CLKXM | CLKRM test needed? Those should be set when the mcbsp->fmt has SND_SOC_DAIFMT_BP_FP?