mtd: vf610_nfc: allow bitflips in an empty page
[oweals/u-boot.git] / drivers / mtd / nand / nand_base.c
index 7153e3ca3630a2219d09dfca487cc7dcafa00a55..c0e381ad2d155cf74b09df1ff4464012764bf129 100644 (file)
@@ -308,8 +308,7 @@ static void ioread16_rep(void *addr, void *buf, int len)
 {
        int i;
        u16 *p = (u16 *) buf;
-       len >>= 1;
+
        for (i = 0; i < len; i++)
                p[i] = readw(addr);
 }
@@ -318,7 +317,6 @@ static void iowrite16_rep(void *addr, void *buf, int len)
 {
        int i;
         u16 *p = (u16 *) buf;
-        len >>= 1;
 
         for (i = 0; i < len; i++)
                 writew(p[i], addr);
@@ -363,51 +361,6 @@ void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
        ioread8_rep(chip->IO_ADDR_R, buf, len);
 }
 
-#ifdef __UBOOT__
-#if defined(CONFIG_MTD_NAND_VERIFY_WRITE)
-/**
- * nand_verify_buf - [DEFAULT] Verify chip data against buffer
- * @mtd: MTD device structure
- * @buf: buffer containing the data to compare
- * @len: number of bytes to compare
- *
- * Default verify function for 8bit buswidth.
- */
-static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
-{
-       int i;
-       struct nand_chip *chip = mtd->priv;
-
-       for (i = 0; i < len; i++)
-               if (buf[i] != readb(chip->IO_ADDR_R))
-                       return -EFAULT;
-       return 0;
-}
-
-/**
- * nand_verify_buf16 - [DEFAULT] Verify chip data against buffer
- * @mtd: MTD device structure
- * @buf: buffer containing the data to compare
- * @len: number of bytes to compare
- *
- * Default verify function for 16bit buswidth.
- */
-static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
-{
-       int i;
-       struct nand_chip *chip = mtd->priv;
-       u16 *p = (u16 *) buf;
-       len >>= 1;
-
-       for (i = 0; i < len; i++)
-               if (p[i] != readw(chip->IO_ADDR_R))
-                       return -EFAULT;
-
-       return 0;
-}
-#endif
-#endif
-
 /**
  * nand_write_buf16 - [DEFAULT] write buffer to chip
  * @mtd: MTD device structure
@@ -636,6 +589,12 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
 {
        struct nand_chip *chip = mtd->priv;
 
+       if (!(chip->options & NAND_SKIP_BBTSCAN) &&
+           !(chip->options & NAND_BBT_SCANNED)) {
+               chip->options |= NAND_BBT_SCANNED;
+               chip->scan_bbt(mtd);
+       }
+
        if (!chip->bbt)
                return chip->block_bad(mtd, ofs, getchip);
 
@@ -1061,11 +1020,6 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
                }
        }
 #endif
-#ifdef PPCHAMELON_NAND_TIMER_HACK
-       time_start = get_timer(0);
-       while (get_timer(time_start) < 10)
-               ;
-#endif /*  PPCHAMELON_NAND_TIMER_HACK */
        led_trigger_event(nand_led_trigger, LED_OFF);
 
        status = (int)chip->read_byte(mtd);
@@ -2436,20 +2390,6 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
                status = chip->waitfunc(mtd, chip);
        }
 
-
-#ifdef __UBOOT__
-#if defined(CONFIG_MTD_NAND_VERIFY_WRITE)
-       /* Send command to read back the data */
-       chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
-
-       if (chip->verify_buf(mtd, buf, mtd->writesize))
-               return -EIO;
-
-       /* Make sure the next page prog is preceded by a status read */
-       chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
-#endif
-#endif
-
        return 0;
 }
 
@@ -2902,7 +2842,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
                WATCHDOG_RESET();
 
                /* Check if we have a bad block, we do not erase bad blocks! */
-               if (nand_block_checkbad(mtd, ((loff_t) page) <<
+               if (!instr->scrub && nand_block_checkbad(mtd, ((loff_t) page) <<
                                        chip->page_shift, 0, allowbbt)) {
                        pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
                                    __func__, page);
@@ -3140,12 +3080,6 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
                chip->read_buf = busw ? nand_read_buf16 : nand_read_buf;
        if (!chip->scan_bbt)
                chip->scan_bbt = nand_default_bbt;
-#ifdef __UBOOT__
-#if defined(CONFIG_MTD_NAND_VERIFY_WRITE)
-       if (!chip->verify_buf)
-               chip->verify_buf = busw ? nand_verify_buf16 : nand_verify_buf;
-#endif
-#endif
 
        if (!chip->controller) {
                chip->controller = &chip->hwcontrol;
@@ -4322,12 +4256,7 @@ int nand_scan_tail(struct mtd_info *mtd)
        if (!mtd->bitflip_threshold)
                mtd->bitflip_threshold = mtd->ecc_strength;
 
-       /* Check, if we should skip the bad block table scan */
-       if (chip->options & NAND_SKIP_BBTSCAN)
-               return 0;
-
-       /* Build bad block table */
-       return chip->scan_bbt(mtd);
+       return 0;
 }
 EXPORT_SYMBOL(nand_scan_tail);