mtd: nand: Add naieve panic_write support for generic nand devices.
San Mehat [Thu, 20 Aug 2009 17:50:45 +0000 (10:50 -0700)]
Signed-off-by: San Mehat <san@google.com>

mtd: nand_base: fix nand_panic_wait

fix the problem of nand_panic_wait

Change-Id: Iafa9faa60d99b7df429bd01dad5599bbafb3c245
Signed-off-by: Tom Zhu <a2289c@android-hal-04.(none)>
Signed-off-by: San Mehat <san@google.com>
Reviewed-on: http://git-master/r/111035
Reviewed-by: Prashant Malani <pmalani@nvidia.com>
Tested-by: Prashant Malani <pmalani@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Bo Yan <byan@nvidia.com>

drivers/mtd/nand/nand_base.c

index 47b19c0..7dbdf01 100644 (file)
@@ -3219,6 +3219,44 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
 }
 EXPORT_SYMBOL(nand_scan_ident);
 
+static void nand_panic_wait(struct mtd_info *mtd)
+{
+       struct nand_chip *chip = mtd->priv;
+       int i;
+
+       if (chip->state != FL_READY)
+               for (i = 0; i < 40; i++) {
+                       if (chip->dev_ready(mtd))
+                               break;
+                       mdelay(10);
+               }
+       chip->state = FL_READY;
+}
+
+static int nand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
+                           size_t *retlen, const u_char *buf)
+{
+       struct nand_chip *chip = mtd->priv;
+       int ret;
+
+       /* Do not allow reads past end of device */
+       if ((to + len) > mtd->size)
+               return -EINVAL;
+       if (!len)
+               return 0;
+
+       nand_panic_wait(mtd);
+
+       chip->ops.len = len;
+       chip->ops.datbuf = (uint8_t *)buf;
+       chip->ops.oobbuf = NULL;
+
+       ret = nand_do_write_ops(mtd, to, &chip->ops);
+
+       *retlen = chip->ops.retlen;
+       return ret;
+}
+
 
 /**
  * nand_scan_tail - [NAND Interface] Scan for the NAND device
@@ -3464,21 +3502,22 @@ int nand_scan_tail(struct mtd_info *mtd)
        mtd->type = MTD_NANDFLASH;
        mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM :
                                                MTD_CAP_NANDFLASH;
-       mtd->_erase = nand_erase;
-       mtd->_point = NULL;
-       mtd->_unpoint = NULL;
-       mtd->_read = nand_read;
-       mtd->_write = nand_write;
-       mtd->_panic_write = panic_nand_write;
-       mtd->_read_oob = nand_read_oob;
-       mtd->_write_oob = nand_write_oob;
-       mtd->_sync = nand_sync;
-       mtd->_lock = NULL;
-       mtd->_unlock = NULL;
-       mtd->_suspend = nand_suspend;
-       mtd->_resume = nand_resume;
-       mtd->_block_isbad = nand_block_isbad;
-       mtd->_block_markbad = nand_block_markbad;
+       mtd->erase = nand_erase;
+       mtd->point = NULL;
+       mtd->unpoint = NULL;
+       mtd->read = nand_read;
+       mtd->write = nand_write;
+       mtd->panic_write = panic_nand_write;
+       mtd->read_oob = nand_read_oob;
+       mtd->write_oob = nand_write_oob;
+       mtd->panic_write = nand_panic_write;
+       mtd->sync = nand_sync;
+       mtd->lock = NULL;
+       mtd->unlock = NULL;
+       mtd->suspend = nand_suspend;
+       mtd->resume = nand_resume;
+       mtd->block_isbad = nand_block_isbad;
+       mtd->block_markbad = nand_block_markbad;
        mtd->writebufsize = mtd->writesize;
 
        /* propagate ecc info to mtd_info */