[PATCH 0/3] ASoC: add shared BCLK rate constraint for cross-DAI coordination
Troy Mitchell
troy.mitchell at linux.spacemit.com
Thu Apr 30 00:46:00 PDT 2026
On some SoCs (e.g. SpacemiT K3), multiple I2S controllers share the
same physical BCLK. When one controller is already streaming, the
others must use hw_params that result in the same BCLK rate, otherwise
the shared clock would be reconfigured and corrupt the active stream.
This series adds framework-level support for this constraint:
Patch 1 adds a bclk field and bclk_ratio to struct snd_soc_dai, plus
a helper snd_soc_dai_set_bclk_clk() for platform drivers to declare
their BCLK clock. It also caches the ratio in the existing
snd_soc_dai_set_bclk_ratio() so the framework can use it for TDM
configurations.
Patch 2 adds the constraint logic in soc-pcm.c. During PCM open,
every DAI that has a bclk clock pointer gets a hw_rule registered
unconditionally. The rule callback runs at hw_refine time: it scans
the card for an active peer sharing the same physical BCLK (via
clk_is_match()) that has already completed hw_params, then constrains
the current stream's rate to match the established BCLK rate. The
first DAI to complete hw_params is unconstrained; subsequent DAIs
must match. Two modes are supported:
- Default (I2S): BCLK = rate * channels * sample_bits. The rule
derives the valid rate range from the current channel and
sample_bits intervals.
- Explicit ratio (TDM): if the driver sets dai->bclk_ratio
(e.g. slots * slot_width), the rule computes the single valid
rate as active_bclk_rate / bclk_ratio.
Patch 3 wires up the SpacemiT K1/K3 I2S driver: a single call to
snd_soc_dai_set_bclk_clk(dai, i2s->c_bclk) in the DAI probe. On SoCs
where the BCLK is not shared (c_bclk is NULL from
devm_clk_get_optional_enabled), the rule is a no-op. On K3, multiple
I2S instances share the same c_bclk, and the framework automatically
constrains their rates.
This series was prompted by review feedback on the SpacemiT K3 I2S
series, where a vendor-specific fixed-sample-rate property was rejected
in favor of a generic framework solution:
https://lore.kernel.org/all/afFqgF6ZRwYdfUmL@sirena.co.uk/
Signed-off-by: Troy Mitchell <troy.mitchell at linux.spacemit.com>
---
Troy Mitchell (3):
ASoC: soc-dai: add shared BCLK clock for cross-DAI rate constraints
ASoC: soc-pcm: constrain hw_params when DAIs share the same BCLK
ASoC: spacemit: declare shared BCLK for cross-DAI rate constraint
include/sound/soc-dai.h | 7 +++
sound/soc/soc-dai.c | 17 +++++++
sound/soc/soc-pcm.c | 113 ++++++++++++++++++++++++++++++++++++++++++++
sound/soc/spacemit/k1_i2s.c | 2 +
4 files changed, 139 insertions(+)
---
base-commit: db490fe819ac280fe608b23d98c54a5467ef2948
change-id: 20260429-i2s-same-blk-fe102b18c5ac
Best regards,
--
Troy Mitchell <troy.mitchell at linux.spacemit.com>
More information about the linux-riscv
mailing list