[PATCH v3 1/3] mtd: nand: add a helper to parse the Hynix nand

Huang Shijie b32955 at freescale.com
Fri Jan 3 03:08:36 EST 2014


This patch adds a nand_parse_hynix() to parse the Hynix MLC nand
whose ID length is 6 bytes.

This patch makes preparations for parsing other Hynix nand.

Signed-off-by: Huang Shijie <b32955 at freescale.com>
---
 drivers/mtd/nand/nand_base.c |   89 +++++++++++++++++++++++------------------
 1 files changed, 50 insertions(+), 39 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 4ce8007..d6b7dc3 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3198,6 +3198,55 @@ static int nand_get_bits_per_cell(u8 cellinfo)
 	return bits + 1;
 }
 
+/* Parse for the Hynix MLC nand which has 6-bytes ID */
+static void nand_parse_hynix(struct mtd_info *mtd, struct nand_chip *chip,
+			u8 id_data[8], int *busw)
+{
+	int extid = id_data[3];
+	unsigned int tmp;
+
+	/* Calc pagesize */
+	mtd->writesize = 2048 << (extid & 0x03);
+	extid >>= 2;
+
+	/* Calc oobsize */
+	switch (((extid >> 2) & 0x04) | (extid & 0x03)) {
+	case 0:
+		mtd->oobsize = 128;
+		break;
+	case 1:
+		mtd->oobsize = 224;
+		break;
+	case 2:
+		mtd->oobsize = 448;
+		break;
+	case 3:
+		mtd->oobsize = 64;
+		break;
+	case 4:
+		mtd->oobsize = 32;
+		break;
+	case 5:
+		mtd->oobsize = 16;
+		break;
+	default:
+		mtd->oobsize = 640;
+		break;
+	}
+	extid >>= 2;
+
+	/* Calc blocksize */
+	tmp = ((extid >> 1) & 0x04) | (extid & 0x03);
+	if (tmp < 0x03)
+		mtd->erasesize = (128 * 1024) << tmp;
+	else if (tmp == 0x03)
+		mtd->erasesize = 768 * 1024;
+	else
+		mtd->erasesize = (64 * 1024) << tmp;
+
+	*busw = 0;
+}
+
 /*
  * Many new NAND share similar device ID codes, which represent the size of the
  * chip. The rest of the parameters must be decoded according to generic or
@@ -3259,45 +3308,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
 		*busw = 0;
 	} else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX &&
 			!nand_is_slc(chip)) {
-		unsigned int tmp;
-
-		/* Calc pagesize */
-		mtd->writesize = 2048 << (extid & 0x03);
-		extid >>= 2;
-		/* Calc oobsize */
-		switch (((extid >> 2) & 0x04) | (extid & 0x03)) {
-		case 0:
-			mtd->oobsize = 128;
-			break;
-		case 1:
-			mtd->oobsize = 224;
-			break;
-		case 2:
-			mtd->oobsize = 448;
-			break;
-		case 3:
-			mtd->oobsize = 64;
-			break;
-		case 4:
-			mtd->oobsize = 32;
-			break;
-		case 5:
-			mtd->oobsize = 16;
-			break;
-		default:
-			mtd->oobsize = 640;
-			break;
-		}
-		extid >>= 2;
-		/* Calc blocksize */
-		tmp = ((extid >> 1) & 0x04) | (extid & 0x03);
-		if (tmp < 0x03)
-			mtd->erasesize = (128 * 1024) << tmp;
-		else if (tmp == 0x03)
-			mtd->erasesize = 768 * 1024;
-		else
-			mtd->erasesize = (64 * 1024) << tmp;
-		*busw = 0;
+		nand_parse_hynix(mtd, chip, id_data, busw);
 	} else {
 		/* Calc pagesize */
 		mtd->writesize = 1024 << (extid & 0x03);
-- 
1.7.2.rc3





More information about the linux-mtd mailing list