From: Jarkko Nikula <jarkko.nikula@bitmer.com>
To: Joseph Telaak <joseph@telaak.dev>, Sen Wang <sen@ti.com>,
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-omap@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] ASoC: ti: omap-mcbsp: Implement set_tdm_slot
Date: Tue, 1 Dec 2026 23:22:00 +0200 [thread overview]
Message-ID: <abcd4b07-d108-4c9f-ac63-42a5d2b4a544@bitmer.com> (raw)
In-Reply-To: <20261130-omap-mcbsp-tdm-slot-v3-2-f2ab4752fb03@telaak.dev>
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@telaak.dev>
> ---
> 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?
next prev parent reply other threads:[~2026-12-01 21:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 0:00 [PATCH v3 0/2] ASoC: ti: omap-mcbsp: TDM slots for generic cards Joseph Telaak
2026-12-01 0:00 ` [PATCH v3 1/2] ASoC: ti: omap-mcbsp: Use all 8 bits of CLKGDV Joseph Telaak
2026-12-01 0:01 ` [PATCH v3 2/2] ASoC: ti: omap-mcbsp: Implement set_tdm_slot Joseph Telaak
2026-12-01 21:22 ` Jarkko Nikula [this message]
2026-12-01 22:33 ` Joseph Telaak
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=abcd4b07-d108-4c9f-ac63-42a5d2b4a544@bitmer.com \
--to=jarkko.nikula@bitmer.com \
--cc=broonie@kernel.org \
--cc=joseph@telaak.dev \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=sen@ti.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®