ASoC: fsl_sai: handle slave mode per TX/RX direction
authorViorel Suman <viorel.suman@nxp.com>
Wed, 3 May 2017 07:16:02 +0000 (10:16 +0300)
committerDong Aisheng <aisheng.dong@nxp.com>
Mon, 14 Dec 2020 02:58:13 +0000 (10:58 +0800)
The SAI interface can be a clock supplier or consummer
as function of stream direction, ie when interacting
with I2S XTOR. Removed FSL_SAI_RFR define as it is now
referred as FSL_SAI_RFR0.

Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
sound/soc/fsl/fsl_sai.c
sound/soc/fsl/fsl_sai.h

index c67070b..59cc3fe 100644 (file)
@@ -300,23 +300,23 @@ static int fsl_sai_set_dai_fmt_tr(struct snd_soc_dai *cpu_dai,
                return -EINVAL;
        }
 
+       sai->slave_mode[tx] = false;
+
        /* DAI clock master masks */
        switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
        case SND_SOC_DAIFMT_CBS_CFS:
                val_cr2 |= FSL_SAI_CR2_BCD_MSTR;
                val_cr4 |= FSL_SAI_CR4_FSD_MSTR;
-               sai->is_slave_mode = false;
                break;
        case SND_SOC_DAIFMT_CBM_CFM:
-               sai->is_slave_mode = true;
+               sai->slave_mode[tx] = true;
                break;
        case SND_SOC_DAIFMT_CBS_CFM:
                val_cr2 |= FSL_SAI_CR2_BCD_MSTR;
-               sai->is_slave_mode = false;
                break;
        case SND_SOC_DAIFMT_CBM_CFS:
                val_cr4 |= FSL_SAI_CR4_FSD_MSTR;
-               sai->is_slave_mode = true;
+               sai->slave_mode[tx] = true;
                break;
        default:
                return -EINVAL;
@@ -360,7 +360,7 @@ static int fsl_sai_set_bclk(struct snd_soc_dai *dai, bool tx, u32 freq)
        int ret = 0;
 
        /* Don't apply to slave mode */
-       if (sai->is_slave_mode)
+       if (sai->slave_mode[tx])
                return 0;
 
        for (id = 0; id < FSL_SAI_MCLK_MAX; id++) {
@@ -466,7 +466,7 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
 
        pins = DIV_ROUND_UP(channels, slots);
 
-       if (!sai->is_slave_mode) {
+       if (!sai->slave_mode[tx]) {
                if (sai->bclk_ratio)
                        ret = fsl_sai_set_bclk(cpu_dai, tx,
                                               sai->bclk_ratio *
@@ -511,7 +511,7 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
         * RCR5(TCR5) for playback(capture), or there will be sync error.
         */
 
-       if (!sai->is_slave_mode && fsl_sai_dir_is_synced(sai, adir)) {
+       if (!sai->slave_mode[tx] && fsl_sai_dir_is_synced(sai, adir)) {
                regmap_update_bits(sai->regmap, FSL_SAI_xCR4(!tx, ofs),
                                   FSL_SAI_CR4_SYWD_MASK | FSL_SAI_CR4_FRSZ_MASK |
                                   FSL_SAI_CR4_CHMOD_MASK,
@@ -558,7 +558,7 @@ static int fsl_sai_hw_free(struct snd_pcm_substream *substream,
        regmap_update_bits(sai->regmap, FSL_SAI_xCR3(tx, ofs),
                           FSL_SAI_CR3_TRCE_MASK, 0);
 
-       if (!sai->is_slave_mode &&
+       if (!sai->slave_mode[tx] &&
                        sai->mclk_streams & BIT(substream->stream)) {
                clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[tx]]);
                sai->mclk_streams &= ~BIT(substream->stream);
@@ -592,7 +592,7 @@ static void fsl_sai_config_disable(struct fsl_sai *sai, int dir)
         * This is a hardware bug, and will be fix in the
         * next sai version.
         */
-       if (!sai->is_slave_mode) {
+       if (!sai->slave_mode[tx]) {
                /* Software Reset */
                regmap_write(sai->regmap, FSL_SAI_xCSR(tx, ofs), FSL_SAI_CSR_SR);
                /* Clear SR bit to finish the reset */
index 6f0100e..30d5638 100644 (file)
@@ -261,7 +261,7 @@ struct fsl_sai {
        struct clk *bus_clk;
        struct clk *mclk_clk[FSL_SAI_MCLK_MAX];
 
-       bool is_slave_mode;
+       bool slave_mode[2];
        bool is_lsb_first;
        bool is_dsp_mode;
        bool synchronous[2];