From: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxx> Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> --- Notes: Changes since v1: - Add missing Signed-off-by sound/soc/fsl/fsl_sai.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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); -- 2.39.2