diff mbox series

[v2,17/29] ASoC: tas2764: Crop SDOUT zero-out mask based on BCLK ratio

Message ID 20250218-apple-codec-changes-v2-17-932760fd7e07@gmail.com (mailing list archive)
State New
Headers show
Series ASoC: tas27{64,70}: improve support for Apple codec variants | expand

Commit Message

James Calligeros Feb. 18, 2025, 8:35 a.m. UTC
From: Martin Povišer <povik+lin@cutebit.org>

Reviewed-by: Neal Gompa <neal@gompa.dev>
Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
---
 sound/soc/codecs/tas2764.c | 56 +++++++++++++++++--------
 1 file changed, 39 insertions(+), 17 deletions(-)

Comments

Mark Brown Feb. 18, 2025, 3:25 p.m. UTC | #1
On Tue, Feb 18, 2025 at 06:35:51PM +1000, James Calligeros wrote:
> From: Martin Povišer <povik+lin@cutebit.org>
> 
> Reviewed-by: Neal Gompa <neal@gompa.dev>
> Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
> Signed-off-by: James Calligeros <jcalligeros99@gmail.com>

Again, why do this?  Is this a bug fix of some kind (ie, does the
hardware misbehave if we get this wrong) or is it just for neatness?
Martin Povišer Feb. 18, 2025, 3:55 p.m. UTC | #2
> On 18. 2. 2025, at 16:25, Mark Brown <broonie@kernel.org> wrote:
> 
> On Tue, Feb 18, 2025 at 06:35:51PM +1000, James Calligeros wrote:
>> From: Martin Povišer <povik+lin@cutebit.org>
>> 
>> Reviewed-by: Neal Gompa <neal@gompa.dev>
>> Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
>> Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
> 
> Again, why do this?  Is this a bug fix of some kind (ie, does the
> hardware misbehave if we get this wrong) or is it just for neatness?

James,

I’ve found the language in the datasheet which made me make this change:

"This register to be programmed as zero in case the slot is not valid as per valid FSRATIO”

Martin
diff mbox series

Patch

diff --git a/sound/soc/codecs/tas2764.c b/sound/soc/codecs/tas2764.c
index 670c59e57997a7988af837bd58da695ad773ae14..39dc466bfbca35d50a5a93507260d59d30affab6 100644
--- a/sound/soc/codecs/tas2764.c
+++ b/sound/soc/codecs/tas2764.c
@@ -376,6 +376,44 @@  static int tas2764_hw_params(struct snd_pcm_substream *substream,
 	return tas2764_set_samplerate(tas2764, params_rate(params));
 }
 
+static int tas2764_write_sdout_zero_mask(struct tas2764_priv *tas2764, int bclk_ratio)
+{
+	struct snd_soc_component *component = tas2764->component;
+	int nsense_slots = bclk_ratio / 8;
+	u32 cropped_mask;
+	int i, ret;
+
+	if (!tas2764->sdout_zero_mask)
+		return 0;
+
+	cropped_mask = tas2764->sdout_zero_mask & GENMASK(nsense_slots - 1, 0);
+
+	for (i = 0; i < 4; i++) {
+		ret = snd_soc_component_write(component, TAS2764_SDOUT_HIZ_1 + i,
+					      (cropped_mask >> (i * 8)) & 0xff);
+
+		if (ret < 0)
+			return ret;
+	}
+
+	ret = snd_soc_component_update_bits(component, TAS2764_SDOUT_HIZ_9,
+					    TAS2764_SDOUT_HIZ_9_FORCE_0_EN,
+					    TAS2764_SDOUT_HIZ_9_FORCE_0_EN);
+
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int tas2764_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
+{
+	struct snd_soc_component *component = dai->component;
+	struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
+
+	return tas2764_write_sdout_zero_mask(tas2764, ratio);
+}
+
 static int tas2764_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
 	struct snd_soc_component *component = dai->component;
@@ -507,6 +545,7 @@  static int tas2764_set_dai_tdm_slot(struct snd_soc_dai *dai,
 static const struct snd_soc_dai_ops tas2764_dai_ops = {
 	.mute_stream = tas2764_mute,
 	.hw_params  = tas2764_hw_params,
+	.set_bclk_ratio = tas2764_set_bclk_ratio,
 	.set_fmt    = tas2764_set_fmt,
 	.set_tdm_slot = tas2764_set_dai_tdm_slot,
 	.no_capture_mute = 1,
@@ -714,23 +753,6 @@  static int tas2764_codec_probe(struct snd_soc_component *component)
 	if (ret < 0)
 		return ret;
 
-	if (tas2764->sdout_zero_mask) {
-		for (i = 0; i < 4; i++) {
-			ret = snd_soc_component_write(component, TAS2764_SDOUT_HIZ_1 + i,
-						      (tas2764->sdout_zero_mask >> (i * 8)) & 0xff);
-
-			if (ret < 0)
-				return ret;
-		}
-
-		ret = snd_soc_component_update_bits(component, TAS2764_SDOUT_HIZ_9,
-						    TAS2764_SDOUT_HIZ_9_FORCE_0_EN,
-						    TAS2764_SDOUT_HIZ_9_FORCE_0_EN);
-
-		if (ret < 0)
-			return ret;
-	}
-
 	if (tas2764->devid == DEVID_SN012776) {
 		ret = snd_soc_component_update_bits(component, TAS2764_PWR_CTRL,
 					TAS2764_PWR_CTRL_BOP_SRC,