[v3,1/4] ASoC: fsl_sai: Add driver suspend and resume to support MEGA Fast
diff mbox

Message ID 6fa4e6ebf1f34f5d637324c9f62e68b03037568c.1438928296.git.zidan.wang@freescale.com
State Accepted
Commit 1fde5e83a17acbcfcce27f68be46a6da4344efbd
Headers show

Commit Message

Zidan Wang Aug. 7, 2015, 6:21 a.m. UTC
For i.MX6 SoloX, there is a mode of the SoC to shutdown all power source of
modules during system suspend and resume procedure. Thus, SAI needs to save
all the values of registers before the system suspend and restore them after
the system resume.

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

Comments

Nicolin Chen Aug. 11, 2015, 9:12 a.m. UTC | #1
On Fri, Aug 07, 2015 at 02:21:05PM +0800, Zidan Wang wrote:
> For i.MX6 SoloX, there is a mode of the SoC to shutdown all power source of
> modules during system suspend and resume procedure. Thus, SAI needs to save
> all the values of registers before the system suspend and restore them after
> the system resume.
> 
> Signed-off-by: Zidan Wang <zidan.wang@freescale.com>

Have you tested this series based on the for-next branch?

I'm having trouble with suspend/resume test on my imx6sx-sdb.
Both broonie/for-next and linux-next/master hanged after suspend
even without this PATCH -- There should be some other patches
that broke the suspend/resume. Do you know which one?

Nicolin

