From 2be258bb0070353f0963520f979ae81b5bce67e5 Mon Sep 17 00:00:00 2001 From: Abhishek Sahu Date: Thu, 26 Apr 2018 11:40:53 +0530 Subject: [PATCH 1/3] mtd: nand: qcom: use ECC according chip spare bytes for non ONFI The ONFI NAND device specifies the required ECC correction in its param page but for non ONFI device, we don't have such info. The QPIC NAND contoller can use 8 bit ECC if the chip has required number of spare bytes. This patch calculates the minimum required spare bytes for using 8 bit ECC and select the same, if non ONFI device has required number of spare bytes otherwise 4 bit ECC will be used. Change-Id: If7c718f4288eee16857171335897e3209a05fd0b Signed-off-by: Abhishek Sahu --- arch/arm/include/asm/arch-qca-common/qpic_nand.h | 4 +++- drivers/mtd/nand/qpic_nand.c | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/arch-qca-common/qpic_nand.h b/arch/arm/include/asm/arch-qca-common/qpic_nand.h index 41f9fbc368..44fa0ae75b 100644 --- a/arch/arm/include/asm/arch-qca-common/qpic_nand.h +++ b/arch/arm/include/asm/arch-qca-common/qpic_nand.h @@ -211,10 +211,12 @@ #define NAND_CW_SIZE_4_BIT_ECC 528 #define NAND_CW_SIZE_8_BIT_ECC 532 - /* Indicates the data bytes in the user data portion of the code word. */ #define USER_DATA_BYTES_PER_CW 512 +#define NAND_CW_SPARE_SIZE_8_BIT_ECC (NAND_CW_SIZE_8_BIT_ECC - \ + USER_DATA_BYTES_PER_CW) + /* Indicates the number of bytes covered by BCH ECC logic when * a codeword is written to a NAND flash device. * This is also the number of bytes that are part of the image in CW. diff --git a/drivers/mtd/nand/qpic_nand.c b/drivers/mtd/nand/qpic_nand.c index e93eec418f..ab7268d21b 100644 --- a/drivers/mtd/nand/qpic_nand.c +++ b/drivers/mtd/nand/qpic_nand.c @@ -1454,6 +1454,7 @@ static int qpic_nand_get_info(struct mtd_info *mtd, uint32_t flash_id) const struct nand_manufacturers *flash_man; const struct nand_flash_dev *flash_dev; struct qpic_nand_dev *dev = MTD_QPIC_NAND_DEV(mtd); + uint32_t min_oobsize_8bit_ecc; man_id = NAND_ID_MAN(flash_id); dev_id = NAND_ID_DEV(flash_id); @@ -1483,7 +1484,14 @@ static int qpic_nand_get_info(struct mtd_info *mtd, uint32_t flash_id) else qpic_nand_get_info_flash_dev(mtd, flash_dev); - mtd->ecc_strength = 4; + min_oobsize_8bit_ecc = + (mtd->writesize / CHUNK_SIZE) * NAND_CW_SPARE_SIZE_8_BIT_ECC; + + /* + * Calculate the minimum required oobsize for using 8 bit ecc and use + * 8 bit ecc if this chip oobsize equal or more than that. + */ + mtd->ecc_strength = mtd->oobsize >= min_oobsize_8bit_ecc ? 8 : 4; dev->num_blocks = mtd->size; dev->num_blocks /= (dev->block_size); From a7ab5a19c2c34c7e6cba72766e5ff4e10601da03 Mon Sep 17 00:00:00 2001 From: Abhishek Sahu Date: Thu, 26 Apr 2018 11:48:03 +0530 Subject: [PATCH 2/3] mtd: nand: qcom: fix ubi mount error for non ONFI nand devices Following error is coming during UBI mount for non ONFI nand device since mtd->writebufsize is coming as zero ubi0: attaching mtd2 UBI init error 22 The mtd->writebufsize is being assigned currently for ONFI devices only so move this assigment to common place. Change-Id: Idd22800dd65035952c1afd07ba375a28ffcf76ad Signed-off-by: Abhishek Sahu --- drivers/mtd/nand/qpic_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/qpic_nand.c b/drivers/mtd/nand/qpic_nand.c index ab7268d21b..42ebd7babd 100644 --- a/drivers/mtd/nand/qpic_nand.c +++ b/drivers/mtd/nand/qpic_nand.c @@ -612,7 +612,6 @@ qpic_nand_onfi_save_params(struct mtd_info *mtd, dev->page_size = param_page->data_per_pg; mtd->writesize = dev->page_size; - mtd->writebufsize = mtd->writesize; dev->block_size = param_page->pgs_per_blk * (dev->page_size); mtd->erasesize = dev->block_size; dev->num_blocks = param_page->blks_per_LUN; @@ -703,6 +702,7 @@ qpic_nand_save_config(struct mtd_info *mtd) mtd->oobavail = (DATA_BYTES_IN_IMG_PER_CW - USER_DATA_BYTES_PER_CW) * dev->cws_per_page; dev->oob_per_page = mtd->oobavail; + mtd->writebufsize = mtd->writesize; /* BAD_BLOCK_BYTE_NUM = Page Size - (CW_PER_PAGE * Codeword Size) + 1 * Note: Set CW_PER_PAGE to 1 less than the actual number. */ From 8c71e56950c06e0092d4aca92dca6c3a242b2f0e Mon Sep 17 00:00:00 2001 From: Abhishek Sahu Date: Thu, 26 Apr 2018 11:51:15 +0530 Subject: [PATCH 3/3] mtd: nand: qcom: use oobsize from nand id table If nand id table has specified oobsize then use the same. Change-Id: I58b19f8f9989c7332d103b83b6920d5b59b29a13 Signed-off-by: Abhishek Sahu --- drivers/mtd/nand/qpic_nand.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/qpic_nand.c b/drivers/mtd/nand/qpic_nand.c index 42ebd7babd..d9bf928e48 100644 --- a/drivers/mtd/nand/qpic_nand.c +++ b/drivers/mtd/nand/qpic_nand.c @@ -1381,7 +1381,8 @@ static void qpic_nand_get_info_flash_dev(struct mtd_info *mtd, struct qpic_nand_dev *dev = MTD_QPIC_NAND_DEV(mtd); mtd->writesize = dev->page_size = flash_dev->pagesize; mtd->erasesize = dev->block_size = flash_dev->erasesize; - mtd->oobsize = dev->spare_size = (flash_dev->pagesize >> 5); + mtd->oobsize = dev->spare_size = flash_dev->oobsize ? + flash_dev->oobsize : (flash_dev->pagesize >> 5); }