Skip to contentSkip to conversation

mtd: nand: enable 8k byte page nand flash support for sama5d3x-ek

PATCH New Josh Wu 2 participants 8 messages Oct 18, 2013 – Nov 14, 2013

Subsystems (3)
lore
Share & tools
lore

Josh Wu

author
#0 lore raw

cover mtd: nand: enable 8k byte page nand flash support for sama5d3x-ek

This patch set enable support 8192-byte page nand flash in sama5d3x-ek

Josh Wu (5):
MTD: nand: increase the max eccpos size to 448 to support 8k page
nand
mtd: atmel_nand: enable PMECC support for 8k bytes page NAND flash
sama5d3xek: support larger than 4G nand flash
mtd: atmel_nand: don't print bit correction message in driver
mtd: atmel_nand: use dev_xxx instead of printk

 board/atmel/sama5d3xek/sama5d3xek.c |    5 +++--
 drivers/mtd/nand/atmel_nand.c       |   36 +++++++++++++++++++++--------------
 include/mtd/mtd-abi.h               |    3 ++-
 3 files changed, 27 insertions(+), 17 deletions(-)
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 1/5 MTD: nand: increase the max eccpos size to 448 to support 8k page nand

For example, Micron MT29F64G08CBAAAWP has 8192 bytes page with 448 byte oob. It needs 24bit ecc per page.
If 24bit error correction per 1024 bytes need extra 42 bytes in oob. That means we need eccpos array size is 336 byte.

---
 include/mtd/mtd-abi.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/mtd/mtd-abi.h +2 -1
index d51c1ab..f6f7370 100644
@@ -156,13 +156,14 @@ struct nand_oobfree {
 };
 
 #define MTD_MAX_OOBFREE_ENTRIES	8
+#define MTD_MAX_ECCPOS_ENTRIES_LARGE    448
 /*
  * ECC layout control structure. Exported to userspace for
  * diagnosis and to allow creation of raw images
  */
 struct nand_ecclayout {
 	uint32_t eccbytes;
-	uint32_t eccpos[128];
+	uint32_t eccpos[MTD_MAX_ECCPOS_ENTRIES_LARGE];
 	uint32_t oobavail;
 	struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
 };
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 1/5 MTD: nand: increase the max eccpos size to 448 to support 8k page nand

Quoted 21 lines · Josh

For example, Micron MT29F64G08CBAAAWP has 8192 bytes page with 448 byte oob. It needs 24bit ecc per page.
If 24bit error correction per 1024 bytes need extra 42 bytes in oob. That means we need eccpos array size is 336 byte.

---
include/mtd/mtd-abi.h | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
include/mtd/mtd-abi.h +1 -0
index d51c1ab..f6f7370 100644
@@ -156,13 +156,14 @@ struct nand_oobfree {
 };
 
 #define MTD_MAX_OOBFREE_ENTRIES	8
+#define MTD_MAX_ECCPOS_ENTRIES_LARGE    448
 /*

include/mtd/mtd-abi.h struct nand_oobfree { · line 169

Quoted 10 lines
include/mtd/mtd-abi.h +1 -1
  * ECC layout control structure. Exported to userspace for
  * diagnosis and to allow creation of raw images
  */
 struct nand_ecclayout {
 	uint32_t eccbytes;
-	uint32_t eccpos[128];
+	uint32_t eccpos[MTD_MAX_ECCPOS_ENTRIES_LARGE];
 	uint32_t oobavail;
 	struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
 };

See http://patchwork.ozlabs.org/patch/280488/

-Scott

author
#3 lore raw

PATCH 2/5 mtd: atmel_nand: enable PMECC support for 8k bytes page NAND flash

In reply to Josh Wu

increase the delay to 75us to support the 8k bytes page nand flash

---
 drivers/mtd/nand/atmel_nand.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/nand/atmel_nand.c +9 -1
