Move the function nand_read_page_hwecc_oob_first() (previously nand_davinci_read_page_hwecc_oob_first()) to nand_base.c, and export it as a GPL symbol, so that it can be used by more modules.
Unified · Split
| @@ -371,73 +371,6 @@ correct: · 370 unmodified lines | ||
| 371 | 371 | return corrected; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | −/** | |
| 375 | − * nand_davinci_read_page_hwecc_oob_first - Hardware ECC page read with ECC | |
| 376 | − * data read from OOB area | |
| 377 | − * @chip: nand chip info structure | |
| 378 | − * @buf: buffer to store read data | |
| 379 | − * @oob_required: caller requires OOB data read to chip->oob_poi | |
| 380 | − * @page: page number to read | |
| 381 | − * | |
| 382 | − * Hardware ECC for large page chips, which requires the ECC data to be | |
| 383 | − * extracted from the OOB before the actual data is read. | |
| 384 | − */ | |
| 385 | −static int nand_davinci_read_page_hwecc_oob_first(struct nand_chip *chip, | |
| 386 | − uint8_t *buf, | |
| 387 | − int oob_required, int page) | |
| 388 | −{ | |
| 389 | − struct mtd_info *mtd = nand_to_mtd(chip); | |
| 390 | − int i, eccsize = chip->ecc.size, ret; | |
| 391 | − int eccbytes = chip->ecc.bytes; | |
| 392 | − int eccsteps = chip->ecc.steps; | |
| 393 | − uint8_t *p = buf; | |
| 394 | − uint8_t *ecc_code = chip->ecc.code_buf; | |
| 395 | − unsigned int max_bitflips = 0; | |
| 396 | − | |
| 397 | − /* Read the OOB area first */ | |
| 398 | − ret = nand_read_oob_op(chip, page, 0, chip->oob_poi, mtd->oobsize); | |
| 399 | − if (ret) | |
| 400 | − return ret; | |
| 401 | − | |
| 402 | − /* Move read cursor to start of page */ | |
| 403 | − ret = nand_change_read_column_op(chip, 0, NULL, 0, false); | |
| 404 | − if (ret) | |
| 405 | − return ret; | |
| 406 | − | |
| 407 | − ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0, | |
| 408 | − chip->ecc.total); | |
| 409 | − if (ret) | |
| 410 | − return ret; | |
| 411 | − | |
| 412 | − for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { | |
| 413 | − int stat; | |
| 414 | − | |
| 415 | − chip->ecc.hwctl(chip, NAND_ECC_READ); | |
| 416 | − | |
| 417 | − ret = nand_read_data_op(chip, p, eccsize, false, false); | |
| 418 | − if (ret) | |
| 419 | − return ret; | |
| 420 | − | |
| 421 | − stat = chip->ecc.correct(chip, p, &ecc_code[i], NULL); | |
| 422 | − if (stat == -EBADMSG && | |
| 423 | − (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { | |
| 424 | − /* check for empty pages with bitflips */ | |
| 425 | − stat = nand_check_erased_ecc_chunk(p, eccsize, | |
| 426 | − &ecc_code[i], | |
| 427 | − eccbytes, NULL, 0, | |
| 428 | − chip->ecc.strength); | |
| 429 | − } | |
| 430 | − | |
| 431 | − if (stat < 0) { | |
| 432 | − mtd->ecc_stats.failed++; | |
| 433 | − } else { | |
| 434 | − mtd->ecc_stats.corrected += stat; | |
| 435 | − max_bitflips = max_t(unsigned int, max_bitflips, stat); | |
| 436 | − } | |
| 437 | − } | |
| 438 | − return max_bitflips; | |
| 439 | −} | |
| 440 | − | |
| 441 | 374 | /*----------------------------------------------------------------------*/ |
| 442 | 375 | |
| 443 | 376 | /* An ECC layout for using 4-bit ECC with small-page flash, storing |
| @@ -647,7 +580,7 @@ static int davinci_nand_attach_chip(struct nand_chip *chip) · 203 unmodified lines | ||
| 647 | 580 | } else if (chunks == 4 || chunks == 8) { |
| 648 | 581 | mtd_set_ooblayout(mtd, |
| 649 | 582 | nand_get_large_page_ooblayout()); |
| 650 | − chip->ecc.read_page = nand_davinci_read_page_hwecc_oob_first; | |
| 583 | + chip->ecc.read_page = nand_read_page_hwecc_oob_first; | |
| 651 | 584 | } else { |
| 652 | 585 | return -EIO; |
| 653 | 586 | } |
| @@ -3160,6 +3160,73 @@ static int nand_read_page_hwecc(struct nand_chip *chip, uint8_t *buf, · 3159 unmodified lines | ||
| 3160 | 3160 | return max_bitflips; |
| 3161 | 3161 | } |
| 3162 | 3162 | |
| 3163 | +/** | |
| 3164 | + * nand_read_page_hwecc_oob_first - Hardware ECC page read with ECC | |
| 3165 | + * data read from OOB area | |
| 3166 | + * @chip: nand chip info structure | |
| 3167 | + * @buf: buffer to store read data | |
| 3168 | + * @oob_required: caller requires OOB data read to chip->oob_poi | |
| 3169 | + * @page: page number to read | |
| 3170 | + * | |
| 3171 | + * Hardware ECC for large page chips, which requires the ECC data to be | |
| 3172 | + * extracted from the OOB before the actual data is read. | |
| 3173 | + */ | |
| 3174 | +int nand_read_page_hwecc_oob_first(struct nand_chip *chip, uint8_t *buf, | |
| 3175 | + int oob_required, int page) | |
| 3176 | +{ | |
| 3177 | + struct mtd_info *mtd = nand_to_mtd(chip); | |
| 3178 | + int i, eccsize = chip->ecc.size, ret; | |
| 3179 | + int eccbytes = chip->ecc.bytes; | |
| 3180 | + int eccsteps = chip->ecc.steps; | |
| 3181 | + uint8_t *p = buf; | |
| 3182 | + uint8_t *ecc_code = chip->ecc.code_buf; | |
| 3183 | + unsigned int max_bitflips = 0; | |
| 3184 | + | |
| 3185 | + /* Read the OOB area first */ | |
| 3186 | + ret = nand_read_oob_op(chip, page, 0, chip->oob_poi, mtd->oobsize); | |
| 3187 | + if (ret) | |
| 3188 | + return ret; | |
| 3189 | + | |
| 3190 | + /* Move read cursor to start of page */ | |
| 3191 | + ret = nand_change_read_column_op(chip, 0, NULL, 0, false); | |
| 3192 | + if (ret) | |
| 3193 | + return ret; | |
| 3194 | + | |
| 3195 | + ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0, | |
| 3196 | + chip->ecc.total); | |
| 3197 | + if (ret) | |
| 3198 | + return ret; | |
| 3199 | + | |
| 3200 | + for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { | |
| 3201 | + int stat; | |
| 3202 | + | |
| 3203 | + chip->ecc.hwctl(chip, NAND_ECC_READ); | |
| 3204 | + | |
| 3205 | + ret = nand_read_data_op(chip, p, eccsize, false, false); | |
| 3206 | + if (ret) | |
| 3207 | + return ret; | |
| 3208 | + | |
| 3209 | + stat = chip->ecc.correct(chip, p, &ecc_code[i], NULL); | |
| 3210 | + if (stat == -EBADMSG && | |
| 3211 | + (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { | |
| 3212 | + /* check for empty pages with bitflips */ | |
| 3213 | + stat = nand_check_erased_ecc_chunk(p, eccsize, | |
| 3214 | + &ecc_code[i], | |
| 3215 | + eccbytes, NULL, 0, | |
| 3216 | + chip->ecc.strength); | |
| 3217 | + } | |
| 3218 | + | |
| 3219 | + if (stat < 0) { | |
| 3220 | + mtd->ecc_stats.failed++; | |
| 3221 | + } else { | |
| 3222 | + mtd->ecc_stats.corrected += stat; | |
| 3223 | + max_bitflips = max_t(unsigned int, max_bitflips, stat); | |
| 3224 | + } | |
| 3225 | + } | |
| 3226 | + return max_bitflips; | |
| 3227 | +} | |
| 3228 | +EXPORT_SYMBOL_GPL(nand_read_page_hwecc_oob_first); | |
| 3229 | + | |
| 3163 | 3230 | /** |
| 3164 | 3231 | * nand_read_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page read |
| 3165 | 3232 | * @chip: nand chip info structure |
| @@ -1539,6 +1539,8 @@ int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len, · 1538 unmodified lines | ||
| 1539 | 1539 | bool force_8bit, bool check_only); |
| 1540 | 1540 | int nand_write_data_op(struct nand_chip *chip, const void *buf, |
| 1541 | 1541 | unsigned int len, bool force_8bit); |
| 1542 | +int nand_read_page_hwecc_oob_first(struct nand_chip *chip, uint8_t *buf, | |
| 1543 | + int oob_required, int page); | |
| 1542 | 1544 | |
| 1543 | 1545 | /* Scan and identify a NAND device */ |
| 1544 | 1546 | int nand_scan_with_ids(struct nand_chip *chip, unsigned int max_chips, |