aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand
diff options
context:
space:
mode:
authorPekon Gupta <pekon@ti.com>2014-02-26 05:23:14 -0500
committerBrian Norris <computersforpeace@gmail.com>2014-03-20 05:30:27 -0400
commit7bcd1dca1d587ad29f9825ba4414620440e8c8da (patch)
tree6ca84dcaea92051ac45fb9f7024ba3f30d9addd1 /drivers/mtd/nand
parent2c9f2365d1e1d0e318b068f683f18c99515b80f8 (diff)
mtd: nand: omap: ecc.calculate: merge omap3_calculate_ecc_bch8 in omap_calculate_ecc_bch
merge omap3_calculate_ecc_bch8() into omap_calculate_ecc_bch() so that common callback can be used for both OMAP_ECC_BCH8_CODE_HW and OMAP_ECC_BCH8_CODE_HW_DETECTION_SW +---------------------+-------------------------------------------------------+ |ecc-scheme | nand_chip->calculate() after this patch | +---------------------+-------------------------------------------------------+ |HAM1_ECC | omap_calculate_ecc() | +---------------------+-------------------------------------------------------+ |BCH4_HW_DETECTION_SW | omap_calculate_ecc_bch() | |BCH4_HW | omap_calculate_ecc_bch() | |BCH8_HW_DETECTION_SW | omap3_calculate_ecc_bch8() -> omap_calculate_ecc_bch()| |BCH8_HW | omap_calculate_ecc_bch() | +---------------------+-------------------------------------------------------+ Tested-by: Stefan Roese <sr@denx.de> Signed-off-by: Pekon Gupta <pekon@ti.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd/nand')
-rw-r--r--drivers/mtd/nand/omap2.c59
1 files changed, 10 insertions, 49 deletions
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index e536267231e2..fa8143624384 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -1122,54 +1122,8 @@ static void omap3_enable_hwecc_bch(struct mtd_info *mtd, int mode)
1122} 1122}
1123#endif 1123#endif
1124static u8 bch4_polynomial[] = {0x28, 0x13, 0xcc, 0x39, 0x96, 0xac, 0x7f}; 1124static u8 bch4_polynomial[] = {0x28, 0x13, 0xcc, 0x39, 0x96, 0xac, 0x7f};
1125 1125static u8 bch8_polynomial[] = {0xef, 0x51, 0x2e, 0x09, 0xed, 0x93, 0x9a, 0xc2,
1126#ifdef CONFIG_MTD_NAND_ECC_BCH 1126 0x97, 0x79, 0xe5, 0x24, 0xb5};
1127/**
1128 * omap3_calculate_ecc_bch8 - Generate 13 bytes of ECC bytes
1129 * @mtd: MTD device structure
1130 * @dat: The pointer to data on which ecc is computed
1131 * @ecc_code: The ecc_code buffer
1132 */
1133static int omap3_calculate_ecc_bch8(struct mtd_info *mtd, const u_char *dat,
1134 u_char *ecc_code)
1135{
1136 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1137 mtd);
1138 unsigned long nsectors, val1, val2, val3, val4;
1139 int i;
1140
1141 nsectors = ((readl(info->reg.gpmc_ecc_config) >> 4) & 0x7) + 1;
1142
1143 for (i = 0; i < nsectors; i++) {
1144
1145 /* Read hw-computed remainder */
1146 val1 = readl(info->reg.gpmc_bch_result0[i]);
1147 val2 = readl(info->reg.gpmc_bch_result1[i]);
1148 val3 = readl(info->reg.gpmc_bch_result2[i]);
1149 val4 = readl(info->reg.gpmc_bch_result3[i]);
1150
1151 /*
1152 * Add constant polynomial to remainder, in order to get an ecc
1153 * sequence of 0xFFs for a buffer filled with 0xFFs.
1154 */
1155 *ecc_code++ = 0xef ^ (val4 & 0xFF);
1156 *ecc_code++ = 0x51 ^ ((val3 >> 24) & 0xFF);
1157 *ecc_code++ = 0x2e ^ ((val3 >> 16) & 0xFF);
1158 *ecc_code++ = 0x09 ^ ((val3 >> 8) & 0xFF);
1159 *ecc_code++ = 0xed ^ (val3 & 0xFF);
1160 *ecc_code++ = 0x93 ^ ((val2 >> 24) & 0xFF);
1161 *ecc_code++ = 0x9a ^ ((val2 >> 16) & 0xFF);
1162 *ecc_code++ = 0xc2 ^ ((val2 >> 8) & 0xFF);
1163 *ecc_code++ = 0x97 ^ (val2 & 0xFF);
1164 *ecc_code++ = 0x79 ^ ((val1 >> 24) & 0xFF);
1165 *ecc_code++ = 0xe5 ^ ((val1 >> 16) & 0xFF);
1166 *ecc_code++ = 0x24 ^ ((val1 >> 8) & 0xFF);
1167 *ecc_code++ = 0xb5 ^ (val1 & 0xFF);
1168 }
1169
1170 return 0;
1171}
1172#endif /* CONFIG_MTD_NAND_ECC_BCH */
1173 1127
1174/** 1128/**
1175 * omap_calculate_ecc_bch - Generate bytes of ECC bytes 1129 * omap_calculate_ecc_bch - Generate bytes of ECC bytes
@@ -1194,6 +1148,7 @@ static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
1194 for (i = 0; i < nsectors; i++) { 1148 for (i = 0; i < nsectors; i++) {
1195 ecc_code = ecc_calc; 1149 ecc_code = ecc_calc;
1196 switch (info->ecc_opt) { 1150 switch (info->ecc_opt) {
1151 case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
1197 case OMAP_ECC_BCH8_CODE_HW: 1152 case OMAP_ECC_BCH8_CODE_HW:
1198 bch_val1 = readl(gpmc_regs->gpmc_bch_result0[i]); 1153 bch_val1 = readl(gpmc_regs->gpmc_bch_result0[i]);
1199 bch_val2 = readl(gpmc_regs->gpmc_bch_result1[i]); 1154 bch_val2 = readl(gpmc_regs->gpmc_bch_result1[i]);
@@ -1242,6 +1197,12 @@ static int __maybe_unused omap_calculate_ecc_bch(struct mtd_info *mtd,
1242 /* Set 8th ECC byte as 0x0 for ROM compatibility */ 1197 /* Set 8th ECC byte as 0x0 for ROM compatibility */
1243 ecc_calc[eccbytes - 1] = 0x0; 1198 ecc_calc[eccbytes - 1] = 0x0;
1244 break; 1199 break;
1200 case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
1201 /* Add constant polynomial to remainder, so that
1202 * ECC of blank pages results in 0x0 on reading back */
1203 for (i = 0; i < eccbytes; i++)
1204 ecc_calc[i] ^= bch8_polynomial[i];
1205 break;
1245 case OMAP_ECC_BCH8_CODE_HW: 1206 case OMAP_ECC_BCH8_CODE_HW:
1246 /* Set 14th ECC byte as 0x0 for ROM compatibility */ 1207 /* Set 14th ECC byte as 0x0 for ROM compatibility */
1247 ecc_calc[eccbytes - 1] = 0x0; 1208 ecc_calc[eccbytes - 1] = 0x0;
@@ -1879,7 +1840,7 @@ static int omap_nand_probe(struct platform_device *pdev)
1879 nand_chip->ecc.strength = 8; 1840 nand_chip->ecc.strength = 8;
1880 nand_chip->ecc.hwctl = omap3_enable_hwecc_bch; 1841 nand_chip->ecc.hwctl = omap3_enable_hwecc_bch;
1881 nand_chip->ecc.correct = nand_bch_correct_data; 1842 nand_chip->ecc.correct = nand_bch_correct_data;
1882 nand_chip->ecc.calculate = omap3_calculate_ecc_bch8; 1843 nand_chip->ecc.calculate = omap_calculate_ecc_bch;
1883 /* define ECC layout */ 1844 /* define ECC layout */
1884 ecclayout->eccbytes = nand_chip->ecc.bytes * 1845 ecclayout->eccbytes = nand_chip->ecc.bytes *
1885 (mtd->writesize / 1846 (mtd->writesize /