Skip to contentSkip to conversation

ASoC: cs530x: Calculate proper bclk rate using TDM

PATCH In review Paul Handrigan 2 participants 3 messages Jul 10, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ASoC: cs530x: Calculate proper bclk rate using TDM

Calculate the proper bclk rate using the number of tdm slots and the width of the tdm data.

Fixes 2884c29152c0 ("ASoC: cs530x: Support for cs530x ADCs")
---
 sound/soc/codecs/cs530x.c | 15 ++++++++++-----
 sound/soc/codecs/cs530x.h |  1 +
 2 files changed, 11 insertions(+), 5 deletions(-)
sound/soc/codecs/cs530x.c +10 -5
index 036d0f45e3ba..195739657f4e 100644
@@ -526,13 +526,15 @@ static int cs530x_hw_params(struct snd_pcm_substream *substream,
 	regmap_update_bits(regmap, CS530X_CLK_CFG_1,
 			   CS530X_SAMPLE_RATE_MASK, fs_val);
 
-	if (cs530x->tdm_slots) {
+
+	if (regmap_test_bits(regmap, CS530X_SIGNAL_PATH_CFG,
+			     CS530X_TDM_EN_MASK)) {
 		dev_dbg(component->dev, "Configuring for %d %d bit TDM slots\n",
 			cs530x->tdm_slots, cs530x->tdm_width);
-		cs530x->bclk = snd_soc_calc_bclk(cs530x->fs,
-						 cs530x->tdm_width,
-						 params_channels(params),
-						 cs530x->tdm_slots);
+		cs530x->bclk = snd_soc_tdm_params_to_bclk(params,
+							  cs530x->tdm_width,
+							  cs530x->tdm_slots,
+							  1);
 	} else {
 		cs530x->bclk = snd_soc_params_to_bclk(params);
 	}
@@ -655,6 +657,9 @@ static int cs530x_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
 		return -EINVAL;
 	}
 
+	cs530x->tdm_width = slot_width;
+	cs530x->tdm_slots = slots;
+
 	return regmap_update_bits(regmap, CS530X_SIGNAL_PATH_CFG,
 				  CS530X_ASP_TDM_SLOT_MASK,
 				  val << CS530X_ASP_TDM_SLOT_SHIFT);
sound/soc/codecs/cs530x.h +1 -0
index 1c85310a5d03..1915a0efe829 100644
@@ -96,6 +96,7 @@
 #define CS530X_ASP_TDM_SLOT_MASK	GENMASK(5, 3)
 #define CS530X_ASP_TDM_SLOT_SHIFT	3
 #define CS530X_ASP_CH_REVERSE		BIT(9)
+#define CS530X_TDM_EN_MASK		BIT(2)
 #define CS530X_ASP_FMT_I2S		0
 #define CS530X_ASP_FMT_LJ		1
 #define CS530X_ASP_FMT_DSP_A		0x6
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 ASoC: cs530x: Remove bclk from private structure

Remove the bclk int from the private structure and pass it into the set_bclk function.

---
 sound/soc/codecs/cs530x.c | 24 ++++++++++++------------
 sound/soc/codecs/cs530x.h |  1 -
 2 files changed, 12 insertions(+), 13 deletions(-)
sound/soc/codecs/cs530x.c +12 -12
index 195739657f4e..25a86a32e936 100644
@@ -415,13 +415,13 @@ static void cs530x_add_34_adc_widgets(struct snd_soc_component *component)
 				ARRAY_SIZE(adc_ch3_4_routes));
 }
 
-static int cs530x_set_bclk(struct snd_soc_component *component)
+static int cs530x_set_bclk(struct snd_soc_component *component, const int freq)
 {
 	struct cs530x_priv *cs530x = snd_soc_component_get_drvdata(component);
 	struct regmap *regmap = cs530x->regmap;
 	unsigned int bclk_val;
 
-	switch (cs530x->bclk) {
+	switch (freq) {
 	case 2822400:
 	case 3072000:
 		bclk_val = CS530X_BCLK_2P822_3P072;
@@ -439,11 +439,11 @@ static int cs530x_set_bclk(struct snd_soc_component *component)
 		bclk_val = CS530X_BCLK_24P5792_24P576;
 		break;
 	default:
-		dev_err(component->dev, "Invalid BCLK %d\n", cs530x->bclk);
+		dev_err(component->dev, "Invalid BCLK frequency %d\n", freq);
 		return -EINVAL;
 	}
 
-	dev_dbg(component->dev, "BCLK is %d\n", cs530x->bclk);
+	dev_dbg(component->dev, "BCLK frequency is %d\n", freq);
 
 	return regmap_update_bits(regmap, CS530X_ASP_CFG,
 				  CS530X_ASP_BCLK_FREQ_MASK, bclk_val);
@@ -489,7 +489,7 @@ static int cs530x_hw_params(struct snd_pcm_substream *substream,
 	struct snd_soc_component *component = dai->component;
 	struct cs530x_priv *cs530x = snd_soc_component_get_drvdata(component);
 	struct regmap *regmap = cs530x->regmap;
-	int ret = 0, fs = params_rate(params);
+	int ret = 0, fs = params_rate(params), bclk;
 	unsigned int fs_val;
 
 
@@ -531,22 +531,22 @@ static int cs530x_hw_params(struct snd_pcm_substream *substream,
 			     CS530X_TDM_EN_MASK)) {
 		dev_dbg(component->dev, "Configuring for %d %d bit TDM slots\n",
 			cs530x->tdm_slots, cs530x->tdm_width);
-		cs530x->bclk = snd_soc_tdm_params_to_bclk(params,
-							  cs530x->tdm_width,
-							  cs530x->tdm_slots,
-							  1);
+		bclk = snd_soc_tdm_params_to_bclk(params,
+						  cs530x->tdm_width,
+						  cs530x->tdm_slots,
+						  1);
 	} else {
-		cs530x->bclk = snd_soc_params_to_bclk(params);
+		bclk = snd_soc_params_to_bclk(params);
 	}
 
 	if (!regmap_test_bits(regmap, CS530X_CLK_CFG_0,
 			     CS530X_PLL_REFCLK_SRC_MASK)) {
-		ret = cs530x_set_pll_refclk(component, cs530x->bclk);
+		ret = cs530x_set_pll_refclk(component, bclk);
 		if (ret)
 			return ret;
 	}
 
-	return cs530x_set_bclk(component);
+	return cs530x_set_bclk(component, bclk);
 }
 
 static int cs530x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
sound/soc/codecs/cs530x.h +0 -1
index 1915a0efe829..f473e33eb835 100644
@@ -211,7 +211,6 @@ struct cs530x_priv {
 
 	int tdm_width;
 	int tdm_slots;
-	int bclk;
 	int fs;
 	int adc_pairs_count;
 
Signature · 1 line
2.34.1
maintainer
#2 lore raw
In reply to Paul Handrigan
Quoted 4 lines · Paul Handrigan

Calculate the proper bclk rate using the number of tdm slots and the width of the tdm data.

Applied to

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

Thanks!

[1/2] ASoC: cs530x: Calculate proper bclk rate using TDM

      commit: c62bec0fe36873ab6c87c9ae84a6b661d09244c4
[2/2] ASoC: cs530x: Remove bclk from private structure
      commit: 0d1ebba74fad7b6b3eb0e2bc08d649d20c7aa7c9

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