]> Pileus Git - ~andy/linux/blobdiff - drivers/mtd/nand/nand_base.c
[MTD] NAND: nand_write_ecc memory and OOB corruption
[~andy/linux] / drivers / mtd / nand / nand_base.c
index eee5115658c8c37bc3bf91136f48494e4221cb16..c18ea76ed408b712d2e818af8ae7d67e79f9dd2d 100644 (file)
@@ -46,6 +46,8 @@
  *             perform extra error status checks on erase and write failures.  This required
  *             adding a wrapper function for nand_read_ecc.
  *
+ * 08-20-2005  vwool: suspend/resume added
+ *
  * Credits:
  *     David Woodhouse for adding multichip support  
  *     
@@ -59,7 +61,7 @@
  *     The AG-AND chips have nice features for speed improvement,
  *     which are not supported yet. Read / program 4 pages in one go.
  *
- * $Id: nand_base.c,v 1.147 2005/07/15 07:18:06 gleixner Exp $
+ * $Id: nand_base.c,v 1.150 2005/09/15 13:58:48 vwool Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -153,7 +155,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int
 #define nand_verify_pages(...) (0)
 #endif
                
-static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state);
+static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state);
 
 /**
  * nand_release_device - [GENERIC] release chip
@@ -431,7 +433,7 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
                this->cmdfunc (mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, page & this->pagemask);
                bad = cpu_to_le16(this->read_word(mtd));
                if (this->badblockpos & 0x1)
-                       bad >>= 1;
+                       bad >>= 8;
                if ((bad & 0xFF) != 0xff)
                        res = 1;
        } else {
@@ -526,6 +528,7 @@ static void nand_wait_ready(struct mtd_info *mtd)
        do {
                if (this->dev_ready(mtd))
                        return;
+               touch_softlockup_watchdog();
        } while (time_before(jiffies, timeo));  
 }
 
@@ -755,7 +758,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column,
  *
  * Get the device and lock it for exclusive access
  */
-static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state)
+static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state)
 {
        struct nand_chip *active;
        spinlock_t *lock;
@@ -778,7 +781,11 @@ retry:
        if (active == this && this->state == FL_READY) {
                this->state = new_state;
                spin_unlock(lock);
-               return;
+               return 0;
+       }
+       if (new_state == FL_PM_SUSPENDED) {
+               spin_unlock(lock);
+               return (this->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN;
        }
        set_current_state(TASK_UNINTERRUPTIBLE);
        add_wait_queue(wq, &wait);
@@ -1715,6 +1722,7 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
                        startpage = page;
                        oobbuf = nand_prepare_oobbuf (mtd, eccbuf, oobsel, 
                                        autoplace, numpages);
+                       oob = 0;
                        /* Check, if we cross a chip boundary */
                        if (!page) {
                                chipnr++;
@@ -2283,6 +2291,34 @@ static int nand_block_markbad (struct mtd_info *mtd, loff_t ofs)
        return this->block_markbad(mtd, ofs);
 }
 
+/**
+ * nand_suspend - [MTD Interface] Suspend the NAND flash
+ * @mtd:       MTD device structure
+ */
+static int nand_suspend(struct mtd_info *mtd)
+{
+       struct nand_chip *this = mtd->priv;
+
+       return nand_get_device (this, mtd, FL_PM_SUSPENDED);
+}
+
+/**
+ * nand_resume - [MTD Interface] Resume the NAND flash
+ * @mtd:       MTD device structure
+ */
+static void nand_resume(struct mtd_info *mtd)
+{
+       struct nand_chip *this = mtd->priv;
+
+       if (this->state == FL_PM_SUSPENDED)
+               nand_release_device(mtd);
+       else
+               printk(KERN_ERR "resume() called for the chip which is not "
+                               "in suspended state\n");
+
+}
+
+
 /**
  * nand_scan - [NAND Interface] Scan for the NAND device
  * @mtd:       MTD device structure
@@ -2368,7 +2404,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
                        mtd->oobblock = 1024 << (extid & 0x3);
                        extid >>= 2;
                        /* Calc oobsize */
-                       mtd->oobsize = (8 << (extid & 0x03)) * (mtd->oobblock / 512);
+                       mtd->oobsize = (8 << (extid & 0x01)) * (mtd->oobblock >> 9);
                        extid >>= 2;
                        /* Calc blocksize. Blocksize is multiples of 64KiB */
                        mtd->erasesize = (64 * 1024)  << (extid & 0x03);
@@ -2642,8 +2678,8 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
        mtd->sync = nand_sync;
        mtd->lock = NULL;
        mtd->unlock = NULL;
-       mtd->suspend = NULL;
-       mtd->resume = NULL;
+       mtd->suspend = nand_suspend;
+       mtd->resume = nand_resume;
        mtd->block_isbad = nand_block_isbad;
        mtd->block_markbad = nand_block_markbad;