index da83f06..2320afe 100644
@@ -827,6 +827,7 @@ static int atmel_pmecc_nand_init_params(struct nand_chip *nand,
 	switch (mtd->writesize) {
 	case 2048:
 	case 4096:
+	case 8192:
 		host->pmecc_degree = (sector_size == 512) ?
 			PMECC_GF_DIMENSION_13 : PMECC_GF_DIMENSION_14;
 		host->pmecc_cw_len = (1 << host->pmecc_degree) - 1;
@@ -840,6 +841,13 @@ static int atmel_pmecc_nand_init_params(struct nand_chip *nand,
 		nand->ecc.steps = 1;
 		nand->ecc.bytes = host->pmecc_bytes_per_sector *
 				       host->pmecc_sector_number;
+
+		if (nand->ecc.bytes > MTD_MAX_ECCPOS_ENTRIES_LARGE) {
+			dev_err(host->dev, "too large eccpos entries. max support ecc.bytes is %d\n",
+					MTD_MAX_ECCPOS_ENTRIES_LARGE);
+			return -EINVAL;
+		}
+
 		if (nand->ecc.bytes > mtd->oobsize - 2) {
 			printk(KERN_ERR "No room for ECC bytes\n");
 			return -EINVAL;
@@ -1186,7 +1194,7 @@ int atmel_nand_chip_init(int devnum, ulong base_addr)
 #ifdef CONFIG_SYS_NAND_READY_PIN
 	nand->dev_ready = at91_nand_ready;
 #endif
-	nand->chip_delay = 20;
+	nand->chip_delay = 75;
 
 	ret = nand_scan_ident(mtd, CONFIG_SYS_NAND_MAX_CHIPS, NULL);
 	if (ret)
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 2/5 mtd: atmel_nand: enable PMECC support for 8k bytes page NAND flash

drivers/mtd/nand/atmel_nand.c static int atmel_pmecc_nand_init_params(struct nand_chip *nand, · line 849

Quoted 10 lines · Josh
drivers/mtd/nand/atmel_nand.c +6 -0
@@ -840,6 +841,13 @@ static int atmel_pmecc_nand_init_params(struct nand_chip *nand,
 		nand->ecc.steps = 1;
 		nand->ecc.bytes = host->pmecc_bytes_per_sector *
 				       host->pmecc_sector_number;
+
+		if (nand->ecc.bytes > MTD_MAX_ECCPOS_ENTRIES_LARGE) {
+			dev_err(host->dev, "too large eccpos entries. max support ecc.bytes is %d\n",
+					MTD_MAX_ECCPOS_ENTRIES_LARGE);
+			return -EINVAL;
+		}

I won't hold up acceptance over this, but wouldn't it be more useful to show the actual ecc.bytes rather than the constant limit which could be easily looked up in the source? Or better, print both.

-Scott

author
#5 lore raw

PATCH 3/5 sama5d3xek: support larger than 4G nand flash

In reply to Josh Wu
---
 board/atmel/sama5d3xek/sama5d3xek.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
board/atmel/sama5d3xek/sama5d3xek.c +3 -2
index b0965ef..83fd63f 100644
@@ -131,7 +131,8 @@ static void sama5d3xek_lcd_hw_init(void)
 
 void lcd_show_board_info(void)
 {
-	ulong dram_size, nand_size;
+	ulong dram_size;
+	uint64_t nand_size;
 	int i;
 	char temp[32];
 
@@ -150,7 +151,7 @@ void lcd_show_board_info(void)
 	for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
 		nand_size += nand_info[i].size;
 #endif
-	lcd_printf("%ld MB SDRAM, %ld MB NAND\n",
+	lcd_printf("%ld MB SDRAM, %lld MB NAND\n",
 		   dram_size >> 20, nand_size >> 20);
 }
 #endif /* CONFIG_LCD_INFO */
Signature · 1 line
1.7.9.5
author
#6 lore raw

PATCH 4/5 mtd: atmel_nand: don't print bit correction message in driver

In reply to Josh Wu

Since for some MLC nand, bit errors happened too often. Just disable it to avoid noise

---
 drivers/mtd/nand/atmel_nand.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/atmel_nand.c +2 -2
index 2320afe..ca2acaf 100644
@@ -452,7 +452,7 @@ static void pmecc_correct_data(struct mtd_info *mtd, uint8_t *buf, uint8_t *ecc,
 			*(buf + byte_pos) ^= (1 << bit_pos);
 
 			pos = sector_num * host->pmecc_sector_size + byte_pos;
-			printk(KERN_INFO "Bit flip in data area, byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n",
+			dev_dbg(host->dev, "Bit flip in data area, byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n",
 				pos, bit_pos, err_byte, *(buf + byte_pos));
 		} else {
 			/* Bit flip in OOB area */
@@ -462,7 +462,7 @@ static void pmecc_correct_data(struct mtd_info *mtd, uint8_t *buf, uint8_t *ecc,
 			ecc[tmp] ^= (1 << bit_pos);
 
 			pos = tmp + nand_chip->ecc.layout->eccpos[0];
-			printk(KERN_INFO "Bit flip in OOB, oob_byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n",
+			dev_dbg(host->dev, "Bit flip in OOB, oob_byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n",
 				pos, bit_pos, err_byte, ecc[tmp]);
 		}
 
Signature · 1 line
1.7.9.5
author
#7 lore raw

PATCH 5/5 mtd: atmel_nand: use dev_xxx instead of printk

In reply to Josh Wu
---
 drivers/mtd/nand/atmel_nand.c |   22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/mtd/nand/atmel_nand.c +11 -11
index ca2acaf..acfbb78 100644
@@ -412,7 +412,7 @@ static int pmecc_err_location(struct mtd_info *mtd)
 	}
 
 	if (!timeout) {
-		printk(KERN_ERR "atmel_nand : Timeout to calculate PMECC error location\n");
+		dev_err(host->dev, "atmel_nand : Timeout to calculate PMECC error location\n");
 		return -1;
 	}
 
@@ -500,7 +500,7 @@ normal_check:
 
 			err_nbr = pmecc_err_location(mtd);
 			if (err_nbr == -1) {
-				printk(KERN_ERR "PMECC: Too many errors\n");
+				dev_err(host->dev, "PMECC: Too many errors\n");
 				mtd->ecc_stats.failed++;
 				return -EIO;
 			} else {
@@ -544,7 +544,7 @@ static int atmel_nand_pmecc_read_page(struct mtd_info *mtd,
 	}
 
 	if (!timeout) {
-		printk(KERN_ERR "atmel_nand : Timeout to read PMECC page\n");
+		dev_err(host->dev, "atmel_nand : Timeout to read PMECC page\n");
 		return -1;
 	}
 
@@ -584,7 +584,7 @@ static int atmel_nand_pmecc_write_page(struct mtd_info *mtd,
 	}
 
 	if (!timeout) {
-		printk(KERN_ERR "atmel_nand : Timeout to read PMECC status, fail to write PMECC in oob\n");
+		dev_err(host->dev, "atmel_nand : Timeout to read PMECC status, fail to write PMECC in oob\n");
 		goto out;
 	}
 
@@ -849,7 +849,7 @@ static int atmel_pmecc_nand_init_params(struct nand_chip *nand,
 		}
 
 		if (nand->ecc.bytes > mtd->oobsize - 2) {
-			printk(KERN_ERR "No room for ECC bytes\n");
+			dev_err(host->dev, "No room for ECC bytes\n");
 			return -EINVAL;
 		}
 		pmecc_config_ecc_layout(&atmel_pmecc_oobinfo,
@@ -860,7 +860,7 @@ static int atmel_pmecc_nand_init_params(struct nand_chip *nand,
 	case 512:
 	case 1024:
 		/* TODO */
-		printk(KERN_ERR "Unsupported page size for PMECC, use Software ECC\n");
+		dev_err(host->dev, "Unsupported page size for PMECC, use Software ECC\n");
 	default:
 		/* page size not handled by HW ECC */
 		/* switching back to soft ECC */
@@ -1043,7 +1043,7 @@ static int atmel_nand_correct(struct mtd_info *mtd, u_char *dat,
 		/* it doesn't seems to be a freshly
 		 * erased block.
 		 * We can't correct so many errors */
-		printk(KERN_WARNING "atmel_nand : multiple errors detected."
+		dev_warn(host->dev, "atmel_nand : multiple errors detected."
 				" Unable to correct.\n");
 		return -EIO;
 	}
@@ -1053,12 +1053,12 @@ static int atmel_nand_correct(struct mtd_info *mtd, u_char *dat,
 		/* there's nothing much to do here.
 		 * the bit error is on the ECC itself.
 		 */
-		printk(KERN_WARNING "atmel_nand : one bit error on ECC code."
+		dev_warn(host->dev, "atmel_nand : one bit error on ECC code."
 				" Nothing to correct\n");
 		return 0;
 	}
 
-	printk(KERN_WARNING "atmel_nand : one bit error on data."
+	dev_warn(host->dev, "atmel_nand : one bit error on data."
 			" (word offset in the page :"
 			" 0x%x bit offset : 0x%x)\n",
 			ecc_word, ecc_bit);
@@ -1070,7 +1070,7 @@ static int atmel_nand_correct(struct mtd_info *mtd, u_char *dat,
 		/* 8 bits words */
 		dat[ecc_word] ^= (1 << ecc_bit);
 	}
-	printk(KERN_WARNING "atmel_nand : error corrected\n");
+	dev_warn(host->dev, "atmel_nand : error corrected\n");
 	return 1;
 }
 
@@ -1222,6 +1222,6 @@ void board_nand_init(void)
 	int i;
 	for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
 		if (atmel_nand_chip_init(i, base_addr[i]))
-			printk(KERN_ERR "atmel_nand: Fail to initialize #%d chip",
+			dev_err(host->dev, "atmel_nand: Fail to initialize #%d chip",
 				i);
 }
Signature · 1 line
1.7.9.5