ASoC: fsl_sai: fix no frame clk in master mode
diff mbox

Message ID 2ec370890aca1bf5e8b796d7ebbfc95a0161980e.1439345935.git.zidan.wang@freescale.com
State New
Headers show

Commit Message

Zidan Wang Aug. 12, 2015, 2:25 a.m. UTC
After several open/close sai test with ctrl+c, there will be I/O error.
The SAI can't work anymore, can't recover. There will be no frame clock.
With adding the software reset in trigger stop, the issue can be fixed.

Signed-off-by: Zidan Wang <zidan.wang@freescale.com>
---
 sound/soc/fsl/fsl_sai.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Nicolin Chen Aug. 12, 2015, 3:53 a.m. UTC | #1
On Wed, Aug 12, 2015 at 10:25:45AM +0800, Zidan Wang wrote:
> After several open/close sai test with ctrl+c, there will be I/O error.
> The SAI can't work anymore, can't recover. There will be no frame clock.
> With adding the software reset in trigger stop, the issue can be fixed.

It doesn't look like a decent fix to me. Is it the only fix that
IC team suggests? And why put this reset in the trigger function.
Your MEGA fast patch has already included a software reset in the
PM runtime functions. When dealing with CTRL+C test cases, that
software reset should have worked as well.

Nicolin

> Signed-off-by: Zidan Wang <zidan.wang@freescale.com>
> ---
>  sound/soc/fsl/fsl_sai.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
> index 5c737f1..6a947dc 100644
> --- a/sound/soc/fsl/fsl_sai.c
> +++ b/sound/soc/fsl/fsl_sai.c
> @@ -504,6 +504,13 @@ static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,
>  					   FSL_SAI_CSR_FR, FSL_SAI_CSR_FR);
>  			regmap_update_bits(sai->regmap, FSL_SAI_RCSR,
>  					   FSL_SAI_CSR_FR, FSL_SAI_CSR_FR);
> +
> +			/* Software Reset for both Tx and Rx */
> +			regmap_write(sai->regmap, FSL_SAI_TCSR, FSL_SAI_CSR_SR);
> +			regmap_write(sai->regmap, FSL_SAI_RCSR, FSL_SAI_CSR_SR);
> +			/* Clear SR bit to finish the reset */
> +			regmap_write(sai->regmap, FSL_SAI_TCSR, 0);
> +			regmap_write(sai->regmap, FSL_SAI_RCSR, 0);
>  		}
>  		break;
>  	default:
> -- 
> 1.9.1
>
Zidan Wang Aug. 12, 2015, 7:59 a.m. UTC | #2
On Tue, Aug 11, 2015 at 08:53:25PM -0700, Nicolin Chen wrote:
> On Wed, Aug 12, 2015 at 10:25:45AM +0800, Zidan Wang wrote:
> > After several open/close sai test with ctrl+c, there will be I/O error.
> > The SAI can't work anymore, can't recover. There will be no frame clock.
> > With adding the software reset in trigger stop, the issue can be fixed.
> 
> It doesn't look like a decent fix to me. Is it the only fix that
> IC team suggests? And why put this reset in the trigger function.
> Your MEGA fast patch has already included a software reset in the
> PM runtime functions. When dealing with CTRL+C test cases, that
> software reset should have worked as well.
> 
The MEGA fast patch add the suspend/resume function, but CTRL+C will not trigger suspend/resume function.
When CTRL+C, it will trigger stop and software reset SAI.
IC team suggest us to rest it, but I don't know if it's the only fix.

Best Regards,
Zidan Wang

> Nicolin
> 
> > Signed-off-by: Zidan Wang <zidan.wang@freescale.com>
> > ---
> >  sound/soc/fsl/fsl_sai.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
> > index 5c737f1..6a947dc 100644
> > --- a/sound/soc/fsl/fsl_sai.c
> > +++ b/sound/soc/fsl/fsl_sai.c
> > @@ -504,6 +504,13 @@ static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,
> >  					   FSL_SAI_CSR_FR, FSL_SAI_CSR_FR);
> >  			regmap_update_bits(sai->regmap, FSL_SAI_RCSR,
> >  					   FSL_SAI_CSR_FR, FSL_SAI_CSR_FR);
> > +
> > +			/* Software Reset for both Tx and Rx */
> > +			regmap_write(sai->regmap, FSL_SAI_TCSR, FSL_SAI_CSR_SR);
> > +			regmap_write(sai->regmap, FSL_SAI_RCSR, FSL_SAI_CSR_SR);
> > +			/* Clear SR bit to finish the reset */
> > +			regmap_write(sai->regmap, FSL_SAI_TCSR, 0);
> > +			regmap_write(sai->regmap, FSL_SAI_RCSR, 0);
> >  		}
> >  		break;
> >  	default:
> > -- 
> > 1.9.1
> >
Nicolin Chen Aug. 12, 2015, 9:19 a.m. UTC | #3
On Wed, Aug 12, 2015 at 03:59:15PM +0800, Zidan Wang wrote:
> On Tue, Aug 11, 2015 at 08:53:25PM -0700, Nicolin Chen wrote:
> > On Wed, Aug 12, 2015 at 10:25:45AM +0800, Zidan Wang wrote:
> > > After several open/close sai test with ctrl+c, there will be I/O error.
> > > The SAI can't work anymore, can't recover. There will be no frame clock.
> > > With adding the software reset in trigger stop, the issue can be fixed.
> > 
> > It doesn't look like a decent fix to me. Is it the only fix that
> > IC team suggests? And why put this reset in the trigger function.
> > Your MEGA fast patch has already included a software reset in the
> > PM runtime functions. When dealing with CTRL+C test cases, that
> > software reset should have worked as well.
> > 
> The MEGA fast patch add the suspend/resume function, but CTRL+C will not trigger suspend/resume function.
> When CTRL+C, it will trigger stop and software reset SAI.
> IC team suggest us to rest it, but I don't know if it's the only fix.

You can try to add SET_RUNTIME_PM_OPS() and to see if the suspend
function is called right after pressing ctrl+c.
Zidan Wang Aug. 18, 2015, 2:01 a.m. UTC | #4
On Wed, Aug 12, 2015 at 02:19:17AM -0700, Nicolin Chen wrote:
> On Wed, Aug 12, 2015 at 03:59:15PM +0800, Zidan Wang wrote:
> > On Tue, Aug 11, 2015 at 08:53:25PM -0700, Nicolin Chen wrote:
> > > On Wed, Aug 12, 2015 at 10:25:45AM +0800, Zidan Wang wrote:
> > > > After several open/close sai test with ctrl+c, there will be I/O error.
> > > > The SAI can't work anymore, can't recover. There will be no frame clock.
> > > > With adding the software reset in trigger stop, the issue can be fixed.
> > > 
> > > It doesn't look like a decent fix to me. Is it the only fix that
> > > IC team suggests? And why put this reset in the trigger function.
> > > Your MEGA fast patch has already included a software reset in the
> > > PM runtime functions. When dealing with CTRL+C test cases, that
> > > software reset should have worked as well.
> > > 
> > The MEGA fast patch add the suspend/resume function, but CTRL+C will not trigger suspend/resume function.
> > When CTRL+C, it will trigger stop and software reset SAI.
> > IC team suggest us to rest it, but I don't know if it's the only fix.
> 
> You can try to add SET_RUNTIME_PM_OPS() and to see if the suspend
> function is called right after pressing ctrl+c.
The runtime suspend function will be call after the power down time. So if i playback again before the power down time, runtime suspend will not be called.

Best Regards,
Zidan Wang
Nicolin Chen Aug. 21, 2015, 7:47 a.m. UTC | #5
On Tue, Aug 18, 2015 at 10:01:54AM +0800, Zidan Wang wrote:

> > > > > After several open/close sai test with ctrl+c, there will be I/O error.
> > > > > The SAI can't work anymore, can't recover. There will be no frame clock.
> > > > > With adding the software reset in trigger stop, the issue can be fixed.

> > > > It doesn't look like a decent fix to me. Is it the only fix that
> > > > IC team suggests? And why put this reset in the trigger function.
> > > > Your MEGA fast patch has already included a software reset in the
> > > > PM runtime functions. When dealing with CTRL+C test cases, that
> > > > software reset should have worked as well.

> > > The MEGA fast patch add the suspend/resume function, but CTRL+C will not
> > > trigger suspend/resume function.
> > > When CTRL+C, it will trigger stop and software reset SAI.
> > > IC team suggest us to rest it, but I don't know if it's the only fix.

> > You can try to add SET_RUNTIME_PM_OPS() and to see if the suspend
> > function is called right after pressing ctrl+c.

> The runtime suspend function will be call after the power down time. So if i
> playback again before the power down time, runtime suspend will not be called.

