@@ -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);