Skip to contentSkip to conversation

ASoC: fsl_sai: Enable transmitter when generating MCLK

PATCH In review Marek Vasut 2 participants 7 messages Nov 7, 2022 – Nov 15, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: fsl_sai: Enable transmitter when generating MCLK

For SAI to generate MCLK on external SoC pad, the transmitter must be enabled as well. With transmitter disabled, no clock are generated. Enable the transmitter using the TERE bit.

---
Cc: Fabio Estevam <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Nicolin Chen <[email protected]>
Cc: Shengjiu Wang <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: Xiubo Li <[email protected]>
To: [email protected]

---
 sound/soc/fsl/fsl_sai.c | 9 +++++++++
 1 file changed, 9 insertions(+)
sound/soc/fsl/fsl_sai.c +9 -0
index 1c9be8a5dcb13..98c62027e5799 100644
@@ -503,6 +503,10 @@ static int fsl_sai_set_bclk(struct snd_soc_dai *dai, bool tx, u32 freq)
 		/* SAI is in master mode at this point, so enable MCLK */
 		regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
 				   FSL_SAI_MCTL_MCLK_EN, FSL_SAI_MCTL_MCLK_EN);
+
+		/* Transmitter must be enabled to generate MCLK on pad */
+		regmap_update_bits(sai->regmap, FSL_SAI_xCSR(1, ofs),
+				   FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);
 	}
 
 	return 0;
@@ -1445,6 +1449,11 @@ static int fsl_sai_probe(struct platform_device *pdev)
 	    sai->soc_data->max_register >= FSL_SAI_MCTL) {
 		regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
 				   FSL_SAI_MCTL_MCLK_EN, FSL_SAI_MCTL_MCLK_EN);
+
+		/* Transmitter must be enabled to generate MCLK on pad */
+		regmap_update_bits(sai->regmap,
+				   FSL_SAI_xCSR(1, sai->soc_data->reg_offset),
+				   FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);
 	}
 
 	ret = pm_runtime_put_sync(dev);
Signature · 1 line
2.35.1
maintainer
#1 lore raw
Quoted 4 lines · Marek Vasut

For SAI to generate MCLK on external SoC pad, the transmitter must be enabled as well. With transmitter disabled, no clock are generated. Enable the transmitter using the TERE bit.

It is already done in trigger(), why need to do this operation in probe() and set_bclk() again?

best regards
wang shengjiu

Quoted 52 lines

---
Cc: Fabio Estevam <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Nicolin Chen <[email protected]>
Cc: Shengjiu Wang <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: Xiubo Li <[email protected]>
To: [email protected]

---
 sound/soc/fsl/fsl_sai.c | 9 +++++++++
 1 file changed, 9 insertions(+)
sound/soc/fsl/fsl_sai.c +4 -0
index 1c9be8a5dcb13..98c62027e5799 100644
@@ -503,6 +503,10 @@ static int fsl_sai_set_bclk(struct snd_soc_dai *dai,
 bool tx, u32 freq)
                /* SAI is in master mode at this point, so enable MCLK */
                regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                   FSL_SAI_MCTL_MCLK_EN,
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad */
+               regmap_update_bits(sai->regmap, FSL_SAI_xCSR(1, ofs),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);
        }
        return 0;
sound/soc/fsl/fsl_sai.c +5 -0
@@ -1445,6 +1449,11 @@ static int fsl_sai_probe(struct platform_device
 *pdev)
            sai->soc_data->max_register >= FSL_SAI_MCTL) {
                regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                   FSL_SAI_MCTL_MCLK_EN,
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad */
+               regmap_update_bits(sai->regmap,
+                                  FSL_SAI_xCSR(1,
 sai->soc_data->reg_offset),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);
        }

        ret = pm_runtime_put_sync(dev);

--
2.35.1

#2 lore raw
Quoted 9 lines · Shengjiu Wang
Quoted 4 lines · Marek Vasut

