[PATCH v5 2/2] mtd: nand: sunxi: add reset line support

Subsystems: memory technology devices (mtd), nand flash subsystem, the rest

STALE3733d

3 messages, 2 authors, 2016-06-19 · open the first message on its own page

[PATCH v5 2/2] mtd: nand: sunxi: add reset line support

From: Icenowy Zheng <hidden>
Date: 2016-06-19 16:14:35

The NAND controller on some sun8i chips needs its reset line to be
deasserted before they can enter working state.

Signed-off-by: Icenowy Zheng <redacted>
---
Changes in v2:
  - Corrected the error checking code of reset line.

Changes in v3:
  - Corrected a more serious error brought in the "fix" of v2.

Changes in v4:
  - Removed unneeded code block after "else".

Changes in v5:
  - Added reassertion code in case of initialization error and device
    remove.

 drivers/mtd/nand/sunxi_nand.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index a83a690..3b40186 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -39,6 +39,7 @@
 #include <linux/gpio.h>
 #include <linux/interrupt.h>
 #include <linux/iopoll.h>
+#include <linux/reset.h>
 
 #define NFC_REG_CTL		0x0000
 #define NFC_REG_ST		0x0004
@@ -269,6 +270,7 @@ struct sunxi_nfc {
 	void __iomem *regs;
 	struct clk *ahb_clk;
 	struct clk *mod_clk;
+	struct reset_control *reset;
 	unsigned long assigned_cs;
 	unsigned long clk_rate;
 	struct list_head chips;
@@ -1871,26 +1873,41 @@ static int sunxi_nfc_probe(struct platform_device *pdev)
 	if (ret)
 		goto out_ahb_clk_unprepare;
 
+	nfc->reset = devm_reset_control_get_optional(dev, "ahb");
+
+	if (!IS_ERR(nfc->reset)) {
+		ret = reset_control_deassert(nfc->reset);
+		if (ret) {
+			dev_err(dev, "reset err %d\n", ret);
+			goto out_mod_clk_unprepare;
+		}
+	} else if (PTR_ERR(nfc->reset) != -ENOENT) {
+		return PTR_ERR(nfc->reset);
+	}
+
 	ret = sunxi_nfc_rst(nfc);
 	if (ret)
-		goto out_mod_clk_unprepare;
+		goto out_ahb_reset_reassert;
 
 	writel(0, nfc->regs + NFC_REG_INT);
 	ret = devm_request_irq(dev, irq, sunxi_nfc_interrupt,
 			       0, "sunxi-nand", nfc);
 	if (ret)
-		goto out_mod_clk_unprepare;
+		goto out_ahb_reset_reassert;
 
 	platform_set_drvdata(pdev, nfc);
 
 	ret = sunxi_nand_chips_init(dev, nfc);
 	if (ret) {
 		dev_err(dev, "failed to init nand chips\n");
-		goto out_mod_clk_unprepare;
+		goto out_ahb_reset_reassert;
 	}
 
 	return 0;
 
+out_ahb_reset_reassert:
+	if (!IS_ERR(nfc->reset))
+		reset_control_assert(nfc->reset);
 out_mod_clk_unprepare:
 	clk_disable_unprepare(nfc->mod_clk);
 out_ahb_clk_unprepare:
@@ -1904,6 +1921,10 @@ static int sunxi_nfc_remove(struct platform_device *pdev)
 	struct sunxi_nfc *nfc = platform_get_drvdata(pdev);
 
 	sunxi_nand_chips_cleanup(nfc);
+
+	if (!IS_ERR(nfc->reset))
+		reset_control_assert(nfc->reset);
+
 	clk_disable_unprepare(nfc->mod_clk);
 	clk_disable_unprepare(nfc->ahb_clk);
 
-- 
2.9.0

Re: [PATCH v5 2/2] mtd: nand: sunxi: add reset line support

From: Maxime Ripard <hidden>
Date: 2016-06-19 19:37:21

On Mon, Jun 20, 2016 at 12:14:35AM +0800, Icenowy Zheng wrote:
quoted hunk
The NAND controller on some sun8i chips needs its reset line to be
deasserted before they can enter working state.

Signed-off-by: Icenowy Zheng <redacted>
---
Changes in v2:
  - Corrected the error checking code of reset line.

Changes in v3:
  - Corrected a more serious error brought in the "fix" of v2.

Changes in v4:
  - Removed unneeded code block after "else".

Changes in v5:
  - Added reassertion code in case of initialization error and device
    remove.

 drivers/mtd/nand/sunxi_nand.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index a83a690..3b40186 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -39,6 +39,7 @@
 #include <linux/gpio.h>
 #include <linux/interrupt.h>
 #include <linux/iopoll.h>
+#include <linux/reset.h>
 
 #define NFC_REG_CTL		0x0000
 #define NFC_REG_ST		0x0004
@@ -269,6 +270,7 @@ struct sunxi_nfc {
 	void __iomem *regs;
 	struct clk *ahb_clk;
 	struct clk *mod_clk;
+	struct reset_control *reset;
 	unsigned long assigned_cs;
 	unsigned long clk_rate;
 	struct list_head chips;
@@ -1871,26 +1873,41 @@ static int sunxi_nfc_probe(struct platform_device *pdev)
 	if (ret)
 		goto out_ahb_clk_unprepare;
 
+	nfc->reset = devm_reset_control_get_optional(dev, "ahb");
+
+	if (!IS_ERR(nfc->reset)) {
+		ret = reset_control_deassert(nfc->reset);
+		if (ret) {
+			dev_err(dev, "reset err %d\n", ret);
+			goto out_mod_clk_unprepare;
+		}
+	} else if (PTR_ERR(nfc->reset) != -ENOENT) {
+		return PTR_ERR(nfc->reset);
You're leaking all the resources here. Please use a goto.

Thanks,
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160619/15675bec/attachment-0001.sig>

Re: [PATCH v5 2/2] mtd: nand: sunxi: add reset line support

From: Icenowy Zheng <hidden>
Date: 2016-06-19 22:54:12

You're right. This is a copy-n-paste error from the original sunxi-mmc.c file,
which get all the clocks and resets before using them.

20.06.2016, 03:37, "Maxime Ripard" [off-list ref]:
On Mon, Jun 20, 2016 at 12:14:35AM +0800, Icenowy Zheng wrote:
quoted
?The NAND controller on some sun8i chips needs its reset line to be
?deasserted before they can enter working state.

?Signed-off-by: Icenowy Zheng [off-list ref]
?---
?Changes in v2:
???- Corrected the error checking code of reset line.

?Changes in v3:
???- Corrected a more serious error brought in the "fix" of v2.

?Changes in v4:
???- Removed unneeded code block after "else".

?Changes in v5:
???- Added reassertion code in case of initialization error and device
?????remove.

??drivers/mtd/nand/sunxi_nand.c | 27 ++++++++++++++++++++++++---
??1 file changed, 24 insertions(+), 3 deletions(-)

?diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
?index a83a690..3b40186 100644
?--- a/drivers/mtd/nand/sunxi_nand.c
?+++ b/drivers/mtd/nand/sunxi_nand.c
?@@ -39,6 +39,7 @@
??#include <linux/gpio.h>
??#include <linux/interrupt.h>
??#include <linux/iopoll.h>
?+#include <linux/reset.h>

??#define NFC_REG_CTL 0x0000
??#define NFC_REG_ST 0x0004
?@@ -269,6 +270,7 @@ struct sunxi_nfc {
??????????void __iomem *regs;
??????????struct clk *ahb_clk;
??????????struct clk *mod_clk;
?+ struct reset_control *reset;
??????????unsigned long assigned_cs;
??????????unsigned long clk_rate;
??????????struct list_head chips;
?@@ -1871,26 +1873,41 @@ static int sunxi_nfc_probe(struct platform_device *pdev)
??????????if (ret)
??????????????????goto out_ahb_clk_unprepare;

?+ nfc->reset = devm_reset_control_get_optional(dev, "ahb");
?+
?+ if (!IS_ERR(nfc->reset)) {
?+ ret = reset_control_deassert(nfc->reset);
?+ if (ret) {
?+ dev_err(dev, "reset err %d\n", ret);
?+ goto out_mod_clk_unprepare;
?+ }
?+ } else if (PTR_ERR(nfc->reset) != -ENOENT) {
?+ return PTR_ERR(nfc->reset);
You're leaking all the resources here. Please use a goto.

Thanks,
Maxime

--
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help