I see.. Can you provide me a test case to reproduce this issue?
Zidan Wang Aug. 21, 2015, 8:40 a.m. UTC | #6
On Fri, Aug 21, 2015 at 12:47:37AM -0700, Nicolin Chen wrote:
> On Tue, Aug 18, 2015 at 10:01:54AM +0800, Zidan Wang wrote:
> 
> > > > > > After several open/close sai test with ctrl+c, there will be I/O error.
> > > > > > The SAI can't work anymore, can't recover. There will be no frame clock.
> > > > > > With adding the software reset in trigger stop, the issue can be fixed.
> 
> > > > > It doesn't look like a decent fix to me. Is it the only fix that
> > > > > IC team suggests? And why put this reset in the trigger function.
> > > > > Your MEGA fast patch has already included a software reset in the
> > > > > PM runtime functions. When dealing with CTRL+C test cases, that
> > > > > software reset should have worked as well.
> 
> > > > The MEGA fast patch add the suspend/resume function, but CTRL+C will not
> > > > trigger suspend/resume function.
> > > > When CTRL+C, it will trigger stop and software reset SAI.
> > > > IC team suggest us to rest it, but I don't know if it's the only fix.
> 
> > > You can try to add SET_RUNTIME_PM_OPS() and to see if the suspend
> > > function is called right after pressing ctrl+c.
> 
> > The runtime suspend function will be call after the power down time. So if i
> > playback again before the power down time, runtime suspend will not be called.
> 
> I see.. Can you provide me a test case to reproduce this issue?

1. aplay -Dhw:0 /unit_tests/audio8k16S.wav
2. ctrl+c

Set SAI to master mode, then try it several times.

Best Regards,
Zidan Wang
Nicolin Chen Oct. 23, 2015, 7:48 a.m. UTC | #7
Hi,
	Sorry for late reply.

On Fri, Aug 21, 2015 at 04:40:20PM +0800, Zidan Wang wrote:
> > > > > > > After several open/close sai test with ctrl+c, there will be I/O error.
> > > > > > > The SAI can't work anymore, can't recover. There will be no frame clock.
> > > > > > > With adding the software reset in trigger stop, the issue can be fixed.
> > 
> > > > > > It doesn't look like a decent fix to me. Is it the only fix that
> > > > > > IC team suggests? And why put this reset in the trigger function.
> > > > > > Your MEGA fast patch has already included a software reset in the
> > > > > > PM runtime functions. When dealing with CTRL+C test cases, that
> > > > > > software reset should have worked as well.
> > 
> > > > > The MEGA fast patch add the suspend/resume function, but CTRL+C will not
> > > > > trigger suspend/resume function.
> > > > > When CTRL+C, it will trigger stop and software reset SAI.
> > > > > IC team suggest us to rest it, but I don't know if it's the only fix.
> > 
> > > > You can try to add SET_RUNTIME_PM_OPS() and to see if the suspend
> > > > function is called right after pressing ctrl+c.
> > 
> > > The runtime suspend function will be call after the power down time. So if i
> > > playback again before the power down time, runtime suspend will not be called.
> > 
> > I see.. Can you provide me a test case to reproduce this issue?
> 
> 1. aplay -Dhw:0 /unit_tests/audio8k16S.wav
> 2. ctrl+c
> 
> Set SAI to master mode, then try it several times.

I've reproduced the issue and tried a few fixes but it turns out
putting a reset procedure in the trigger is seemly the only fix.
(Even using pm_runtime without power down delay does not cover
 all the test cases.)

So I suggest you first to double confirm with the IC team if the
problem is caused by defect of the internal bit clock generator
and reseting is the only option. After that, I'll accept the fix.

However, you may also need to refine your commit log and comments
in the driver for the following points:

1) This is a hardware bug/errata and reset is the only option.
2) According to the reference manual, the software reset doesn't
   reset any control register but only internal hardware logics
   such as bit clock generator, status flags, and FIFO pointers.
   (Our purpose is just to reset the clock generator while the
    software reset is the only way to do that.)
3) Since slave mode doesn't use the clock generator, only apply
   the reset procedure to the master mode.

Additionally, we may also need to take care of asynchronous mode
later as TX clock generator will not be reset when RX is still
running.

Nicolin

Patch
diff mbox

diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index 5c737f1..6a947dc 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -504,6 +504,13 @@  static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,
 					   FSL_SAI_CSR_FR, FSL_SAI_CSR_FR);
 			regmap_update_bits(sai->regmap, FSL_SAI_RCSR,
 					   FSL_SAI_CSR_FR, FSL_SAI_CSR_FR);
+
+			/* Software Reset for both Tx and Rx */
+			regmap_write(sai->regmap, FSL_SAI_TCSR, FSL_SAI_CSR_SR);
+			regmap_write(sai->regmap, FSL_SAI_RCSR, FSL_SAI_CSR_SR);
+			/* Clear SR bit to finish the reset */
+			regmap_write(sai->regmap, FSL_SAI_TCSR, 0);
+			regmap_write(sai->regmap, FSL_SAI_RCSR, 0);
 		}
 		break;
 	default: