aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/atmel_nand.c
diff options
context:
space:
mode:
authorBo Shen <voice.shen@atmel.com>2014-06-12 03:58:45 -0400
committerBrian Norris <computersforpeace@gmail.com>2014-07-21 22:39:55 -0400
commitb38576667cdcf7a646843b07666faae11cc63e9c (patch)
treeb07fec491086eaacb1cbb874328482e592396ce2 /drivers/mtd/nand/atmel_nand.c
parent974647ea8a13021a91d558df61d598bcabf73439 (diff)
mtd: atmel_nand: make ecc parameters same as definition
If the ecc parameter is not the same as definition, when the mtd core check these parameters, it will give the error result. Take the following as an example: Calculate how many bits can be corrected in one page. According to the ecc parameters definition, one page correct bits = (mtd->writesize * ecc->strength) / ecc->size take the following use case as an example: mtd->writesize = 2048 bytes ecc->strength = 4 bytes (for 512 bytes) before this patch, the ecc->size = 2048, so the result is 4 bytes. after this patch, the ecc->size = 512, so the result is 16 bytes. So, align the ecc parameters the same as definition to correct this kind of error. Signed-off-by: Bo Shen <voice.shen@atmel.com> Acked-by: Josh Wu <josh.wu@atmel.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd/nand/atmel_nand.c')
-rw-r--r--drivers/mtd/nand/atmel_nand.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 4ce181a35bcd..4f5348fd409c 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -861,12 +861,11 @@ static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf,
861{ 861{
862 struct nand_chip *nand_chip = mtd->priv; 862 struct nand_chip *nand_chip = mtd->priv;
863 struct atmel_nand_host *host = nand_chip->priv; 863 struct atmel_nand_host *host = nand_chip->priv;
864 int i, err_nbr, eccbytes; 864 int i, err_nbr;
865 uint8_t *buf_pos; 865 uint8_t *buf_pos;
866 int total_err = 0; 866 int total_err = 0;
867 867
868 eccbytes = nand_chip->ecc.bytes; 868 for (i = 0; i < nand_chip->ecc.total; i++)
869 for (i = 0; i < eccbytes; i++)
870 if (ecc[i] != 0xff) 869 if (ecc[i] != 0xff)
871 goto normal_check; 870 goto normal_check;
872 /* Erased page, return OK */ 871 /* Erased page, return OK */
@@ -928,7 +927,7 @@ static int atmel_nand_pmecc_read_page(struct mtd_info *mtd,
928 struct nand_chip *chip, uint8_t *buf, int oob_required, int page) 927 struct nand_chip *chip, uint8_t *buf, int oob_required, int page)
929{ 928{
930 struct atmel_nand_host *host = chip->priv; 929 struct atmel_nand_host *host = chip->priv;
931 int eccsize = chip->ecc.size; 930 int eccsize = chip->ecc.size * chip->ecc.steps;
932 uint8_t *oob = chip->oob_poi; 931 uint8_t *oob = chip->oob_poi;
933 uint32_t *eccpos = chip->ecc.layout->eccpos; 932 uint32_t *eccpos = chip->ecc.layout->eccpos;
934 uint32_t stat; 933 uint32_t stat;
@@ -1169,8 +1168,7 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev,
1169 goto err; 1168 goto err;
1170 } 1169 }
1171 1170
1172 /* ECC is calculated for the whole page (1 step) */ 1171 nand_chip->ecc.size = sector_size;
1173 nand_chip->ecc.size = mtd->writesize;
1174 1172
1175 /* set ECC page size and oob layout */ 1173 /* set ECC page size and oob layout */
1176 switch (mtd->writesize) { 1174 switch (mtd->writesize) {
@@ -1185,18 +1183,20 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev,
1185 host->pmecc_index_of = host->pmecc_rom_base + 1183 host->pmecc_index_of = host->pmecc_rom_base +
1186 host->pmecc_lookup_table_offset; 1184 host->pmecc_lookup_table_offset;
1187 1185
1188 nand_chip->ecc.steps = 1; 1186 nand_chip->ecc.steps = host->pmecc_sector_number;
1189 nand_chip->ecc.strength = cap; 1187 nand_chip->ecc.strength = cap;
1190 nand_chip->ecc.bytes = host->pmecc_bytes_per_sector * 1188 nand_chip->ecc.bytes = host->pmecc_bytes_per_sector;
1189 nand_chip->ecc.total = host->pmecc_bytes_per_sector *
1191 host->pmecc_sector_number; 1190 host->pmecc_sector_number;
1192 if (nand_chip->ecc.bytes > mtd->oobsize - 2) { 1191 if (nand_chip->ecc.total > mtd->oobsize - 2) {
1193 dev_err(host->dev, "No room for ECC bytes\n"); 1192 dev_err(host->dev, "No room for ECC bytes\n");
1194 err_no = -EINVAL; 1193 err_no = -EINVAL;
1195 goto err; 1194 goto err;
1196 } 1195 }
1197 pmecc_config_ecc_layout(&atmel_pmecc_oobinfo, 1196 pmecc_config_ecc_layout(&atmel_pmecc_oobinfo,
1198 mtd->oobsize, 1197 mtd->oobsize,
1199 nand_chip->ecc.bytes); 1198 nand_chip->ecc.total);
1199
1200 nand_chip->ecc.layout = &atmel_pmecc_oobinfo; 1200 nand_chip->ecc.layout = &atmel_pmecc_oobinfo;
1201 break; 1201 break;
1202 case 512: 1202 case 512: