diff mbox series

[1/2] ASoC: fsl_sai: refactor TDM slots calculation into helper function

Message ID 20230629135820.2631908-2-s.hauer@pengutronix.de (mailing list archive)
State Superseded
Headers show
Series ASoC: fsl_sai: Fill Tx FIFO to avoid initial underruns | expand

Commit Message

Sascha Hauer June 29, 2023, 1:58 p.m. UTC
From: Ahmad Fatoum <a.fatoum@pengutronix.de>

Splitting the calculation between the initializer and later on makes it
harder to follow. A follow-up commit will also need to do this calculation,
so move it into a helper function. No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 sound/soc/fsl/fsl_sai.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

Comments

Mark Brown June 29, 2023, 2:03 p.m. UTC | #1
On Thu, Jun 29, 2023 at 03:58:19PM +0200, Sascha Hauer wrote:
> From: Ahmad Fatoum <a.fatoum@pengutronix.de>
> 
> Splitting the calculation between the initializer and later on makes it
> harder to follow. A follow-up commit will also need to do this calculation,
> so move it into a helper function. No functional change.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---

You've not provided a Signed-off-by for this so I can't do anything with
it, please see Documentation/process/submitting-patches.rst for details
on what this is and why it's important.
diff mbox series

Patch

diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index e3105d48fb651..36f6115469843 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -516,6 +516,19 @@  static int fsl_sai_set_bclk(struct snd_soc_dai *dai, bool tx, u32 freq)
 	return 0;
 }
 
+static unsigned int fsl_sai_get_tdm_slots(struct fsl_sai *sai,
+					  unsigned int channels,
+					  unsigned int slot_width)
+{
+	if (sai->slots)
+		return sai->slots;
+
+	if (sai->bclk_ratio)
+		return sai->bclk_ratio / slot_width;
+
+	return channels == 1 ? 2 : channels;
+}
+
 static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
 		struct snd_pcm_hw_params *params,
 		struct snd_soc_dai *cpu_dai)
@@ -531,7 +544,7 @@  static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
 	int dl_cfg_cnt = sai->dl_cfg_cnt;
 	u32 dl_type = FSL_SAI_DL_I2S;
 	u32 val_cr4 = 0, val_cr5 = 0;
-	u32 slots = (channels == 1) ? 2 : channels;
+	u32 slots;
 	u32 slot_width = word_width;
 	int adir = tx ? RX : TX;
 	u32 pins, bclk;
@@ -541,10 +554,7 @@  static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
 	if (sai->slot_width)
 		slot_width = sai->slot_width;
 
-	if (sai->slots)
-		slots = sai->slots;
-	else if (sai->bclk_ratio)
-		slots = sai->bclk_ratio / slot_width;
+	slots = fsl_sai_get_tdm_slots(sai, channels, slot_width);
 
 	pins = DIV_ROUND_UP(channels, slots);