Skip to contentSkip to conversation

mtd: rawnand: gpmi: fix the suspend/resume issue

PATCH In review Han Xu 4 participants 7 messages Jan 9, 2020 – Jan 14, 2020

Subsystems (3)
lore
Share & tools
lore

Han Xu

author maintainer
#0 lore raw

PATCH 1/1 mtd: rawnand: gpmi: fix the suspend/resume issue

fix several issues when system suspend/resume,

- leverage the runtime pm for system suspend/resume
- enable the clock before register access
- re-apply timing settings
- set the proper pinctrl state

---
 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 59 ++++++++++++++++------
 1 file changed, 44 insertions(+), 15 deletions(-)
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +44 -15
index 334fe3130285..37437d47ab9a 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/dma/mxs-dma.h>
 #include "gpmi-nand.h"
 #include "gpmi-regs.h"
@@ -146,7 +147,11 @@ static int __gpmi_enable_clk(struct gpmi_nand_data *this, bool v)
 static int gpmi_init(struct gpmi_nand_data *this)
 {
 	struct resources *r = &this->resources;
-	int ret;
+	int ret = 0;
+
+	ret = pm_runtime_get_sync(this->dev);
+	if (ret < 0)
+		return ret;
 
 	ret = gpmi_reset_block(r->gpmi_regs, false);
 	if (ret)
@@ -179,8 +184,10 @@ static int gpmi_init(struct gpmi_nand_data *this)
 	 */
 	writel(BM_GPMI_CTRL1_DECOUPLE_CS, r->gpmi_regs + HW_GPMI_CTRL1_SET);
 
-	return 0;
 err_out:
+	pm_runtime_mark_last_busy(this->dev);
+	pm_runtime_put_autosuspend(this->dev);
+
 	return ret;
 }
 