> ---
>  sound/soc/fsl/fsl_sai.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
> index a18fd92..5c737f1 100644
> --- a/sound/soc/fsl/fsl_sai.c
> +++ b/sound/soc/fsl/fsl_sai.c
> @@ -637,6 +637,8 @@ static bool fsl_sai_readable_reg(struct device *dev, unsigned int reg)
>  static bool fsl_sai_volatile_reg(struct device *dev, unsigned int reg)
>  {
>  	switch (reg) {
> +	case FSL_SAI_TCSR:
> +	case FSL_SAI_RCSR:
>  	case FSL_SAI_TFR:
>  	case FSL_SAI_RFR:
>  	case FSL_SAI_TDR:
> @@ -681,6 +683,7 @@ static const struct regmap_config fsl_sai_regmap_config = {
>  	.readable_reg = fsl_sai_readable_reg,
>  	.volatile_reg = fsl_sai_volatile_reg,
>  	.writeable_reg = fsl_sai_writeable_reg,
> +	.cache_type = REGCACHE_FLAT,
>  };
>  
>  static int fsl_sai_probe(struct platform_device *pdev)
> @@ -802,10 +805,40 @@ static const struct of_device_id fsl_sai_ids[] = {
>  	{ /* sentinel */ }
>  };
>  
> +#if CONFIG_PM_SLEEP
> +static int fsl_sai_suspend(struct device *dev)
> +{
> +	struct fsl_sai *sai = dev_get_drvdata(dev);
> +
> +	regcache_cache_only(sai->regmap, true);
> +	regcache_mark_dirty(sai->regmap);
> +
> +	return 0;
> +}
> +
> +static int fsl_sai_resume(struct device *dev)
> +{
> +	struct fsl_sai *sai = dev_get_drvdata(dev);
> +
> +	regcache_cache_only(sai->regmap, false);
> +	regmap_write(sai->regmap, FSL_SAI_TCSR, FSL_SAI_CSR_SR);
> +	regmap_write(sai->regmap, FSL_SAI_RCSR, FSL_SAI_CSR_SR);
> +	msleep(1);
> +	regmap_write(sai->regmap, FSL_SAI_TCSR, 0);
> +	regmap_write(sai->regmap, FSL_SAI_RCSR, 0);
> +	return regcache_sync(sai->regmap);
> +}
> +#endif /* CONFIG_PM_SLEEP */
> +
> +static const struct dev_pm_ops fsl_sai_pm_ops = {
> +	SET_SYSTEM_SLEEP_PM_OPS(fsl_sai_suspend, fsl_sai_resume)
> +};
> +
>  static struct platform_driver fsl_sai_driver = {
>  	.probe = fsl_sai_probe,
>  	.driver = {
>  		.name = "fsl-sai",
> +		.pm = &fsl_sai_pm_ops,
>  		.of_match_table = fsl_sai_ids,
>  	},
>  };
> -- 
> 1.9.1
>
Zidan Wang Aug. 11, 2015, 9:28 a.m. UTC | #2
On Tue, Aug 11, 2015 at 02:12:21AM -0700, Nicolin Chen wrote:
> On Fri, Aug 07, 2015 at 02:21:05PM +0800, Zidan Wang wrote:
> > For i.MX6 SoloX, there is a mode of the SoC to shutdown all power source of
> > modules during system suspend and resume procedure. Thus, SAI needs to save
> > all the values of registers before the system suspend and restore them after
> > the system resume.
> > 
> > Signed-off-by: Zidan Wang <zidan.wang@freescale.com>
> 
> Have you tested this series based on the for-next branch?
> 
> I'm having trouble with suspend/resume test on my imx6sx-sdb.
> Both broonie/for-next and linux-next/master hanged after suspend
> even without this PATCH -- There should be some other patches
> that broke the suspend/resume. Do you know which one?
> 
I just rebase to the newest linux-next/master, and don't meet system hang after suspend on imx6sx-sdb board.
Zidan Wang Aug. 11, 2015, 9:34 a.m. UTC | #3
On Tue, Aug 11, 2015 at 07:41:52AM -0300, Fabio Estevam wrote:
> On Tue, Aug 11, 2015 at 6:12 AM, Nicolin Chen <nicoleotsuka@gmail.com> wrote:
> > On Fri, Aug 07, 2015 at 02:21:05PM +0800, Zidan Wang wrote:
> >> For i.MX6 SoloX, there is a mode of the SoC to shutdown all power source of
> >> modules during system suspend and resume procedure. Thus, SAI needs to save
> >> all the values of registers before the system suspend and restore them after
> >> the system resume.
> >>
> >> Signed-off-by: Zidan Wang <zidan.wang@freescale.com>
> >
> > Have you tested this series based on the for-next branch?
> 
> I am also interested in testing sai, but if I recall correctly we
> still miss the SDMA remap feature, right?
> 
I have sent the SDMA remap patch to community, but have no response now. I can share the patch for you.

Best Regards,
Zidan Wang
> Regards,
> 
> Fabio Estevam
Fabio Estevam Aug. 11, 2015, 10:41 a.m. UTC | #4
On Tue, Aug 11, 2015 at 6:12 AM, Nicolin Chen <nicoleotsuka@gmail.com> wrote:
> On Fri, Aug 07, 2015 at 02:21:05PM +0800, Zidan Wang wrote:
>> For i.MX6 SoloX, there is a mode of the SoC to shutdown all power source of
>> modules during system suspend and resume procedure. Thus, SAI needs to save
>> all the values of registers before the system suspend and restore them after
>> the system resume.
>>
>> Signed-off-by: Zidan Wang <zidan.wang@freescale.com>
>
> Have you tested this series based on the for-next branch?

I am also interested in testing sai, but if I recall correctly we
still miss the SDMA remap feature, right?

Regards,

Fabio Estevam
Fabio Estevam Aug. 11, 2015, 10:46 a.m. UTC | #5
On Tue, Aug 11, 2015 at 6:34 AM, Zidan Wang <zidan.wang@freescale.com> wrote:

> I have sent the SDMA remap patch to community, but have no response now. I can share the patch for you.

Please share the link to your patch, thanks.
Nicolin Chen Sept. 16, 2015, 5:08 a.m. UTC | #6
On Fri, Aug 07, 2015 at 02:21:05PM +0800, Zidan Wang wrote:
> For i.MX6 SoloX, there is a mode of the SoC to shutdown all power source of
> modules during system suspend and resume procedure. Thus, SAI needs to save
> all the values of registers before the system suspend and restore them after
> the system resume.
> 
> Signed-off-by: Zidan Wang <zidan.wang@freescale.com>

For this series,

Acked-by: Nicolin Chen <nicoleotsuka@gmail.com>

I'm still having trouble to test system suspend/resume even without
these PATCHes. But they look fine to me.

Thank you
Nicolin

> ---
>  sound/soc/fsl/fsl_sai.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
> index a18fd92..5c737f1 100644
> --- a/sound/soc/fsl/fsl_sai.c
> +++ b/sound/soc/fsl/fsl_sai.c
> @@ -637,6 +637,8 @@ static bool fsl_sai_readable_reg(struct device *dev, unsigned int reg)
>  static bool fsl_sai_volatile_reg(struct device *dev, unsigned int reg)
>  {
>  	switch (reg) {
> +	case FSL_SAI_TCSR:
> +	case FSL_SAI_RCSR:
>  	case FSL_SAI_TFR:
>  	case FSL_SAI_RFR:
>  	case FSL_SAI_TDR:
> @@ -681,6 +683,7 @@ static const struct regmap_config fsl_sai_regmap_config = {
>  	.readable_reg = fsl_sai_readable_reg,
>  	.volatile_reg = fsl_sai_volatile_reg,
>  	.writeable_reg = fsl_sai_writeable_reg,
> +	.cache_type = REGCACHE_FLAT,
>  };
>  
>  static int fsl_sai_probe(struct platform_device *pdev)
> @@ -802,10 +805,40 @@ static const struct of_device_id fsl_sai_ids[] = {
>  	{ /* sentinel */ }
>  };
>  
> +#if CONFIG_PM_SLEEP
> +static int fsl_sai_suspend(struct device *dev)
> +{
> +	struct fsl_sai *sai = dev_get_drvdata(dev);
> +
> +	regcache_cache_only(sai->regmap, true);
> +	regcache_mark_dirty(sai->regmap);
> +
> +	return 0;
> +}
> +
> +static int fsl_sai_resume(struct device *dev)
> +{
> +	struct fsl_sai *sai = dev_get_drvdata(dev);
> +
> +	regcache_cache_only(sai->regmap, false);
> +	regmap_write(sai->regmap, FSL_SAI_TCSR, FSL_SAI_CSR_SR);
> +	regmap_write(sai->regmap, FSL_SAI_RCSR, FSL_SAI_CSR_SR);
> +	msleep(1);
> +	regmap_write(sai->regmap, FSL_SAI_TCSR, 0);
> +	regmap_write(sai->regmap, FSL_SAI_RCSR, 0);
> +	return regcache_sync(sai->regmap);
> +}
> +#endif /* CONFIG_PM_SLEEP */
> +
> +static const struct dev_pm_ops fsl_sai_pm_ops = {
> +	SET_SYSTEM_SLEEP_PM_OPS(fsl_sai_suspend, fsl_sai_resume)
> +};
> +
>  static struct platform_driver fsl_sai_driver = {
>  	.probe = fsl_sai_probe,
>  	.driver = {
>  		.name = "fsl-sai",
> +		.pm = &fsl_sai_pm_ops,
>  		.of_match_table = fsl_sai_ids,
>  	},
>  };
> -- 
> 1.9.1
>

Patch
diff mbox

diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index a18fd92..5c737f1 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -637,6 +637,8 @@  static bool fsl_sai_readable_reg(struct device *dev, unsigned int reg)
 static bool fsl_sai_volatile_reg(struct device *dev, unsigned int reg)
 {
 	switch (reg) {
+	case FSL_SAI_TCSR:
+	case FSL_SAI_RCSR:
 	case FSL_SAI_TFR:
 	case FSL_SAI_RFR:
 	case FSL_SAI_TDR:
@@ -681,6 +683,7 @@  static const struct regmap_config fsl_sai_regmap_config = {
 	.readable_reg = fsl_sai_readable_reg,
 	.volatile_reg = fsl_sai_volatile_reg,
 	.writeable_reg = fsl_sai_writeable_reg,
+	.cache_type = REGCACHE_FLAT,
 };
 
 static int fsl_sai_probe(struct platform_device *pdev)
@@ -802,10 +805,40 @@  static const struct of_device_id fsl_sai_ids[] = {
 	{ /* sentinel */ }
 };
 
+#if CONFIG_PM_SLEEP
+static int fsl_sai_suspend(struct device *dev)
+{
+	struct fsl_sai *sai = dev_get_drvdata(dev);
+
+	regcache_cache_only(sai->regmap, true);
+	regcache_mark_dirty(sai->regmap);
+
+	return 0;
+}
+
+static int fsl_sai_resume(struct device *dev)
+{
+	struct fsl_sai *sai = dev_get_drvdata(dev);
+
+	regcache_cache_only(sai->regmap, false);
+	regmap_write(sai->regmap, FSL_SAI_TCSR, FSL_SAI_CSR_SR);
+	regmap_write(sai->regmap, FSL_SAI_RCSR, FSL_SAI_CSR_SR);
+	msleep(1);
+	regmap_write(sai->regmap, FSL_SAI_TCSR, 0);
+	regmap_write(sai->regmap, FSL_SAI_RCSR, 0);
+	return regcache_sync(sai->regmap);
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static const struct dev_pm_ops fsl_sai_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(fsl_sai_suspend, fsl_sai_resume)
+};
+
 static struct platform_driver fsl_sai_driver = {
 	.probe = fsl_sai_probe,
 	.driver = {
 		.name = "fsl-sai",
+		.pm = &fsl_sai_pm_ops,
 		.of_match_table = fsl_sai_ids,
 	},
 };