Lines Matching full:ecc

18 #include <linux/mtd/nand-ecc-sw-bch.h>
122 /* GPMC ecc engine settings for read */
129 /* GPMC ecc engine settings for write */
170 /* fields specific for BCHx_HW ECC scheme */
639 * gen_true_ecc - This function will generate true ECC value
640 * @ecc_buf: buffer to store ecc code
642 * This generated true ECC value can be used when correcting
660 * @ecc_data1: ecc code from nand spare area
661 * @ecc_data2: ecc code from hardware register obtained from hardware ecc
664 * This function compares two ECC's and indicates if there is an error.
740 * ECC values are equal in omap_compare_ecc()
746 pr_debug("ECC UNCORRECTED_ERROR 1\n"); in omap_compare_ecc()
751 pr_debug("ECC UNCORRECTED_ERROR B\n"); in omap_compare_ecc()
768 pr_debug("Correcting single bit ECC error at offset: " in omap_compare_ecc()
787 * omap_correct_data - Compares the ECC read with HW generated ECC
790 * @read_ecc: ecc read from nand flash
791 * @calc_ecc: ecc read from HW ECC registers
793 * Compares the ecc read from nand spare area with ECC registers values
794 * and if ECC's mismatched, it will call 'omap_compare_ecc' for error
808 if (info->nand.ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST && in omap_correct_data()
809 info->nand.ecc.size == 2048) in omap_correct_data()
830 * omap_calculate_ecc - Generate non-inverted ECC bytes.
832 * @dat: The pointer to data on which ecc is computed
835 * Using noninverted ECC can be considered ugly since writing a blank
836 * page ie. padding will clear the ECC bytes. This is no problem as long
838 * an erased page will produce an ECC mismatch between generated and read
839 * ECC bytes that has to be dealt with separately.
851 /* read ecc result */ in omap_calculate_ecc()
862 * omap_enable_hwecc - This function enables the hardware ecc functionality
872 /* clear ecc and enable bits */ in omap_enable_hwecc()
876 /* program ecc and result sizes */ in omap_enable_hwecc()
877 val = ((((info->nand.ecc.size >> 1) - 1) << ECCSIZE1_SHIFT) | in omap_enable_hwecc()
895 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */ in omap_enable_hwecc()
901 * omap_enable_hwecc_bch - Program GPMC to perform BCH ECC calculation
921 /* GPMC configurations for calculating ECC */ in omap_enable_hwecc_bch()
932 nsectors = chip->ecc.steps; in omap_enable_hwecc_bch()
952 nsectors = chip->ecc.steps; in omap_enable_hwecc_bch()
965 nsectors = chip->ecc.steps; in omap_enable_hwecc_bch()
968 ecc_size0 = 52; /* ECC bits in nibbles per sector */ in omap_enable_hwecc_bch()
969 ecc_size1 = 0; /* non-ECC bits in nibbles per sector */ in omap_enable_hwecc_bch()
982 /* Configure ecc size for BCH */ in omap_enable_hwecc_bch()
994 (info->gpmc_cs << 1) | /* ECC CS */ in omap_enable_hwecc_bch()
995 (0x1)); /* enable ECC */ in omap_enable_hwecc_bch()
999 /* Clear ecc and enable bits */ in omap_enable_hwecc_bch()
1008 * _omap_calculate_ecc_bch - Generate ECC bytes for one sector
1010 * @dat: The pointer to data on which ecc is computed
1014 * Support calculating of BCH4/8/16 ECC vectors for one sector
1021 int eccbytes = info->nand.ecc.bytes; in _omap_calculate_ecc_bch()
1102 /* ECC scheme specific syndrome customizations */ in _omap_calculate_ecc_bch()
1106 * ECC of blank pages results in 0x0 on reading back in _omap_calculate_ecc_bch()
1112 /* Set 8th ECC byte as 0x0 for ROM compatibility */ in _omap_calculate_ecc_bch()
1117 * ECC of blank pages results in 0x0 on reading back in _omap_calculate_ecc_bch()
1123 /* Set 14th ECC byte as 0x0 for ROM compatibility */ in _omap_calculate_ecc_bch()
1136 * omap_calculate_ecc_bch_sw - ECC generator for sector for SW based correction
1138 * @dat: The pointer to data on which ecc is computed
1139 * @ecc_calc: Buffer storing the calculated ECC bytes
1141 * Support calculating of BCH4/8/16 ECC vectors for one sector. This is used
1142 * when SW based correction is required as ECC is required for one sector
1152 * omap_calculate_ecc_bch_multi - Generate ECC for multiple sectors
1154 * @dat: The pointer to data on which ecc is computed
1155 * @ecc_calc: Buffer storing the calculated ECC bytes
1157 * Support calculating of BCH4/8/16 ecc vectors for the entire page in one go.
1163 int eccbytes = info->nand.ecc.bytes; in omap_calculate_ecc_bch_multi()
1194 for (i = 0; i < info->nand.ecc.size; i++) { in erased_sector_bitflips()
1196 if (flip_bits > info->nand.ecc.strength) in erased_sector_bitflips()
1200 for (i = 0; i < info->nand.ecc.bytes - 1; i++) { in erased_sector_bitflips()
1202 if (flip_bits > info->nand.ecc.strength) in erased_sector_bitflips()
1211 memset(data, 0xFF, info->nand.ecc.size); in erased_sector_bitflips()
1212 memset(oob, 0xFF, info->nand.ecc.bytes); in erased_sector_bitflips()
1222 * @read_ecc: ecc read from nand flash
1223 * @calc_ecc: ecc read from HW ECC registers
1225 * Calculated ecc vector reported as zero in case of non-error pages.
1226 * In case of non-zero ecc vector, first filter out erased-pages, and
1233 struct nand_ecc_ctrl *ecc = &info->nand.ecc; in omap_elm_correct_data() local
1249 /* omit 7th ECC byte reserved for ROM code compatibility */ in omap_elm_correct_data()
1250 actual_eccbytes = ecc->bytes - 1; in omap_elm_correct_data()
1254 /* omit 14th ECC byte reserved for ROM code compatibility */ in omap_elm_correct_data()
1255 actual_eccbytes = ecc->bytes - 1; in omap_elm_correct_data()
1259 actual_eccbytes = ecc->bytes; in omap_elm_correct_data()
1275 * In case of error, non zero ecc reported. in omap_elm_correct_data()
1279 eccflag = 1; /* non zero ecc, error present */ in omap_elm_correct_data()
1288 * calc_ecc[] matches pattern for ECC(all 0xff) in omap_elm_correct_data()
1292 buf = &data[info->nand.ecc.size * i]; in omap_elm_correct_data()
1302 * number of 0-bits within ECC limits in omap_elm_correct_data()
1319 /* Update the ecc vector */ in omap_elm_correct_data()
1320 calc_ecc += ecc->bytes; in omap_elm_correct_data()
1321 read_ecc += ecc->bytes; in omap_elm_correct_data()
1352 error_max = (ecc->size + actual_eccbytes) * 8; in omap_elm_correct_data()
1384 data += ecc->size; in omap_elm_correct_data()
1385 spare_ecc += ecc->bytes; in omap_elm_correct_data()
1392 * omap_write_page_bch - BCH ecc based write page function for entire page
1405 uint8_t *ecc_calc = chip->ecc.calc_buf; in omap_write_page_bch()
1414 /* Enable GPMC ecc engine */ in omap_write_page_bch()
1415 chip->ecc.hwctl(chip, NAND_ECC_WRITE); in omap_write_page_bch()
1421 /* Update ecc vector from GPMC result registers */ in omap_write_page_bch()
1436 /* Write ecc vector to OOB area */ in omap_write_page_bch()
1443 * omap_write_subpage_bch - BCH hardware ECC based subpage write
1459 u8 *ecc_calc = chip->ecc.calc_buf; in omap_write_subpage_bch()
1460 int ecc_size = chip->ecc.size; in omap_write_subpage_bch()
1461 int ecc_bytes = chip->ecc.bytes; in omap_write_subpage_bch()
1469 * as ECC is calculated by hardware. in omap_write_subpage_bch()
1470 * ECC is calculated for all subpages but we choose in omap_write_subpage_bch()
1478 /* Enable GPMC ECC engine */ in omap_write_subpage_bch()
1479 chip->ecc.hwctl(chip, NAND_ECC_WRITE); in omap_write_subpage_bch()
1489 /* Mask ECC of un-touched subpages with 0xFFs */ in omap_write_subpage_bch()
1505 * Copy the calculated ECC for the whole page including the in omap_write_subpage_bch()
1522 * omap_read_page_bch - BCH ecc based page read function for entire page
1528 * For BCH ecc scheme, GPMC used for syndrome calculation and ELM module
1532 * ecc engine enabled. ecc vector updated after read of OOB data.
1533 * For non error pages ecc vector reported as zero.
1540 uint8_t *ecc_calc = chip->ecc.calc_buf; in omap_read_page_bch()
1541 uint8_t *ecc_code = chip->ecc.code_buf; in omap_read_page_bch()
1550 /* Enable GPMC ecc engine */ in omap_read_page_bch()
1551 chip->ecc.hwctl(chip, NAND_ECC_READ); in omap_read_page_bch()
1570 /* Calculate ecc bytes */ in omap_read_page_bch()
1584 stat = chip->ecc.correct(chip, in omap_read_page_bch()
1696 /* select ecc-scheme for NAND */ in omap_get_dt_info()
1697 if (of_property_read_string(child, "ti,nand-ecc-opt", &s)) { in omap_get_dt_info()
1698 dev_err(dev, "ti,nand-ecc-opt not found\n"); in omap_get_dt_info()
1720 dev_err(dev, "unrecognized value for ti,nand-ecc-opt\n"); in omap_get_dt_info()
1755 oobregion->length = chip->ecc.total; in omap_ooblayout_ecc()
1774 off += chip->ecc.total; in omap_ooblayout_free()
1785 .ecc = omap_ooblayout_ecc,
1802 * reserved after each ECC step. in omap_sw_ooblayout_ecc()
1823 * reserved after each ECC step. in omap_sw_ooblayout_free()
1836 .ecc = omap_sw_ooblayout_ecc,
1942 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT; in omap_nand_attach_chip()
1943 chip->ecc.algo = NAND_ECC_ALGO_HAMMING; in omap_nand_attach_chip()
1947 /* Populate MTD interface based on ECC scheme */ in omap_nand_attach_chip()
1951 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in omap_nand_attach_chip()
1952 chip->ecc.bytes = 3; in omap_nand_attach_chip()
1953 chip->ecc.size = 512; in omap_nand_attach_chip()
1954 chip->ecc.strength = 1; in omap_nand_attach_chip()
1955 chip->ecc.calculate = omap_calculate_ecc; in omap_nand_attach_chip()
1956 chip->ecc.hwctl = omap_enable_hwecc; in omap_nand_attach_chip()
1957 chip->ecc.correct = omap_correct_data; in omap_nand_attach_chip()
1959 oobbytes_per_step = chip->ecc.bytes; in omap_nand_attach_chip()
1968 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in omap_nand_attach_chip()
1969 chip->ecc.size = 512; in omap_nand_attach_chip()
1970 chip->ecc.bytes = 7; in omap_nand_attach_chip()
1971 chip->ecc.strength = 4; in omap_nand_attach_chip()
1972 chip->ecc.hwctl = omap_enable_hwecc_bch; in omap_nand_attach_chip()
1973 chip->ecc.correct = rawnand_sw_bch_correct; in omap_nand_attach_chip()
1974 chip->ecc.calculate = omap_calculate_ecc_bch_sw; in omap_nand_attach_chip()
1977 oobbytes_per_step = chip->ecc.bytes + 1; in omap_nand_attach_chip()
1987 pr_info("nand: using OMAP_ECC_BCH4_CODE_HW ECC scheme\n"); in omap_nand_attach_chip()
1988 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in omap_nand_attach_chip()
1989 chip->ecc.size = 512; in omap_nand_attach_chip()
1991 chip->ecc.bytes = 7 + 1; in omap_nand_attach_chip()
1992 chip->ecc.strength = 4; in omap_nand_attach_chip()
1993 chip->ecc.hwctl = omap_enable_hwecc_bch; in omap_nand_attach_chip()
1994 chip->ecc.correct = omap_elm_correct_data; in omap_nand_attach_chip()
1995 chip->ecc.read_page = omap_read_page_bch; in omap_nand_attach_chip()
1996 chip->ecc.write_page = omap_write_page_bch; in omap_nand_attach_chip()
1997 chip->ecc.write_subpage = omap_write_subpage_bch; in omap_nand_attach_chip()
1999 oobbytes_per_step = chip->ecc.bytes; in omap_nand_attach_chip()
2005 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in omap_nand_attach_chip()
2006 chip->ecc.size = 512; in omap_nand_attach_chip()
2007 chip->ecc.bytes = 13; in omap_nand_attach_chip()
2008 chip->ecc.strength = 8; in omap_nand_attach_chip()
2009 chip->ecc.hwctl = omap_enable_hwecc_bch; in omap_nand_attach_chip()
2010 chip->ecc.correct = rawnand_sw_bch_correct; in omap_nand_attach_chip()
2011 chip->ecc.calculate = omap_calculate_ecc_bch_sw; in omap_nand_attach_chip()
2014 oobbytes_per_step = chip->ecc.bytes + 1; in omap_nand_attach_chip()
2024 pr_info("nand: using OMAP_ECC_BCH8_CODE_HW ECC scheme\n"); in omap_nand_attach_chip()
2025 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in omap_nand_attach_chip()
2026 chip->ecc.size = 512; in omap_nand_attach_chip()
2028 chip->ecc.bytes = 13 + 1; in omap_nand_attach_chip()
2029 chip->ecc.strength = 8; in omap_nand_attach_chip()
2030 chip->ecc.hwctl = omap_enable_hwecc_bch; in omap_nand_attach_chip()
2031 chip->ecc.correct = omap_elm_correct_data; in omap_nand_attach_chip()
2032 chip->ecc.read_page = omap_read_page_bch; in omap_nand_attach_chip()
2033 chip->ecc.write_page = omap_write_page_bch; in omap_nand_attach_chip()
2034 chip->ecc.write_subpage = omap_write_subpage_bch; in omap_nand_attach_chip()
2036 oobbytes_per_step = chip->ecc.bytes; in omap_nand_attach_chip()
2041 pr_info("Using OMAP_ECC_BCH16_CODE_HW ECC scheme\n"); in omap_nand_attach_chip()
2042 chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in omap_nand_attach_chip()
2043 chip->ecc.size = 512; in omap_nand_attach_chip()
2044 chip->ecc.bytes = 26; in omap_nand_attach_chip()
2045 chip->ecc.strength = 16; in omap_nand_attach_chip()
2046 chip->ecc.hwctl = omap_enable_hwecc_bch; in omap_nand_attach_chip()
2047 chip->ecc.correct = omap_elm_correct_data; in omap_nand_attach_chip()
2048 chip->ecc.read_page = omap_read_page_bch; in omap_nand_attach_chip()
2049 chip->ecc.write_page = omap_write_page_bch; in omap_nand_attach_chip()
2050 chip->ecc.write_subpage = omap_write_subpage_bch; in omap_nand_attach_chip()
2052 oobbytes_per_step = chip->ecc.bytes; in omap_nand_attach_chip()
2056 dev_err(dev, "Invalid or unsupported ECC scheme\n"); in omap_nand_attach_chip()
2061 chip->ecc.steps = mtd->writesize / chip->ecc.size; in omap_nand_attach_chip()
2062 info->neccpg = chip->ecc.steps / ERROR_VECTOR_MAX; in omap_nand_attach_chip()
2067 info->nsteps_per_eccpg = chip->ecc.steps; in omap_nand_attach_chip()
2069 info->eccpg_size = info->nsteps_per_eccpg * chip->ecc.size; in omap_nand_attach_chip()
2070 info->eccpg_bytes = info->nsteps_per_eccpg * chip->ecc.bytes; in omap_nand_attach_chip()
2073 info->nsteps_per_eccpg, chip->ecc.size, in omap_nand_attach_chip()
2074 chip->ecc.bytes); in omap_nand_attach_chip()
2079 /* Check if NAND device's OOB is enough to store ECC signatures */ in omap_nand_attach_chip()
2081 (mtd->writesize / chip->ecc.size)); in omap_nand_attach_chip()
2193 /* Shared among all NAND instances to synchronize access to the ECC Engine */