Skip to content

ASoC: add shared BCLK rate constraint for cross-DAI coordination

Troy Mitchell linux-riscv linux-sound lkml spacemit 4 versions – In review

Get series with b4
b4 am [email protected] change-id 20260429-i2s-same-blk-fe102b18c5ac

Versions newest first

  1. v4 Latest3 patches 1 replyIn review
  2. v32 patches 2 repliesSuperseded
  3. v23 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v13 patches2 repliesSuperseded

Changes in v4 from the cover letter

- Use snd_soc_card_mutex_lock()/snd_soc_card_mutex_unlock() via a local DEFINE_GUARD for lockdep subclass consistency
- Add DEFINE_GUARD(snd_soc_card_mutex) as a separate patch
- Link to v3: https://patch.msgid.link/[email protected]

- Drop the SpacemiT K1/K3 I2S driver patch (previously patch 3) which
depends on the not-yet-merged K3 I2S series; it will be sent as a
standalone patch once that series lands
- Link to v2: https://patch.msgid.link/[email protected]

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3ASoC: soc-dai: add shared BCLK clock for cross-DAI rate constraintsinclude/sound/soc-dai.h sound/soc/soc-dai.c+25 -00 replies
2/3ASoC: soc-pcm: add DEFINE_GUARD for snd_soc_card_mutexsound/soc/soc-pcm.c+3 -00 replies
3/3ASoC: soc-pcm: constrain hw_params when DAIs share the same BCLKsound/soc/soc-pcm.c+116 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/3] ASoC: add shared BCLK rate constraint for cross-DAI coordination

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 the dt-bindings for the spacemit,k3-i2s compatible. The K3 SoC uses the same I2S IP as K1 but requires additional clocks:
a dedicated sysclk_div, along with c_sysclk and c_bclk which are shared across multiple I2S controllers.

Patch 2 adds a DEFINE_GUARD wrapping snd_soc_card_mutex_lock() and snd_soc_card_mutex_unlock() so that scope-based locking picks up the SND_SOC_CARD_CLASS_RUNTIME lockdep subclass.

Patch 3 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.

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/[email protected]/

---
Changes in v4:
- Use snd_soc_card_mutex_lock()/snd_soc_card_mutex_unlock() via a local DEFINE_GUARD for lockdep subclass consistency
- Add DEFINE_GUARD(snd_soc_card_mutex) as a separate patch
- Link to v3: https://patch.msgid.link/[email protected]

- Drop the SpacemiT K1/K3 I2S driver patch (previously patch 3) which
depends on the not-yet-merged K3 I2S series; it will be sent as a
standalone patch once that series lands
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Only store bclk_ratio when set_bclk_ratio op succeeds, avoiding stale
ratio on real errors
- Hold card->mutex during rtd list traversal in hw_rule callback
- Link to v1: https://patch.msgid.link/[email protected]

To: Liam Girdwood <[email protected]>
To: Mark Brown <[email protected]>
To: Jaroslav Kysela <[email protected]>
To: Takashi Iwai <[email protected]>
To: Yixun Lan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Troy Mitchell (3):
ASoC: soc-dai: add shared BCLK clock for cross-DAI rate constraints
ASoC: soc-pcm: add DEFINE_GUARD for snd_soc_card_mutex
ASoC: soc-pcm: constrain hw_params when DAIs share the same BCLK

 include/sound/soc-dai.h |   7 +++
 sound/soc/soc-dai.c     |  18 ++++++++
 sound/soc/soc-pcm.c     | 119 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)

---
base-commit: db490fe819ac280fe608b23d98c54a5467ef2948
change-id: 20260429-i2s-same-blk-fe102b18c5ac

Best regards,

Signature · 1 line
Troy Mitchell <[email protected]>