@@ -528,7 +535,7 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this)
 static int bch_set_geometry(struct gpmi_nand_data *this)
 {
 	struct resources *r = &this->resources;
-	int ret;
+	int ret = 0;
 
 	ret = common_nfc_set_geometry(this);
 	if (ret)
@@ -550,7 +557,6 @@ static int bch_set_geometry(struct gpmi_nand_data *this)
 	/* Set *all* chip selects to use layout 0. */
 	writel(0, r->bch_regs + HW_BCH_LAYOUTSELECT);
 
-	ret = 0;
 err_out:
 	pm_runtime_mark_last_busy(this->dev);
 	pm_runtime_put_autosuspend(this->dev);
@@ -2676,7 +2682,7 @@ static int gpmi_nand_probe(struct platform_device *pdev)
 	return 0;
 
 exit_nfc_init:
-	pm_runtime_put(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	release_resources(this);
 exit_acquire_resources:
@@ -2688,7 +2694,6 @@ static int gpmi_nand_remove(struct platform_device *pdev)
 {
 	struct gpmi_nand_data *this = platform_get_drvdata(pdev);
 
-	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
 	nand_release(&this->nand);
@@ -2700,10 +2705,12 @@ static int gpmi_nand_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int gpmi_pm_suspend(struct device *dev)
 {
-	struct gpmi_nand_data *this = dev_get_drvdata(dev);
+	int ret;
 
-	release_dma_channels(this);
-	return 0;
+	pinctrl_pm_select_sleep_state(dev);
+	ret = pm_runtime_force_suspend(dev);
+
+	return ret;
 }
 
 static int gpmi_pm_resume(struct device *dev)
@@ -2711,9 +2718,13 @@ static int gpmi_pm_resume(struct device *dev)
 	struct gpmi_nand_data *this = dev_get_drvdata(dev);
 	int ret;
 
-	ret = acquire_dma_channels(this);
-	if (ret < 0)
+	ret = pm_runtime_force_resume(dev);
+	if (ret) {
+		dev_err(this->dev, "Error in resume %d\n", ret);
 		return ret;
+	}
+
+	pinctrl_pm_select_default_state(dev);
 
 	/* re-init the GPMI registers */
 	ret = gpmi_init(this);
@@ -2729,22 +2740,40 @@ static int gpmi_pm_resume(struct device *dev)
 		return ret;
 	}
 
+	/* re-apply the timing setting */
+	this->hw.must_apply_timings = true;
+
 	return 0;
 }
 #endif /* CONFIG_PM_SLEEP */
 
-static int __maybe_unused gpmi_runtime_suspend(struct device *dev)
+#define gpmi_enable_clk(x)	__gpmi_enable_clk(x, true)
+#define gpmi_disable_clk(x)	__gpmi_enable_clk(x, false)
+
+static int gpmi_runtime_suspend(struct device *dev)
 {
 	struct gpmi_nand_data *this = dev_get_drvdata(dev);
 
-	return __gpmi_enable_clk(this, false);
+	gpmi_disable_clk(this);
+	release_dma_channels(this);
+
+	return 0;
 }
 
-static int __maybe_unused gpmi_runtime_resume(struct device *dev)
+static int gpmi_runtime_resume(struct device *dev)
 {
 	struct gpmi_nand_data *this = dev_get_drvdata(dev);
+	int ret;
 
-	return __gpmi_enable_clk(this, true);
+	ret = gpmi_enable_clk(this);
+	if (ret)
+		return ret;
+
+	ret = acquire_dma_channels(this);
+	if (ret < 0)
+		return ret;
+
+	return 0;
 }
 
 static const struct dev_pm_ops gpmi_pm_ops = {
Signature · 6 lines
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#1 lore raw

Hi Esben, Han,

Han Xu <[email protected]> wrote on Fri, 10 Jan 2020 01:05:56 +0800:

Quoted 6 lines

fix several issues when system suspend/resume,

- leverage the runtime pm for system suspend/resume
- enable the clock before register access
- re-apply timing settings
- set the proper pinctrl state

Esben are you fine with this patch?

Or maybe Han you could take over Eben's patch and extend it?

Quoted 144 lines
---
 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 59 ++++++++++++++++------
 1 file changed, 44 insertions(+), 15 deletions(-)
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +37 -15
index 334fe3130285..37437d47ab9a 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/dma/mxs-dma.h>
 #include "gpmi-nand.h"
 #include "gpmi-regs.h"
@@ -146,7 +147,11 @@ static int __gpmi_enable_clk(struct gpmi_nand_data *this, bool v)
 static int gpmi_init(struct gpmi_nand_data *this)
 {
 	struct resources *r = &this->resources;
-	int ret;
+	int ret = 0;
+
+	ret = pm_runtime_get_sync(this->dev);
+	if (ret < 0)
+		return ret;
 
 	ret = gpmi_reset_block(r->gpmi_regs, false);
 	if (ret)
@@ -179,8 +184,10 @@ static int gpmi_init(struct gpmi_nand_data *this)
 	 */
 	writel(BM_GPMI_CTRL1_DECOUPLE_CS, r->gpmi_regs + HW_GPMI_CTRL1_SET);
 
-	return 0;
 err_out:
+	pm_runtime_mark_last_busy(this->dev);
+	pm_runtime_put_autosuspend(this->dev);
+
 	return ret;
 }
 
@@ -528,7 +535,7 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this)
 static int bch_set_geometry(struct gpmi_nand_data *this)
 {
 	struct resources *r = &this->resources;
-	int ret;
+	int ret = 0;
 
 	ret = common_nfc_set_geometry(this);
 	if (ret)
@@ -550,7 +557,6 @@ static int bch_set_geometry(struct gpmi_nand_data *this)
 	/* Set *all* chip selects to use layout 0. */
 	writel(0, r->bch_regs + HW_BCH_LAYOUTSELECT);
 
-	ret = 0;
 err_out:
 	pm_runtime_mark_last_busy(this->dev);
 	pm_runtime_put_autosuspend(this->dev);
@@ -2676,7 +2682,7 @@ static int gpmi_nand_probe(struct platform_device *pdev)
 	return 0;
 
 exit_nfc_init:
-	pm_runtime_put(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	release_resources(this);
 exit_acquire_resources:
@@ -2688,7 +2694,6 @@ static int gpmi_nand_remove(struct platform_device *pdev)
 {
 	struct gpmi_nand_data *this = platform_get_drvdata(pdev);
 
-	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
 	nand_release(&this->nand);
@@ -2700,10 +2705,12 @@ static int gpmi_nand_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int gpmi_pm_suspend(struct device *dev)
 {
-	struct gpmi_nand_data *this = dev_get_drvdata(dev);
+	int ret;
 
-	release_dma_channels(this);
-	return 0;
+	pinctrl_pm_select_sleep_state(dev);
+	ret = pm_runtime_force_suspend(dev);
+
+	return ret;
 }
 
 static int gpmi_pm_resume(struct device *dev)
@@ -2711,9 +2718,13 @@ static int gpmi_pm_resume(struct device *dev)
 	struct gpmi_nand_data *this = dev_get_drvdata(dev);
 	int ret;
 
-	ret = acquire_dma_channels(this);
-	if (ret < 0)
+	ret = pm_runtime_force_resume(dev);
+	if (ret) {
+		dev_err(this->dev, "Error in resume %d\n", ret);
 		return ret;
+	}
+
+	pinctrl_pm_select_default_state(dev);
 
 	/* re-init the GPMI registers */
 	ret = gpmi_init(this);
@@ -2729,22 +2740,40 @@ static int gpmi_pm_resume(struct device *dev)
 		return ret;
 	}
 
+	/* re-apply the timing setting */
+	this->hw.must_apply_timings = true;
+
 	return 0;
 }
 #endif /* CONFIG_PM_SLEEP */
 
-static int __maybe_unused gpmi_runtime_suspend(struct device *dev)
+#define gpmi_enable_clk(x)	__gpmi_enable_clk(x, true)
+#define gpmi_disable_clk(x)	__gpmi_enable_clk(x, false)
+
+static int gpmi_runtime_suspend(struct device *dev)
 {
 	struct gpmi_nand_data *this = dev_get_drvdata(dev);
 
-	return __gpmi_enable_clk(this, false);
+	gpmi_disable_clk(this);
+	release_dma_channels(this);
+
+	return 0;
 }
 
-static int __maybe_unused gpmi_runtime_resume(struct device *dev)
+static int gpmi_runtime_resume(struct device *dev)
 {
 	struct gpmi_nand_data *this = dev_get_drvdata(dev);
+	int ret;
 
-	return __gpmi_enable_clk(this, true);
+	ret = gpmi_enable_clk(this);
+	if (ret)

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_pm_resume(struct device *dev) · line 2779

Quoted 10 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +7 -0
+		return ret;
+
+	ret = acquire_dma_channels(this);
+	if (ret < 0)
+		return ret;
+
+	return 0;
 }
 
 static const struct dev_pm_ops gpmi_pm_ops = {

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#2 lore raw
Quoted 4 lines · Miquel Raynal

Hi Esben, Han,

Han Xu <[email protected]> wrote on Fri, 10 Jan 2020 01:05:56 +0800:

Quoted 8 lines
Quoted 6 lines

fix several issues when system suspend/resume,

- leverage the runtime pm for system suspend/resume
- enable the clock before register access
- re-apply timing settings
- set the proper pinctrl state

Esben are you fine with this patch?

It sounds like something that should probably be 4 separate patches.

Quoted 1 line

Or maybe Han you could take over Esben's patch and extend it?

I don't see why my two patches, which covers point 1 and 3 in the list of issues covered by Han's patch, should not be merged.

Han, would you mind re-spin your patch to two separate patches covering the remaining issues

- enable the clock before register access
- set the proper pinctrl state

/Esben

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#3 lore raw
Quoted 18 lines · Esben Haabendal
Quoted 4 lines · Miquel Raynal

Hi Esben, Han,

Han Xu <[email protected]> wrote on Fri, 10 Jan 2020 01:05:56 +0800:

Quoted 8 lines
Quoted 6 lines

fix several issues when system suspend/resume,

- leverage the runtime pm for system suspend/resume
- enable the clock before register access
- re-apply timing settings
- set the proper pinctrl state

Esben are you fine with this patch?

It sounds like something that should probably be 4 separate patches.

Quoted 7 lines
Quoted 1 line

Or maybe Han you could take over Esben's patch and extend it?

I don't see why my two patches, which covers point 1 and 3 in the list of issues covered by Han's patch, should not be merged.

Han, would you mind re-spin your patch to two separate patches covering the remaining issues

I am fine to keep your patches and re-spin the rest changes.

Quoted 9 lines

- enable the clock before register access
- set the proper pinctrl state

/Esben

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Signature · 7 lines
Sincerely,

Han XU

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#4 lore raw

Hi Han,

Han Xu <[email protected]> wrote on Thu, 9 Jan 2020 14:09:24 -0600:

Quoted 21 lines · Esben Haabendal
Quoted 20 lines
Quoted 4 lines · Miquel Raynal

Hi Esben, Han,

Han Xu <[email protected]> wrote on Fri, 10 Jan 2020 01:05:56 +0800:

Quoted 8 lines
Quoted 6 lines

fix several issues when system suspend/resume,

- leverage the runtime pm for system suspend/resume
- enable the clock before register access
- re-apply timing settings
- set the proper pinctrl state

Esben are you fine with this patch?

It sounds like something that should probably be 4 separate patches.

Quoted 1 line

Or maybe Han you could take over Esben's patch and extend it?

Quoted 7 lines
Quoted 5 lines

I don't see why my two patches, which covers point 1 and 3 in the list of issues covered by Han's patch, should not be merged.

Han, would you mind re-spin your patch to two separate patches covering the remaining issues

I am fine to keep your patches and re-spin the rest changes.

Great, I'll queue Esben patches for 5.6 then.

Would you mind acking them?

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#5 lore raw
In reply to Han Xu

Hi Han

See comments/questions below.

If I understand the purpose of some of your changes correct, you are fixing the handling of pm usage counter, as it currently is incremented in gpmi_init() and decremented in gpmi_nand_remove(). I believe that would be nice to have in a separate patch with an explanation of the change.

Quoted 25 lines · Han Xu

fix several issues when system suspend/resume,

- leverage the runtime pm for system suspend/resume
- enable the clock before register access
- re-apply timing settings
- set the proper pinctrl state

---
 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 59 ++++++++++++++++------
 1 file changed, 44 insertions(+), 15 deletions(-)
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +1 -0
index 334fe3130285..37437d47ab9a 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/dma/mxs-dma.h>
 #include "gpmi-nand.h"
 #include "gpmi-regs.h"

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int __gpmi_enable_clk(struct gpmi_nand_data *this, bool v) · line 150

Quoted 5 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +1 -1
@@ -146,7 +147,11 @@ static int __gpmi_enable_clk(struct gpmi_nand_data *this, bool v)
 static int gpmi_init(struct gpmi_nand_data *this)
 {
 	struct resources *r = &this->resources;
-	int ret;
+	int ret = 0;

I don't see why this is changed, given that ret is unconditionally assigned in the next line.

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_init(struct gpmi_nand_data *this) · line 182

Quoted 12 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +4 -1
+
+	ret = pm_runtime_get_sync(this->dev);
+	if (ret < 0)
+		return ret;
 
 	ret = gpmi_reset_block(r->gpmi_regs, false);
 	if (ret)
@@ -179,8 +184,10 @@ static int gpmi_init(struct gpmi_nand_data *this)
 	 */
 	writel(BM_GPMI_CTRL1_DECOUPLE_CS, r->gpmi_regs + HW_GPMI_CTRL1_SET);
 
-	return 0;

Please provide an explanation of the reasoning of this change is.

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int common_nfc_set_geometry(struct gpmi_nand_data *this) · line 538

Quoted 13 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +4 -1
 err_out:
+	pm_runtime_mark_last_busy(this->dev);
+	pm_runtime_put_autosuspend(this->dev);
+
 	return ret;
 }
 
@@ -528,7 +535,7 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this)
 static int bch_set_geometry(struct gpmi_nand_data *this)
 {
 	struct resources *r = &this->resources;
-	int ret;
+	int ret = 0;

I don't see any reason for this change.

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_nand_probe(struct platform_device *pdev) · line 2679

Quoted 7 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +0 -1
 	ret = common_nfc_set_geometry(this);
 	if (ret)
@@ -2676,7 +2682,7 @@ static int gpmi_nand_probe(struct platform_device *pdev)
 	return 0;
 
 exit_nfc_init:
-	pm_runtime_put(&pdev->dev);

I guess this is because of the change above that causes usage counter not to be incremented in gpmi_init() when it is successful.

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_nand_probe(struct platform_device *pdev) · line 2685

Quoted 1 line
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +1 -0
+	pm_runtime_dont_use_autosuspend(&pdev->dev);

Is this required before pm_runtime_disable()?

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_nand_remove(struct platform_device *pdev) · line 2691

Quoted 8 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +0 -1
 	pm_runtime_disable(&pdev->dev);
 	release_resources(this);
 exit_acquire_resources:
@@ -2688,7 +2694,6 @@ static int gpmi_nand_remove(struct platform_device *pdev)
 {
 	struct gpmi_nand_data *this = platform_get_drvdata(pdev);
 
-	pm_runtime_put_sync(&pdev->dev);

Should be covered by explanation of the change in gpmi_init().

Quoted 70 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +26 -9
 	pm_runtime_disable(&pdev->dev);
 
 	nand_release(&this->nand);
@@ -2700,10 +2705,12 @@ static int gpmi_nand_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int gpmi_pm_suspend(struct device *dev)
 {
-	struct gpmi_nand_data *this = dev_get_drvdata(dev);
+	int ret;
 
-	release_dma_channels(this);
-	return 0;
+	pinctrl_pm_select_sleep_state(dev);
+	ret = pm_runtime_force_suspend(dev);
+
+	return ret;
 }
 
 static int gpmi_pm_resume(struct device *dev)
@@ -2711,9 +2718,13 @@ static int gpmi_pm_resume(struct device *dev)
 	struct gpmi_nand_data *this = dev_get_drvdata(dev);
 	int ret;
 
-	ret = acquire_dma_channels(this);
-	if (ret < 0)
+	ret = pm_runtime_force_resume(dev);
+	if (ret) {
+		dev_err(this->dev, "Error in resume %d\n", ret);
 		return ret;
+	}
+
+	pinctrl_pm_select_default_state(dev);
 
 	/* re-init the GPMI registers */
 	ret = gpmi_init(this);
@@ -2729,22 +2740,40 @@ static int gpmi_pm_resume(struct device *dev)
 		return ret;
 	}
 
+	/* re-apply the timing setting */
+	this->hw.must_apply_timings = true;
+
 	return 0;
 }
 #endif /* CONFIG_PM_SLEEP */
 
-static int __maybe_unused gpmi_runtime_suspend(struct device *dev)
+#define gpmi_enable_clk(x)	__gpmi_enable_clk(x, true)
+#define gpmi_disable_clk(x)	__gpmi_enable_clk(x, false)
+
+static int gpmi_runtime_suspend(struct device *dev)
 {
 	struct gpmi_nand_data *this = dev_get_drvdata(dev);
 
-	return __gpmi_enable_clk(this, false);
+	gpmi_disable_clk(this);
+	release_dma_channels(this);
+
+	return 0;
 }
 
-static int __maybe_unused gpmi_runtime_resume(struct device *dev)
+static int gpmi_runtime_resume(struct device *dev)
 {
 	struct gpmi_nand_data *this = dev_get_drvdata(dev);
+	int ret;
 
-	return __gpmi_enable_clk(this, true);
+	ret = gpmi_enable_clk(this);
+	if (ret)

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_pm_resume(struct device *dev) · line 2779

Quoted 10 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +7 -0
+		return ret;
+
+	ret = acquire_dma_channels(this);
+	if (ret < 0)
+		return ret;
+
+	return 0;
 }
 
 static const struct dev_pm_ops gpmi_pm_ops = {

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#6 lore raw
Quoted 38 lines · Esben Haabendal

Hi Han

See comments/questions below.

If I understand the purpose of some of your changes correct, you are fixing the handling of pm usage counter, as it currently is incremented in gpmi_init() and decremented in gpmi_nand_remove(). I believe that would be nice to have in a separate patch with an explanation of the change.

Quoted 25 lines · Han Xu

fix several issues when system suspend/resume,

- leverage the runtime pm for system suspend/resume
- enable the clock before register access
- re-apply timing settings
- set the proper pinctrl state

---
 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 59 ++++++++++++++++------
 1 file changed, 44 insertions(+), 15 deletions(-)
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +1 -0
index 334fe3130285..37437d47ab9a 100644
@@ -15,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/dma/mxs-dma.h>
 #include "gpmi-nand.h"
 #include "gpmi-regs.h"
@@ -146,7 +147,11 @@ static int __gpmi_enable_clk(struct gpmi_nand_data *this, bool v)
Quoted 8 lines

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int __gpmi_enable_clk(struct gpmi_nand_data *this, bool v) · line 150

Quoted 5 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +1 -1
 static int gpmi_init(struct gpmi_nand_data *this)
 {
      struct resources *r = &this->resources;
-     int ret;
+     int ret = 0;

I don't see why this is changed, given that ret is unconditionally assigned in the next line.

removed.

Quoted 12 lines
Quoted 12 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +4 -0
+
+     ret = pm_runtime_get_sync(this->dev);
+     if (ret < 0)
+             return ret;
 
      ret = gpmi_reset_block(r->gpmi_regs, false);
      if (ret)
@@ -179,8 +184,10 @@ static int gpmi_init(struct gpmi_nand_data *this)
       */
      writel(BM_GPMI_CTRL1_DECOUPLE_CS, r->gpmi_regs + HW_GPMI_CTRL1_SET);
 
Quoted 3 lines

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_init(struct gpmi_nand_data *this) · line 182

Quoted 1 line
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +0 -1
-     return 0;

Please provide an explanation of the reasoning of this change is.

I prefer to pair all runtime ops in same function, get_sync before register access and put after that, in all cases.

Quoted 8 lines
Quoted 8 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +3 -0
 err_out:
+     pm_runtime_mark_last_busy(this->dev);
+     pm_runtime_put_autosuspend(this->dev);
+
      return ret;
 }
 
Quoted 8 lines

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int common_nfc_set_geometry(struct gpmi_nand_data *this) · line 538

Quoted 6 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +1 -1
@@ -528,7 +535,7 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this)
 static int bch_set_geometry(struct gpmi_nand_data *this)
 {
      struct resources *r = &this->resources;
-     int ret;
+     int ret = 0;

I don't see any reason for this change.

removed

Quoted 12 lines

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_nand_probe(struct platform_device *pdev) · line 2679

Quoted 8 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +0 -1
      ret = common_nfc_set_geometry(this);
      if (ret)
@@ -2676,7 +2682,7 @@ static int gpmi_nand_probe(struct platform_device *pdev)
      return 0;
 
 exit_nfc_init:
-     pm_runtime_put(&pdev->dev);

I guess this is because of the change above that causes usage counter not to be incremented in gpmi_init() when it is successful.

Quoted 3 lines

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_nand_probe(struct platform_device *pdev) · line 2685

Quoted 1 line
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +1 -0
+     pm_runtime_dont_use_autosuspend(&pdev->dev);

Is this required before pm_runtime_disable()?

If probe function failed before runtime timeout, for instance, the NAND chip not mounted, the runtime suspend won't be called without this change.

Quoted 96 lines

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_nand_remove(struct platform_device *pdev) · line 2691

Quoted 9 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +0 -1
      pm_runtime_disable(&pdev->dev);
      release_resources(this);
 exit_acquire_resources:
@@ -2688,7 +2694,6 @@ static int gpmi_nand_remove(struct platform_device *pdev)
 {
      struct gpmi_nand_data *this = platform_get_drvdata(pdev);
 
-     pm_runtime_put_sync(&pdev->dev);

Should be covered by explanation of the change in gpmi_init().

Quoted 70 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +26 -9
      pm_runtime_disable(&pdev->dev);
 
      nand_release(&this->nand);
@@ -2700,10 +2705,12 @@ static int gpmi_nand_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int gpmi_pm_suspend(struct device *dev)
 {
-     struct gpmi_nand_data *this = dev_get_drvdata(dev);
+     int ret;
 
-     release_dma_channels(this);
-     return 0;
+     pinctrl_pm_select_sleep_state(dev);
+     ret = pm_runtime_force_suspend(dev);
+
+     return ret;
 }
 
 static int gpmi_pm_resume(struct device *dev)
@@ -2711,9 +2718,13 @@ static int gpmi_pm_resume(struct device *dev)
      struct gpmi_nand_data *this = dev_get_drvdata(dev);
      int ret;
 
-     ret = acquire_dma_channels(this);
-     if (ret < 0)
+     ret = pm_runtime_force_resume(dev);
+     if (ret) {
+             dev_err(this->dev, "Error in resume %d\n", ret);
              return ret;
+     }
+
+     pinctrl_pm_select_default_state(dev);
 
      /* re-init the GPMI registers */
      ret = gpmi_init(this);
@@ -2729,22 +2740,40 @@ static int gpmi_pm_resume(struct device *dev)
              return ret;
      }
 
+     /* re-apply the timing setting */
+     this->hw.must_apply_timings = true;
+
      return 0;
 }
 #endif /* CONFIG_PM_SLEEP */
 
-static int __maybe_unused gpmi_runtime_suspend(struct device *dev)
+#define gpmi_enable_clk(x)   __gpmi_enable_clk(x, true)
+#define gpmi_disable_clk(x)  __gpmi_enable_clk(x, false)
+
+static int gpmi_runtime_suspend(struct device *dev)
 {
      struct gpmi_nand_data *this = dev_get_drvdata(dev);
 
-     return __gpmi_enable_clk(this, false);
+     gpmi_disable_clk(this);
+     release_dma_channels(this);
+
+     return 0;
 }
 
-static int __maybe_unused gpmi_runtime_resume(struct device *dev)
+static int gpmi_runtime_resume(struct device *dev)
 {
      struct gpmi_nand_data *this = dev_get_drvdata(dev);
+     int ret;
 
-     return __gpmi_enable_clk(this, true);
+     ret = gpmi_enable_clk(this);
+     if (ret)

drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c static int gpmi_pm_resume(struct device *dev) · line 2779

Quoted 10 lines
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +7 -0
+             return ret;
+
+     ret = acquire_dma_channels(this);
+     if (ret < 0)
+             return ret;
+
+     return 0;
 }
 
 static const struct dev_pm_ops gpmi_pm_ops = {

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Signature · 7 lines
Sincerely,

Han XU

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/