Skip to content

Commit

Permalink
drivers: imx: sai: Fix frame size computation
Browse files Browse the repository at this point in the history
When I2S-like interface is enabled we must have
2 words in a frame because this is how I2S works (it has 2 channels)!

So, even if the user plays a mono file we must configure 2 words per
slot and the second slot will be masked so the users will get silence
on the second channel.

Signed-off-by: Daniel Baluta <[email protected]>
  • Loading branch information
dbaluta committed Sep 14, 2023
1 parent f27085f commit 7a09ff6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/drivers/imx/sai.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ DECLARE_TR_CTX(sai_tr, SOF_UUID(sai_uuid), LOG_LEVEL_INFO);
#define REG_TX_DIR 0
#define REG_RX_DIR 1

#define TDM_DISABLE 0
#define TDM_ENABLE 1

static void sai_start(struct dai *dai, int direction)
{
dai_info(dai, "SAI: sai_start");
Expand Down Expand Up @@ -229,6 +232,7 @@ static inline int sai_set_config(struct dai *dai, struct ipc_config_dai *common_
uint32_t val_cr2 = 0, val_cr4 = 0, val_cr5 = 0;
uint32_t mask_cr2 = 0, mask_cr4 = 0, mask_cr5 = 0;
uint32_t clk_div;
int tdm_mode;
struct sai_pdata *sai = dai_get_drvdata(dai);

sai->config = *config;
Expand All @@ -251,6 +255,9 @@ static inline int sai_set_config(struct dai *dai, struct ipc_config_dai *common_
clk_div = (config->sai.mclk_rate / config->sai.bclk_rate / 2) - 1;
}

/* TDM mode is enabled only when fmt is dsp_a or dsp_b */
tdm_mode = TDM_DISABLE;

switch (config->format & SOF_DAI_FMT_FORMAT_MASK) {
case SOF_DAI_FMT_I2S:
/*
Expand Down Expand Up @@ -285,6 +292,7 @@ static inline int sai_set_config(struct dai *dai, struct ipc_config_dai *common_
val_cr2 |= REG_SAI_CR2_BCP;
val_cr4 |= REG_SAI_CR4_FSE;
val_cr4 |= REG_SAI_CR4_SYWD(1U);
tdm_mode = TDM_ENABLE;
break;
case SOF_DAI_FMT_DSP_B:
/*
Expand All @@ -293,6 +301,7 @@ static inline int sai_set_config(struct dai *dai, struct ipc_config_dai *common_
*/
val_cr2 |= REG_SAI_CR2_BCP;
val_cr4 |= REG_SAI_CR4_SYWD(1U);
tdm_mode = TDM_ENABLE;
break;
case SOF_DAI_FMT_PDM:
val_cr2 |= REG_SAI_CR2_BCP;
Expand Down Expand Up @@ -366,7 +375,12 @@ static inline int sai_set_config(struct dai *dai, struct ipc_config_dai *common_
break;
}

val_cr4 |= REG_SAI_CR4_FRSZ(sai->params.tdm_slots);
if (tdm_mode == TDM_ENABLE)
val_cr4 |= REG_SAI_CR4_FRSZ(sai->params.tdm_slots);
else
val_cr4 |= REG_SAI_CR4_FRSZ(
(sai->params.tdm_slots == 1) ? 2 : sai->params.tdm_slots);

val_cr4 |= REG_SAI_CR4_CHMOD;
val_cr4 |= REG_SAI_CR4_MF;

Expand Down

0 comments on commit 7a09ff6

Please sign in to comment.