aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand
diff options
context:
space:
mode:
authorMaxim Levitsky <maximlevitsky@gmail.com>2010-02-22 13:39:38 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2010-02-26 13:02:07 -0500
commite0b58d0a7005cd4b9c7fa4694a437a2d86719c13 (patch)
tree24eef139ef7ab9d37125f9d508a6cf712155a20e /drivers/mtd/nand
parentb64d39d8b03fea88417d53715ccbebf71d4dcc9f (diff)
mtd: nand: add ->badblockbits for minimum number of set bits in bad block byte
This can be used to protect against bitflips in that field, but now mostly for smartmedia. Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/nand')
-rw-r--r--drivers/mtd/nand/nand_base.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 51dfea1b3ce..ba29a29bd74 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -364,14 +364,18 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
364 bad = cpu_to_le16(chip->read_word(mtd)); 364 bad = cpu_to_le16(chip->read_word(mtd));
365 if (chip->badblockpos & 0x1) 365 if (chip->badblockpos & 0x1)
366 bad >>= 8; 366 bad >>= 8;
367 if ((bad & 0xFF) != 0xff) 367 else
368 res = 1; 368 bad &= 0xFF;
369 } else { 369 } else {
370 chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, page); 370 chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, page);
371 if (chip->read_byte(mtd) != 0xff) 371 bad = chip->read_byte(mtd);
372 res = 1;
373 } 372 }
374 373
374 if (likely(chip->badblockbits == 8))
375 res = bad != 0xFF;
376 else
377 res = hweight8(bad) < chip->badblockbits;
378
375 if (getchip) 379 if (getchip)
376 nand_release_device(mtd); 380 nand_release_device(mtd);
377 381
@@ -2884,6 +2888,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2884 /* Set the bad block position */ 2888 /* Set the bad block position */
2885 chip->badblockpos = mtd->writesize > 512 ? 2889 chip->badblockpos = mtd->writesize > 512 ?
2886 NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS; 2890 NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
2891 chip->badblockbits = 8;
2887 2892
2888 /* Get chip options, preserve non chip based options */ 2893 /* Get chip options, preserve non chip based options */
2889 chip->options &= ~NAND_CHIPOPTIONS_MSK; 2894 chip->options &= ~NAND_CHIPOPTIONS_MSK;