]> git.hungrycats.org Git - linux/commit
ASoC: soc-pcm: constrain hw_params when DAIs share the same BCLK
authorTroy Mitchell <troy.mitchell@linux.spacemit.com>
Fri, 22 May 2026 13:33:59 +0000 (21:33 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 25 May 2026 10:42:43 +0000 (11:42 +0100)
commitc8c2ffd722a6e497b9c6bb9961a7afb6ee5e2c28
treea6d63968e50f82cefbeb72979c0f2661153f9679
parent2555c62275a10bb7dfb4476ebe73d48df11f3112
ASoC: soc-pcm: constrain hw_params when DAIs share the same BCLK

When multiple CPU DAIs on the same sound card share the same physical
BCLK, add a hw_rule during PCM open that constrains the sample rate so
the resulting BCLK rate stays consistent across all sharing DAIs.

The rule callback scans all DAIs on the card at hw_refine time, looking
for an active peer that shares the same physical BCLK (via
clk_is_match()) and has already completed hw_params (checked via
dai->symmetric_rate != 0). This ensures the constraint uses the real
BCLK rate established by the peer's clk_set_rate() in hw_params, not a
stale boot-time default.

The first DAI to complete hw_params is unconstrained (no active peer
yet); subsequent DAIs are constrained to match.

The rule supports two modes:
- If the DAI has an explicit bclk_ratio set (e.g. for TDM where
  BCLK = rate * slots * slot_width), the rate is constrained to
  active_bclk_rate / bclk_ratio.
- Otherwise, the default formula BCLK = rate * channels * sample_bits
  is used to derive the valid rate range.

The constraint is purely additive: DAIs that do not set a bclk clock
pointer are completely unaffected.

Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Link: https://patch.msgid.link/20260522-i2s-same-blk-v4-3-a71a86faaa20@linux.spacemit.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-pcm.c