[PATCH 6/7] ASoC: spacemit: add fixed-sample-rate constraint support
Troy Mitchell
troy.mitchell at linux.spacemit.com
Tue Apr 28 18:38:51 PDT 2026
When multiple I2S controllers share a common bclk, they must all use
the same sample rate. Read the optional spacemit,fixed-sample-rate DT
property and apply it as a hardware constraint in the startup callback,
restricting the PCM rate to the specified value.
This applies to both K1 and K3 SoCs and is only needed when two or
more I2S controllers are active simultaneously.
Signed-off-by: Troy Mitchell <troy.mitchell at linux.spacemit.com>
---
sound/soc/spacemit/k1_i2s.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/sound/soc/spacemit/k1_i2s.c b/sound/soc/spacemit/k1_i2s.c
index cef883ba4de9..7d0794d21ea6 100644
--- a/sound/soc/spacemit/k1_i2s.c
+++ b/sound/soc/spacemit/k1_i2s.c
@@ -3,6 +3,7 @@
#include <linux/bitfield.h>
#include <linux/clk.h>
+#include <linux/of.h>
#include <linux/reset.h>
#include <sound/dmaengine_pcm.h>
#include <sound/pcm.h>
@@ -54,6 +55,8 @@ struct spacemit_i2s_dev {
struct clk *bclk;
struct clk *sspa_clk;
+ unsigned int fixed_sample_rate;
+
struct snd_dmaengine_dai_dma_data capture_dma_data;
struct snd_dmaengine_dai_dma_data playback_dma_data;
@@ -111,6 +114,13 @@ static int spacemit_i2s_startup(struct snd_pcm_substream *substream,
{
struct spacemit_i2s_dev *i2s = snd_soc_dai_get_drvdata(dai);
+ if (i2s->fixed_sample_rate) {
+ snd_pcm_hw_constraint_minmax(substream->runtime,
+ SNDRV_PCM_HW_PARAM_RATE,
+ i2s->fixed_sample_rate,
+ i2s->fixed_sample_rate);
+ }
+
switch (i2s->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
snd_pcm_hw_constraint_minmax(substream->runtime,
@@ -437,6 +447,9 @@ static int spacemit_i2s_probe(struct platform_device *pdev)
return dev_err_probe(i2s->dev, PTR_ERR(i2s->sspa_clk),
"failed to enable sspa clock\n");
+ of_property_read_u32(i2s->dev->of_node, "spacemit,fixed-sample-rate",
+ &i2s->fixed_sample_rate);
+
i2s->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(i2s->base))
return dev_err_probe(i2s->dev, PTR_ERR(i2s->base), "failed to map registers\n");
--
2.54.0
More information about the linux-riscv
mailing list