From patchwork Wed Feb 17 21:49:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 45682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CA513B7D05 for ; Thu, 18 Feb 2010 08:52:48 +1100 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1Nhrmd-0006Ah-HU; Wed, 17 Feb 2010 21:50:11 +0000 Received: from mail-fx0-f209.google.com ([209.85.220.209]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NhrmO-0005Os-Tm for linux-mtd@lists.infradead.org; Wed, 17 Feb 2010 21:50:06 +0000 Received: by mail-fx0-f209.google.com with SMTP id 1so8377421fxm.4 for ; Wed, 17 Feb 2010 13:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=4sGM4UrBxOgJSUoGScBPBUzz7Rb5xnPNcvfzAb+UiRk=; b=u/gyUhi80m2a+BO3LIvz8t9NWEGIXw4YQBvX3rnqH2qySvZVkb4d+MBfvYyPXWtMmY RnOCglOLvUJ9Wv1QCXI5i4drc+QcmkhFDH8odUr6xb9VAlMPAlOxVjm5YfT6PgtoKO6Q THI4H2NGsIdh/xcrXjaqLwB4GSevWGUvYpFG0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=RQc4AdDAf/x9Uusfw3hAY5uFh3axqyclPf1mbdM2yIuqdye22giyb502P6kHxRO8ms U/meM2uHjdkQCSmI04hc0lzZMVb9StpgM4HDNLYsPUcv3GT9inOJYXYLwOi1c18Ot/BI yVTUdwnZCy2xbipSPng8QEKoD/SZ+1Y7OXzBE= Received: by 10.87.11.34 with SMTP id o34mr1327397fgi.26.1266443396397; Wed, 17 Feb 2010 13:49:56 -0800 (PST) Received: from localhost.localdomain ([77.126.218.27]) by mx.google.com with ESMTPS id d4sm3096749fga.8.2010.02.17.13.49.54 (version=SSLv3 cipher=RC4-MD5); Wed, 17 Feb 2010 13:49:56 -0800 (PST) From: Maxim Levitsky To: David Woodhouse Subject: [PATCH 10/14] MTD: nand: add ->badblockbits to specify the minimum number of bits in bad block byte to consider the block good Date: Wed, 17 Feb 2010 23:49:20 +0200 Message-Id: <1266443364-4538-11-git-send-email-maximlevitsky@gmail.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1266443364-4538-1-git-send-email-maximlevitsky@gmail.com> References: <1266443364-4538-1-git-send-email-maximlevitsky@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100217_164957_114126_7D3495FE X-CRM114-Status: GOOD ( 15.74 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- _SUMMARY_ Cc: Maxim Levitsky , Alex Dubov , Artem Bityutskiy , joern , Vitaly Wool , linux-kernel , "stanley.miao" , linux-mtd , Thomas Gleixner X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This can be used to protect against bitflips in that field, but now mostly for smartmedia. Signed-off-by: Maxim Levitsky --- drivers/mtd/nand/nand_base.c | 13 +++++++++---- include/linux/mtd/nand.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index c393df3..88750a6 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -335,14 +335,18 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) bad = cpu_to_le16(chip->read_word(mtd)); if (chip->badblockpos & 0x1) bad >>= 8; - if ((bad & 0xFF) != 0xff) - res = 1; + else + bad &= 0xFF; } else { chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, page); - if (chip->read_byte(mtd) != 0xff) - res = 1; + bad = chip->read_byte(mtd); } + if (likely(chip->badblockbits == 8)) + res = bad != 0xFF; + else + res = hweight8(bad) < chip->badblockbits; + if (getchip) nand_release_device(mtd); @@ -2710,6 +2714,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, /* Set the bad block position */ chip->badblockpos = mtd->writesize > 512 ? NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS; + chip->badblockbits = 8; /* Get chip options, preserve non chip based options */ chip->options &= ~NAND_CHIPOPTIONS_MSK; diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index ccab9df..27d998e 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h @@ -391,6 +391,7 @@ struct nand_chip { int subpagesize; uint8_t cellinfo; int badblockpos; + int badblockbits; flstate_t state;