Skip to content

Commit be2f092

Browse files
atsushi-nemotoDavid Woodhouse
authored andcommitted
mtd: nand: add __nand_correct_data helper function
Split nand_correct_data() into two part, a pure calculation function and a wrapper for mtd interface. The tmio_nand driver can implement its ecc.correct function easily using this __nand_correct_data helper. Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Acked-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Acked-by: Vimal Singh <vimalsingh@ti.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 23af51e commit be2f092

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

‎drivers/mtd/nand/nand_ecc.c‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,22 +417,22 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
417417
EXPORT_SYMBOL(nand_calculate_ecc);
418418

419419
/**
420-
* nand_correct_data - [NAND Interface] Detect and correct bit error(s)
421-
* @mtd: MTD block structure
420+
* __nand_correct_data - [NAND Interface] Detect and correct bit error(s)
422421
* @buf: raw data read from the chip
423422
* @read_ecc: ECC from the chip
424423
* @calc_ecc: the ECC calculated from raw data
424+
* @eccsize: data bytes per ecc step (256 or 512)
425425
*
426-
* Detect and correct a 1 bit error for 256/512 byte block
426+
* Detect and correct a 1 bit error for eccsize byte block
427427
*/
428-
int nand_correct_data(struct mtd_info *mtd, unsigned char *buf,
429-
unsigned char *read_ecc, unsigned char *calc_ecc)
428+
int __nand_correct_data(unsigned char *buf,
429+
unsigned char *read_ecc, unsigned char *calc_ecc,
430+
unsigned int eccsize)
430431
{
431432
unsigned char b0, b1, b2, bit_addr;
432433
unsigned int byte_addr;
433434
/* 256 or 512 bytes/ecc */
434-
const uint32_t eccsize_mult =
435-
(((struct nand_chip *)mtd->priv)->ecc.size) >> 8;
435+
const uint32_t eccsize_mult = eccsize >> 8;
436436

437437
/*
438438
* b0 to b2 indicate which bit is faulty (if any)
@@ -495,6 +495,23 @@ int nand_correct_data(struct mtd_info *mtd, unsigned char *buf,
495495
printk(KERN_ERR "uncorrectable error : ");
496496
return -1;
497497
}
498+
EXPORT_SYMBOL(__nand_correct_data);
499+
500+
/**
501+
* nand_correct_data - [NAND Interface] Detect and correct bit error(s)
502+
* @mtd: MTD block structure
503+
* @buf: raw data read from the chip
504+
* @read_ecc: ECC from the chip
505+
* @calc_ecc: the ECC calculated from raw data
506+
*
507+
* Detect and correct a 1 bit error for 256/512 byte block
508+
*/
509+
int nand_correct_data(struct mtd_info *mtd, unsigned char *buf,
510+
unsigned char *read_ecc, unsigned char *calc_ecc)
511+
{
512+
return __nand_correct_data(buf, read_ecc, calc_ecc,
513+
((struct nand_chip *)mtd->priv)->ecc.size);
514+
}
498515
EXPORT_SYMBOL(nand_correct_data);
499516

500517
MODULE_LICENSE("GPL");

‎include/linux/mtd/nand_ecc.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ struct mtd_info;
2020
*/
2121
int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code);
2222

23+
/*
24+
* Detect and correct a 1 bit error for eccsize byte block
25+
*/
26+
int __nand_correct_data(u_char *dat, u_char *read_ecc, u_char *calc_ecc,
27+
unsigned int eccsize);
28+
2329
/*
2430
* Detect and correct a 1 bit error for 256 byte block
2531
*/

0 commit comments

Comments
 (0)