For SAI to generate MCLK on external SoC pad, the transmitter must be enabled as well. With transmitter disabled, no clock are generated. Enable the transmitter using the TERE bit.

It is already done in trigger(), why need to do this operation in probe() and set_bclk() again?

The system I have here has SAI MCLK (output) connected to SGTL5000 codec MCLK (input) . If the SAI MCLK (output), the codec I2C interface won't work. That's why the MCLK must be enabled so early.

maintainer
#3 lore raw
In reply to Marek Vasut
Quoted 24 lines · Marek Vasut

For SAI to generate MCLK on external SoC pad, the transmitter must be enabled as well. With transmitter disabled, no clock are generated. Enable the transmitter using the TERE bit.

---
Cc: Fabio Estevam <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Nicolin Chen <[email protected]>
Cc: Shengjiu Wang <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: Xiubo Li <[email protected]>
To: [email protected]

---
 sound/soc/fsl/fsl_sai.c | 9 +++++++++
 1 file changed, 9 insertions(+)
sound/soc/fsl/fsl_sai.c +0 -0
index 1c9be8a5dcb13..98c62027e5799 100644

sound/soc/fsl/fsl_sai.c static int fsl_sai_set_bclk(struct snd_soc_dai *dai, · line 512

Quoted 10 lines
sound/soc/fsl/fsl_sai.c +4 -0
@@ -503,6 +503,10 @@ static int fsl_sai_set_bclk(struct snd_soc_dai *dai,
 bool tx, u32 freq)
                /* SAI is in master mode at this point, so enable MCLK */
                regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                   FSL_SAI_MCTL_MCLK_EN,
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad */
+               regmap_update_bits(sai->regmap, FSL_SAI_xCSR(1, ofs),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);
 

No need to fix the transmitter, FSL_SAI_xCSR(tx, ofs) should work also.

Quoted 6 lines
        }

        return 0;
sound/soc/fsl/fsl_sai.c +0 -0
@@ -1445,6 +1449,11 @@ static int fsl_sai_probe(struct platform_device
 *pdev)

sound/soc/fsl/fsl_sai.c static int fsl_sai_probe(struct platform_device · line 1459

Quoted 10 lines
sound/soc/fsl/fsl_sai.c +5 -0
            sai->soc_data->max_register >= FSL_SAI_MCTL) {
                regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                   FSL_SAI_MCTL_MCLK_EN,
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad */
+               regmap_update_bits(sai->regmap,
+                                  FSL_SAI_xCSR(1,
 sai->soc_data->reg_offset),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);

After one time playback or recording, the TERE is disabled, so this changes in probe() only for the first time. There is the same issue for the second time.

best regards
wang shengjiu

Quoted 7 lines
        }

        ret = pm_runtime_put_sync(dev);

--
2.35.1

#4 lore raw

On 11/9/22 10:30, Shengjiu Wang wrote:

[...]

Quoted 9 lines
Quoted 9 lines
sound/soc/fsl/fsl_sai.c +0 -0
index 1c9be8a5dcb13..98c62027e5799 100644
@@ -503,6 +503,10 @@ static int fsl_sai_set_bclk(struct snd_soc_dai *dai,
 bool tx, u32 freq)
                 /* SAI is in master mode at this point, so enable MCLK */
                 regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                    FSL_SAI_MCTL_MCLK_EN,
Quoted 8 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_set_bclk(struct snd_soc_dai *dai, bool tx, u32 freq) · line 511

Quoted 6 lines
sound/soc/fsl/fsl_sai.c +4 -0
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad */
+               regmap_update_bits(sai->regmap, FSL_SAI_xCSR(1, ofs),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);
 

No need to fix the transmitter, FSL_SAI_xCSR(tx, ofs) should work also.

That's probably not a good idea, since this could also enable the RE(receiver) part . We always need to enable the TE(transmitter) to generate MCLK.

Quoted 12 lines
Quoted 12 lines
         }

         return 0;
sound/soc/fsl/fsl_sai.c +3 -0
@@ -1445,6 +1449,11 @@ static int fsl_sai_probe(struct platform_device
 *pdev)
             sai->soc_data->max_register >= FSL_SAI_MCTL) {
                 regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                    FSL_SAI_MCTL_MCLK_EN,
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad */
+               regmap_update_bits(sai->regmap,
Quoted 8 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_probe(struct platform_device · line 1459

Quoted 4 lines
sound/soc/fsl/fsl_sai.c +2 -0
+                                  FSL_SAI_xCSR(1,
 sai->soc_data->reg_offset),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);

After one time playback or recording, the TERE is disabled, so this changes in probe() only for the first time. There is the same issue for the second time.

So what would you suggest to keep the MCLK clock generated always ?

I was almost tempted to turn the SAI into a clock provider, so that the codec could become its clock consumer and enable the MCLK on demand, but that seems to be a rather invasive change.

maintainer
#5 lore raw
Quoted 23 lines · Marek Vasut

On 11/9/22 10:30, Shengjiu Wang wrote:

[...]

Quoted 5 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_set_bclk(struct snd_soc_dai

Quoted 5 lines
sound/soc/fsl/fsl_sai.c +0 -0
index 1c9be8a5dcb13..98c62027e5799 100644
@@ -503,6 +503,10 @@ static int fsl_sai_set_bclk(struct snd_soc_dai

*dai,

Quoted 2 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_set_bclk(struct snd_soc_dai · line 504

Quoted 2 lines
sound/soc/fsl/fsl_sai.c +0 -0
 bool tx, u32 freq)
                 /* SAI is in master mode at this point, so enable MCLK

*/

Quoted 5 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_set_bclk(struct snd_soc_dai · line 509

Quoted 5 lines
sound/soc/fsl/fsl_sai.c +2 -0
                 regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                    FSL_SAI_MCTL_MCLK_EN,
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad

*/

Quoted 4 lines
Quoted 3 lines
sound/soc/fsl/fsl_sai.c +2 -0
+               regmap_update_bits(sai->regmap, FSL_SAI_xCSR(1, ofs),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);
 
Quoted 6 lines
Quoted 1 line

No need to fix the transmitter, FSL_SAI_xCSR(tx, ofs) should work also.

That's probably not a good idea, since this could also enable the RE(receiver) part . We always need to enable the TE(transmitter) to generate MCLK.

TCSR.TERE and RCSR.TERE all can enable the MCLK.
if use the FSL_SAI_xCSR(tx, ofs), both cases can be covered. if the bclk is generated by TX, then enable the TE(transmitter) to generate MCLK. or if the bclk is generated by RX, then enable the RE(receiver) to generate MCLK.

Quoted 22 lines
Quoted 12 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_probe(struct platform_device · line 1455

Quoted 12 lines
         }

         return 0;
sound/soc/fsl/fsl_sai.c +2 -0
@@ -1445,6 +1449,11 @@ static int fsl_sai_probe(struct platform_device
 *pdev)
             sai->soc_data->max_register >= FSL_SAI_MCTL) {
                 regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                    FSL_SAI_MCTL_MCLK_EN,
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad

*/

Quoted 7 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_probe(struct platform_device *pdev) · line 1456

Quoted 5 lines
sound/soc/fsl/fsl_sai.c +3 -0
+               regmap_update_bits(sai->regmap,
+                                  FSL_SAI_xCSR(1,
 sai->soc_data->reg_offset),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);

After one time playback or recording, the TERE is disabled, so this

changes

Quoted 1 line

in probe() only for the first time. There is the same issue for the

Quoted 9 lines

second

Quoted 1 line

time.

So what would you suggest to keep the MCLK clock generated always ?

I was almost tempted to turn the SAI into a clock provider, so that the codec could become its clock consumer and enable the MCLK on demand, but that seems to be a rather invasive change.

May you can try to enhance the drivers/clk/clk-fsl-sai.c

best regards
wang shengjiu

#6 lore raw
Quoted 32 lines · Shengjiu Wang
Quoted 23 lines · Marek Vasut

On 11/9/22 10:30, Shengjiu Wang wrote:

[...]

Quoted 5 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_set_bclk(struct snd_soc_dai

Quoted 5 lines
sound/soc/fsl/fsl_sai.c +0 -0
index 1c9be8a5dcb13..98c62027e5799 100644
@@ -503,6 +503,10 @@ static int fsl_sai_set_bclk(struct snd_soc_dai

*dai,

Quoted 2 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_set_bclk(struct snd_soc_dai · line 504

Quoted 2 lines
sound/soc/fsl/fsl_sai.c +0 -0
 bool tx, u32 freq)
                  /* SAI is in master mode at this point, so enable MCLK

*/

Quoted 5 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_set_bclk(struct snd_soc_dai · line 509

Quoted 5 lines
sound/soc/fsl/fsl_sai.c +2 -0
                  regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                     FSL_SAI_MCTL_MCLK_EN,
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad

*/

Quoted 4 lines
Quoted 3 lines
sound/soc/fsl/fsl_sai.c +2 -0
+               regmap_update_bits(sai->regmap, FSL_SAI_xCSR(1, ofs),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);
 
Quoted 6 lines
Quoted 1 line

No need to fix the transmitter, FSL_SAI_xCSR(tx, ofs) should work also.

That's probably not a good idea, since this could also enable the RE(receiver) part . We always need to enable the TE(transmitter) to generate MCLK.

Quoted 5 lines

TCSR.TERE and RCSR.TERE all can enable the MCLK.
if use the FSL_SAI_xCSR(tx, ofs), both cases can be covered. if the bclk is generated by TX, then enable the TE(transmitter) to generate MCLK. or if the bclk is generated by RX, then enable the RE(receiver) to generate MCLK.

I will need to do a full re-test to validate this claim.

Quoted 21 lines
Quoted 21 lines
Quoted 8 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_probe(struct platform_device · line 1455

Quoted 8 lines
sound/soc/fsl/fsl_sai.c +2 -0
@@ -1445,6 +1449,11 @@ static int fsl_sai_probe(struct platform_device
 *pdev)
              sai->soc_data->max_register >= FSL_SAI_MCTL) {
                  regmap_update_bits(sai->regmap, FSL_SAI_MCTL,
                                     FSL_SAI_MCTL_MCLK_EN,
 FSL_SAI_MCTL_MCLK_EN);
+
+               /* Transmitter must be enabled to generate MCLK on pad

*/

Quoted 7 lines

sound/soc/fsl/fsl_sai.c static int fsl_sai_probe(struct platform_device *pdev) · line 1456

Quoted 5 lines
sound/soc/fsl/fsl_sai.c +3 -0
+               regmap_update_bits(sai->regmap,
+                                  FSL_SAI_xCSR(1,
 sai->soc_data->reg_offset),
+                                  FSL_SAI_CSR_TERE, FSL_SAI_CSR_TERE);

After one time playback or recording, the TERE is disabled, so this

changes

Quoted 1 line

in probe() only for the first time. There is the same issue for the

second

Quoted 1 line

time.

Quoted 8 lines
Quoted 6 lines

So what would you suggest to keep the MCLK clock generated always ?

I was almost tempted to turn the SAI into a clock provider, so that the codec could become its clock consumer and enable the MCLK on demand, but that seems to be a rather invasive change.

May you can try to enhance the drivers/clk/clk-fsl-sai.c

This is not really useful in this case, this lets users use the SAI as a plain clock source. I use the SAI as audio IP, all I need in addition to that is enable the MCLK as codec Master Clock to drive the codec register file and whatever internal state it has.