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

From: Boris Brezillon
Date: Sun Jun 19 2016 - 08:56:27 EST


On Sun, 19 Jun 2016 20:41:09 +0800
icenowy@xxxxxxxx wrote:

> To be honest, I copied them from sunxi-mmc.c.
>
> What function should be chosen better?

You did the right thing (except for the error detection part). My
question was addressed to Philipp (the reset subsystem maintainer).

>
>
> 19.06.2016, 20:06, "Boris Brezillon" <boris.brezillon@xxxxxxxxxxxxxxxxxx>:
> > +Philipp
> >
> > On Sun, 19 Jun 2016 19:37:39 +0800
> > Icenowy Zheng <icenowy@xxxxxxxx> wrote:
> >
> >> ÂThe NAND controller on some sun8i chips needs its reset line to be deasserted
> >> Âbefore they can enter working state. This commit added the reset line process
> >> Âto the driver.
> >>
> >> ÂSigned-off-by: Icenowy Zheng <icenowy@xxxxxxxx>
> >> Â---
> >> ÂÂdrivers/mtd/nand/sunxi_nand.c | 14 ++++++++++++++
> >> ÂÂ1 file changed, 14 insertions(+)
> >>
> >> Âdiff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
> >> Âindex a83a690..1502748 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,6 +1873,18 @@ 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 (PTR_ERR(nfc->reset) == -EPROBE_DEFER)
> >> Â+ return PTR_ERR(nfc->reset);
> >
> > Actually you should test for != -ENOENT, because all error codes except
> > this one should stop the ->probe().
> >
> > BTW, this devm_reset_control_get_optional() is really weird. While most
> > _optional() methods return NULL when the element is not defined in the
> > DT, this one returns -ENOTENT, which makes it impossible to
> > differentiate a real error from a undefined reset line (which is a
> > valid case for _optional()).
> >
> > Philipp, is there a good reason for doing that?
> >
> >> Â+
> >> Â+ 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;
> >> Â+ }
> >> Â+ }
> >> Â+