Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Shenghao Ding <shenghao-ding@ti.com>, Kevin Lu <kevin-lu@ti.com>,
	Baojun Xu <baojun.xu@ti.com>, Sen Wang <sen@ti.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 6/7] ASoC: tlv320aic32x4: factor out rate configuration helper
Date: Sat, 25 Jul 2026 18:05:16 -0700	[thread overview]
Message-ID: <20260726010519.117805-6-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20260726010519.117805-1-dmitry.torokhov@gmail.com>

Factor out sample-rate dependent parameter setup and processing block
configuration into a separate helper function aic32x4_configure_rate.

Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 sound/soc/codecs/tlv320aic32x4.c | 75 +++++++++++++++++++-------------
 1 file changed, 44 insertions(+), 31 deletions(-)

diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c
index 690acfc005c2..8d3f2d5c6128 100644
--- a/sound/soc/codecs/tlv320aic32x4.c
+++ b/sound/soc/codecs/tlv320aic32x4.c
@@ -703,6 +703,45 @@ static int aic32x4_set_processing_blocks(struct snd_soc_component *component,
 	return 0;
 }
 
+static int aic32x4_configure_rate(struct snd_soc_component *component,
+				  unsigned int rate, u8 *aosr, u8 *adc_rc,
+				  u8 *dac_rc, u8 *dosr_inc)
+{
+	struct aic32x4_priv *aic32x4 = snd_soc_component_get_drvdata(component);
+	u8 prb_rx, prb_tx;
+
+	if (rate <= 48000) {
+		*aosr = 128;
+		*adc_rc = 6;
+		*dac_rc = 8;
+		*dosr_inc = 8;
+		prb_rx = 1;
+		prb_tx = 1;
+	} else if (rate <= 96000) {
+		*aosr = 64;
+		*adc_rc = 6;
+		*dac_rc = 8;
+		*dosr_inc = 4;
+		prb_rx = 1;
+		prb_tx = (aic32x4->type == AIC32X4_TYPE_TAS2505) ? 1 : 9;
+	} else if (rate == 192000) {
+		*aosr = 32;
+		*adc_rc = 3;
+		*dac_rc = 4;
+		*dosr_inc = 2;
+		prb_rx = 13;
+		prb_tx = (aic32x4->type == AIC32X4_TYPE_TAS2505) ? 1 : 19;
+	} else {
+		dev_err(component->dev, "Sampling rate %u not supported\n", rate);
+		return -EINVAL;
+	}
+
+	if (aic32x4->type == AIC32X4_TYPE_TAS2505)
+		prb_rx = 0;
+
+	return aic32x4_set_processing_blocks(component, prb_rx, prb_tx);
+}
+
 static int aic32x4_setup_clocks(struct snd_soc_component *component,
 				unsigned int sample_rate, unsigned int channels,
 				unsigned int bit_depth)
@@ -729,37 +768,11 @@ static int aic32x4_setup_clocks(struct snd_soc_component *component,
 	if (ret)
 		return ret;
 
-	if (sample_rate <= 48000) {
-		aosr = 128;
-		adc_resource_class = 6;
-		dac_resource_class = 8;
-		dosr_increment = 8;
-		if (aic32x4->type == AIC32X4_TYPE_TAS2505)
-			aic32x4_set_processing_blocks(component, 0, 1);
-		else
-			aic32x4_set_processing_blocks(component, 1, 1);
-	} else if (sample_rate <= 96000) {
-		aosr = 64;
-		adc_resource_class = 6;
-		dac_resource_class = 8;
-		dosr_increment = 4;
-		if (aic32x4->type == AIC32X4_TYPE_TAS2505)
-			aic32x4_set_processing_blocks(component, 0, 1);
-		else
-			aic32x4_set_processing_blocks(component, 1, 9);
-	} else if (sample_rate == 192000) {
-		aosr = 32;
-		adc_resource_class = 3;
-		dac_resource_class = 4;
-		dosr_increment = 2;
-		if (aic32x4->type == AIC32X4_TYPE_TAS2505)
-			aic32x4_set_processing_blocks(component, 0, 1);
-		else
-			aic32x4_set_processing_blocks(component, 13, 19);
-	} else {
-		dev_err(component->dev, "Sampling rate not supported\n");
-		return -EINVAL;
-	}
+	ret = aic32x4_configure_rate(component, sample_rate, &aosr,
+				     &adc_resource_class, &dac_resource_class,
+				     &dosr_increment);
+	if (ret)
+		return ret;
 
 	/* PCM over I2S is always 2-channel */
 	if ((aic32x4->fmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_I2S)
-- 
2.55.0.229.g6434b31f56-goog


  parent reply	other threads:[~2026-07-26  1:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-26  1:05 [PATCH 1/7] ASoC: tlv320aic32x4: remove global header with platform data Dmitry Torokhov
2026-07-26  1:05 ` [PATCH 2/7] ASoC: tlv320aic32x4: do not allocate gpio config separately Dmitry Torokhov
2026-07-26  1:05 ` [PATCH 3/7] ASoC: tlv320aic32x4: consolidate programming functions Dmitry Torokhov
2026-07-26  1:05 ` [PATCH 4/7] ASoC: tlv320aic32x4: move regmap_config into i2c and spi drivers Dmitry Torokhov
2026-07-26  1:05 ` [PATCH 5/7] ASoC: tlv320aic32x4: do not make clocks bulk data static Dmitry Torokhov
2026-07-26  1:05 ` Dmitry Torokhov [this message]
2026-07-26  1:05 ` [PATCH 7/7] ASoC: tlv320aic32x4: clean up driver code formatting and logging Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260726010519.117805-6-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=baojun.xu@ti.com \
    --cc=broonie@kernel.org \
    --cc=kevin-lu@ti.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=sen@ti.com \
    --cc=shenghao-ding@ti.com \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox