[PATCH] ASoC: cs42xx8: add error checks for constraints in TDM mode

Shengjiu Wang posted 1 patch 1 month, 1 week ago
sound/soc/codecs/cs42xx8.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
[PATCH] ASoC: cs42xx8: add error checks for constraints in TDM mode
Posted by Shengjiu Wang 1 month, 1 week ago
In the TDM format the ADC and DAC serial ports will only operate as a
slave, the sysclk should not be less than 256FS and Quad-Speed Mode (100
to 200 kHz sample rates) is not supported by ADC. So add error checks
for these constraints.

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
---
 sound/soc/codecs/cs42xx8.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c
index d14538c49b97..378995561ab2 100644
--- a/sound/soc/codecs/cs42xx8.c
+++ b/sound/soc/codecs/cs42xx8.c
@@ -43,6 +43,7 @@ struct cs42xx8_priv {
 	struct clk *clk;
 
 	bool slave_mode;
+	bool is_tdm_mode;
 	unsigned long sysclk;
 	u32 tx_channels;
 	struct gpio_desc *gpiod_reset;
@@ -217,6 +218,8 @@ static int cs42xx8_set_dai_fmt(struct snd_soc_dai *codec_dai,
 	struct cs42xx8_priv *cs42xx8 = snd_soc_component_get_drvdata(component);
 	u32 val;
 
+	cs42xx8->is_tdm_mode = false;
+
 	/* Set DAI format */
 	switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
 	case SND_SOC_DAIFMT_LEFT_J:
@@ -230,6 +233,7 @@ static int cs42xx8_set_dai_fmt(struct snd_soc_dai *codec_dai,
 		break;
 	case SND_SOC_DAIFMT_DSP_A:
 		val = CS42XX8_INTF_DAC_DIF_TDM | CS42XX8_INTF_ADC_DIF_TDM;
+		cs42xx8->is_tdm_mode = true;
 		break;
 	default:
 		dev_err(component->dev, "unsupported dai format\n");
@@ -253,6 +257,11 @@ static int cs42xx8_set_dai_fmt(struct snd_soc_dai *codec_dai,
 		return -EINVAL;
 	}
 
+	if (cs42xx8->is_tdm_mode && !cs42xx8->slave_mode) {
+		dev_err(component->dev, "TDM mode is supported only in slave mode\n");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
@@ -335,6 +344,19 @@ static int cs42xx8_hw_params(struct snd_pcm_substream *substream,
 
 	cs42xx8->rate[tx] = params_rate(params);
 
+	if (cs42xx8->is_tdm_mode) {
+		if (cs42xx8->sysclk < 256 * cs42xx8->rate[tx]) {
+			dev_err(component->dev, "Unsupported sysclk in TDM mode\n");
+			return -EINVAL;
+		}
+
+		if (!tx && cs42xx8->rate[tx] > 100000) {
+			dev_err(component->dev,
+				"ADC does not support Quad-Speed Mode in TDM mode\n");
+			return -EINVAL;
+		}
+	}
+
 	mask = CS42XX8_FUNCMOD_MFREQ_MASK;
 	val = cs42xx8_ratios[i].mfreq;
 
-- 
2.34.1
Re: [PATCH] ASoC: cs42xx8: add error checks for constraints in TDM mode
Posted by Mark Brown 1 month ago
On Wed, 25 Feb 2026 18:09:07 +0800, Shengjiu Wang wrote:
> In the TDM format the ADC and DAC serial ports will only operate as a
> slave, the sysclk should not be less than 256FS and Quad-Speed Mode (100
> to 200 kHz sample rates) is not supported by ADC. So add error checks
> for these constraints.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: cs42xx8: add error checks for constraints in TDM mode
      commit: da37bfe76b5b4ccc01ed8132215098e20d78e5f3

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark