Re: [PATCH 0/5] mtd: rawnand: davinci: Convert to exec_op()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 4 May 2020 18:34:55 +0200
Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx> wrote:

> pt., 1 maj 2020 o 12:07 Boris Brezillon
> <boris.brezillon@xxxxxxxxxxxxx> napisał(a):
> >
> > Hello,
> >
> > A bit of context to explain the motivation behind those conversions
> > I've been sending for the last couple of weeks. The raw NAND subsystem
> > carries a lot of history which makes any rework not only painful, but
> > also subject to regressions which we only detect when someone dares to
> > update its kernel on one of those ancient HW. While carrying drivers
> > for old HW is not a problem per se, carrying ancient and unmaintained
> > drivers that are not converted to new APIs is a maintenance burden,
> > hence this massive conversion attempt I'm conducting here.
> >
> > So here is a series converting the Davinci NAND controller driver to
> > exec_op(), plus a bunch of minor improvements done along the way.
> >
> > Regards,
> >
> > Boris
> >
> > Boris Brezillon (5):
> >   mtd: rawnand: davinci: Inherit from nand_controller
> >   mtd: rawnand: davinci: Stop using nand_chip.legacy.IO_ADDR_{R,W}
> >   mtd: rawnand: davinci: Implement exec_op()
> >   mtd: rawnand: davinci: Get rid of the legacy interface implementation
> >   mtd: rawnand: davinci: Change the {read,write}_buf prototypes
> >
> >  drivers/mtd/nand/raw/davinci_nand.c | 161 +++++++++++++++-------------
> >  1 file changed, 85 insertions(+), 76 deletions(-)
> >
> > --
> > 2.25.3
> >  
> 
> Hi Boris,
> 
> Thanks for doing this. Unfortunately this breaks NAND on da850-lcdk
> with the following error message:
> 
>     nand: No NAND device found

I had a second look and the below diff should fix the detection (you
can also find those changes in my exec-op-conversion branch [1]).

[1]https://github.com/bbrezillon/linux/tree/nand/exec-op-conversion

--->8---
diff --git a/drivers/mtd/nand/raw/davinci_nand.c b/drivers/mtd/nand/raw/davinci_nand.c
index 296047884c6a..0eeb30c7fc4e 100644
--- a/drivers/mtd/nand/raw/davinci_nand.c
+++ b/drivers/mtd/nand/raw/davinci_nand.c
@@ -678,6 +678,33 @@ static int davinci_nand_attach_chip(struct nand_chip *chip)
        return ret;
 }
 
+static void nand_davinci_data_in(struct davinci_nand_info *info, void *buf,
+                                unsigned int len, bool force_8bit)
+{
+       u32 alignment = ((uintptr_t)buf | len) & 3;
+
+       if (force_8bit || (alignment & 1))
+               ioread8_rep(info->current_cs, buf, len);
+       else if (alignment & 3)
+               ioread16_rep(info->current_cs, buf, len >> 1);
+       else
+               ioread32_rep(info->current_cs, buf, len >> 2);
+}
+
+static void nand_davinci_data_out(struct davinci_nand_info *info,
+                                 const void *buf, unsigned int len,
+                                 bool force_8bit)
+{
+       u32 alignment = ((uintptr_t)buf | len) & 3;
+
+       if (force_8bit || (alignment & 1))
+               iowrite8_rep(info->current_cs, buf, len);
+       else if (alignment & 3)
+               iowrite16_rep(info->current_cs, buf, len >> 1);
+       else
+               iowrite32_rep(info->current_cs, buf, len >> 2);
+}
+
 static int davinci_nand_exec_instr(struct davinci_nand_info *info,
                                   const struct nand_op_instr *instr)
 {
@@ -699,13 +726,15 @@ static int davinci_nand_exec_instr(struct davinci_nand_info *info,
                break;
 
        case NAND_OP_DATA_IN_INSTR:
-               nand_davinci_read_buf(&info->chip, instr->ctx.data.buf.in,
-                                     instr->ctx.data.len);
+               nand_davinci_data_in(info, instr->ctx.data.buf.in,
+                                    instr->ctx.data.len,
+                                    instr->ctx.data.force_8bit);
                break;
 
        case NAND_OP_DATA_OUT_INSTR:
-               nand_davinci_write_buf(&info->chip, instr->ctx.data.buf.out,
-                                      instr->ctx.data.len);
+               nand_davinci_data_out(info, instr->ctx.data.buf.out,
+                                     instr->ctx.data.len,
+                                     instr->ctx.data.force_8bit);
                break;
 
        case NAND_OP_WAITRDY_INSTR:
@@ -731,20 +760,21 @@ static int davinci_nand_exec_op(struct nand_chip *chip,
 {
        struct davinci_nand_info *info = to_davinci_nand(nand_to_mtd(chip));
        unsigned int i;
-       int ret;
 
        if (check_only)
-               return true;
+               return 0;
 
        info->current_cs = info->vaddr + (op->cs * info->mask_chipsel);
 
        for (i = 0; i < op->ninstrs; i++) {
+               int ret;
+
                ret = davinci_nand_exec_instr(info, &op->instrs[i]);
                if (ret)
-                       break;
+                       return ret;
        }
 
-       return ret;
+       return 0;
 }
 
 static const struct nand_controller_ops davinci_nand_controller_ops = {


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




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux