Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] ASoC: add shared BCLK rate constraint for cross-DAI coordination
@ 2026-05-07 10:31 Troy Mitchell
  2026-05-07 10:31 ` [PATCH v2 1/3] ASoC: soc-dai: add shared BCLK clock for cross-DAI rate constraints Troy Mitchell
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Troy Mitchell @ 2026-05-07 10:31 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Yixun Lan
  Cc: linux-sound, linux-kernel, linux-riscv, spacemit, jinmei.wei,
	Troy Mitchell

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 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@linux.spacemit.com>
---
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/20260430-i2s-same-blk-v1-0-3a1f04eb6159@linux.spacemit.com

To: Liam Girdwood <lgirdwood@gmail.com>
To: Mark Brown <broonie@kernel.org>
To: Jaroslav Kysela <perex@perex.cz>
To: Takashi Iwai <tiwai@suse.com>
To: Yixun Lan <dlan@kernel.org>
Cc: linux-sound@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-riscv@lists.infradead.org
Cc: spacemit@lists.linux.dev

---
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         |  18 +++++++
 sound/soc/soc-pcm.c         | 119 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/spacemit/k1_i2s.c |   2 +
 4 files changed, 146 insertions(+)
---
base-commit: db490fe819ac280fe608b23d98c54a5467ef2948
change-id: 20260429-i2s-same-blk-fe102b18c5ac

Best regards,
--  
Troy Mitchell <troy.mitchell@linux.spacemit.com>


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-07 10:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-07 10:31 [PATCH v2 0/3] ASoC: add shared BCLK rate constraint for cross-DAI coordination Troy Mitchell
2026-05-07 10:31 ` [PATCH v2 1/3] ASoC: soc-dai: add shared BCLK clock for cross-DAI rate constraints Troy Mitchell
2026-05-07 10:31 ` [PATCH v2 2/3] ASoC: soc-pcm: constrain hw_params when DAIs share the same BCLK Troy Mitchell
2026-05-07 10:31 ` [PATCH v2 3/3] ASoC: spacemit: declare shared BCLK for cross-DAI rate constraint Troy Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox