Commit 2c9f2365 authored by Pekon Gupta's avatar Pekon Gupta Committed by Brian Norris

mtd: nand: omap: ecc.calculate: merge omap3_calculate_ecc_bch4 in omap_calculate_ecc_bch

merges omap3_calculate_ecc_bch4() into omap_calculate_ecc_bch() so that
common callback can be used for both OMAP_ECC_BCH4_CODE_HW and
OMAP_ECC_BCH4_CODE_HW_DETECTION_SW ecc-schemes

+---------------------+-------------------------------------------------------+
|ecc-scheme           | nand_chip->calculate() after this patch               |
+---------------------+-------------------------------------------------------+
|HAM1_ECC             | omap_calculate_ecc()                                  |
+---------------------+-------------------------------------------------------+
|BCH4_HW_DETECTION_SW | omap3_calculate_ecc_bch4() -> omap_calculate_ecc_bch()|
|BCH4_HW              | omap_calculate_ecc_bch()                              |
|BCH8_HW_DETECTION_SW | omap3_calculate_ecc_bch8()                            |
|BCH8_HW              | omap_calculate_ecc_bch()                              |
+---------------------+-------------------------------------------------------+
Tested-by: default avatarStefan Roese <sr@denx.de>
Signed-off-by: default avatarPekon Gupta <pekon@ti.com>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent f5dc06fb
...@@ -1121,47 +1121,9 @@ static void omap3_enable_hwecc_bch(struct mtd_info *mtd, int mode) ...@@ -1121,47 +1121,9 @@ static void omap3_enable_hwecc_bch(struct mtd_info *mtd, int mode)
writel(ECCCLEAR | ECC1, info->reg.gpmc_ecc_control); writel(ECCCLEAR | ECC1, info->reg.gpmc_ecc_control);
} }
#endif #endif
static u8 bch4_polynomial[] = {0x28, 0x13, 0xcc, 0x39, 0x96, 0xac, 0x7f};
#ifdef CONFIG_MTD_NAND_ECC_BCH #ifdef CONFIG_MTD_NAND_ECC_BCH
/**
* omap3_calculate_ecc_bch4 - Generate 7 bytes of ECC bytes
* @mtd: MTD device structure
* @dat: The pointer to data on which ecc is computed
* @ecc_code: The ecc_code buffer
*/
static int omap3_calculate_ecc_bch4(struct mtd_info *mtd, const u_char *dat,
u_char *ecc_code)
{
struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
mtd);
unsigned long nsectors, val1, val2;
int i;
nsectors = ((readl(info->reg.gpmc_ecc_config) >> 4) & 0x7) + 1;
for (i = 0; i < nsectors; i++) {
/* Read hw-computed remainder */
val1 = readl(info->reg.gpmc_bch_result0[i]);
val2 = readl(info->reg.gpmc_bch_result1[i]);
/*
* Add constant polynomial to remainder, in order to get an ecc
* sequence of 0xFFs for a buffer filled with 0xFFs; and
* left-justify the resulting polynomial.
*/
*ecc_code++ = 0x28 ^ ((val2 >> 12) & 0xFF);
*ecc_code++ = 0x13 ^ ((val2 >> 4) & 0xFF);
*ecc_code++ = 0xcc ^ (((val2 & 0xF) << 4)|((val1 >> 28) & 0xF));
*ecc_code++ = 0x39 ^ ((val1 >> 20) & 0xFF);
*ecc_code++ = 0x96 ^ ((val1 >> 12) & 0xFF);
*ecc_code++ = 0xac ^ ((val1 >> 4) & 0xFF);
*ecc_code++ = 0x7f ^ ((val1 & 0xF) << 4);
}
return 0;
}
/** /**
* omap3_calculate_ecc_bch8 - Generate 13 bytes of ECC bytes * omap3_calculate_ecc_bch8 - Generate 13 bytes of ECC bytes
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -1209,7 +1171,6 @@ static int omap3_calculate_ecc_bch8(struct mtd_info *mtd, const u_char *dat, ...@@ -1209,7 +1171,6 @@ static int omap3_calculate_ecc_bch8(struct mtd_info *mtd, const u_char *dat,
} }
#endif /* CONFIG_MTD_NAND_ECC_BCH */ #endif /* CONFIG_MTD_NAND_ECC_BCH */
#ifdef CONFIG_MTD_NAND_OMAP_BCH
/** /**
* omap_calculate_ecc_bch - Generate bytes of ECC bytes * omap_calculate_ecc_bch - Generate bytes of ECC bytes
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -1252,6 +1213,7 @@ static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd, ...@@ -1252,6 +1213,7 @@ static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
*ecc_code++ = ((bch_val1 >> 8) & 0xFF); *ecc_code++ = ((bch_val1 >> 8) & 0xFF);
*ecc_code++ = (bch_val1 & 0xFF); *ecc_code++ = (bch_val1 & 0xFF);
break; break;
case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW:
case OMAP_ECC_BCH4_CODE_HW: case OMAP_ECC_BCH4_CODE_HW:
bch_val1 = readl(gpmc_regs->gpmc_bch_result0[i]); bch_val1 = readl(gpmc_regs->gpmc_bch_result0[i]);
bch_val2 = readl(gpmc_regs->gpmc_bch_result1[i]); bch_val2 = readl(gpmc_regs->gpmc_bch_result1[i]);
...@@ -1270,6 +1232,12 @@ static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd, ...@@ -1270,6 +1232,12 @@ static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
/* ECC scheme specific syndrome customizations */ /* ECC scheme specific syndrome customizations */
switch (info->ecc_opt) { switch (info->ecc_opt) {
case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW:
/* Add constant polynomial to remainder, so that
* ECC of blank pages results in 0x0 on reading back */
for (i = 0; i < eccbytes; i++)
ecc_calc[i] ^= bch4_polynomial[i];
break;
case OMAP_ECC_BCH4_CODE_HW: case OMAP_ECC_BCH4_CODE_HW:
/* Set 8th ECC byte as 0x0 for ROM compatibility */ /* Set 8th ECC byte as 0x0 for ROM compatibility */
ecc_calc[eccbytes - 1] = 0x0; ecc_calc[eccbytes - 1] = 0x0;
...@@ -1327,6 +1295,7 @@ static int erased_sector_bitflips(u_char *data, u_char *oob, ...@@ -1327,6 +1295,7 @@ static int erased_sector_bitflips(u_char *data, u_char *oob,
return flip_bits; return flip_bits;
} }
#ifdef CONFIG_MTD_NAND_OMAP_BCH
/** /**
* omap_elm_correct_data - corrects page data area in case error reported * omap_elm_correct_data - corrects page data area in case error reported
* @mtd: MTD device structure * @mtd: MTD device structure
...@@ -1835,7 +1804,7 @@ static int omap_nand_probe(struct platform_device *pdev) ...@@ -1835,7 +1804,7 @@ static int omap_nand_probe(struct platform_device *pdev)
nand_chip->ecc.strength = 4; nand_chip->ecc.strength = 4;
nand_chip->ecc.hwctl = omap3_enable_hwecc_bch; nand_chip->ecc.hwctl = omap3_enable_hwecc_bch;
nand_chip->ecc.correct = nand_bch_correct_data; nand_chip->ecc.correct = nand_bch_correct_data;
nand_chip->ecc.calculate = omap3_calculate_ecc_bch4; nand_chip->ecc.calculate = omap_calculate_ecc_bch;
/* define ECC layout */ /* define ECC layout */
ecclayout->eccbytes = nand_chip->ecc.bytes * ecclayout->eccbytes = nand_chip->ecc.bytes *
(mtd->writesize / (mtd->writesize /
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment