aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAtsushi Nemoto <anemo@mba.ocn.ne.jp>2009-09-04 12:20:43 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2009-09-19 17:20:25 -0400
commitbe2f092bfc4f6a415bb4c3e2dcbf521a1f2a0fe5 (patch)
tree7994454518bdfd2977a2866befcec8983647188e
parent23af51ecfb04ff65bae51bd8e2270f4449abc789 (diff)
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>
-rw-r--r--drivers/mtd/nand/nand_ecc.c31
-rw-r--r--include/linux/mtd/nand_ecc.h6
2 files changed, 30 insertions, 7 deletions
diff --git a/drivers/mtd/nand/nand_ecc.c b/drivers/mtd/nand/nand_ecc.c
index c0cb87d6d16e..db7ae9d6a296 100644
--- a/drivers/mtd/nand/nand_ecc.c
+++ b/drivers/mtd/nand/nand_ecc.c
@@ -417,22 +417,22 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
417EXPORT_SYMBOL(nand_calculate_ecc); 417EXPORT_SYMBOL(nand_calculate_ecc);
418 418
419/** 419/**
420 * nand_correct_data - [NAND Interface] Detect and correct bit error(s) 420 * __nand_correct_data - [NAND Interface] Detect and correct bit error(s)
421 * @mtd: MTD block structure
422 * @buf: raw data read from the chip 421 * @buf: raw data read from the chip
423 * @read_ecc: ECC from the chip 422 * @read_ecc: ECC from the chip
424 * @calc_ecc: the ECC calculated from raw data 423 * @calc_ecc: the ECC calculated from raw data
424 * @eccsize: data bytes per ecc step (256 or 512)
425 * 425 *
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
427 */ 427 */
428int nand_correct_data(struct mtd_info *mtd, unsigned char *buf, 428int __nand_correct_data(unsigned char *buf,
429 unsigned char *read_ecc, unsigned char *calc_ecc) 429 unsigned char *read_ecc, unsigned char *calc_ecc,
430 unsigned int eccsize)
430{ 431{
431 unsigned char b0, b1, b2, bit_addr; 432 unsigned char b0, b1, b2, bit_addr;
432 unsigned int byte_addr; 433 unsigned int byte_addr;
433 /* 256 or 512 bytes/ecc */ 434 /* 256 or 512 bytes/ecc */
434 const uint32_t eccsize_mult = 435 const uint32_t eccsize_mult = eccsize >> 8;
435 (((struct nand_chip *)mtd->priv)->ecc.size) >> 8;
436 436
437 /* 437 /*
438 * b0 to b2 indicate which bit is faulty (if any) 438 * 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,
495 printk(KERN_ERR "uncorrectable error : "); 495 printk(KERN_ERR "uncorrectable error : ");
496 return -1; 496 return -1;
497} 497}
498EXPORT_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 */
509int 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}
498EXPORT_SYMBOL(nand_correct_data); 515EXPORT_SYMBOL(nand_correct_data);
499 516
500MODULE_LICENSE("GPL"); 517MODULE_LICENSE("GPL");
diff --git a/include/linux/mtd/nand_ecc.h b/include/linux/mtd/nand_ecc.h
index 090da505425d..052ea8ca2434 100644
--- a/include/linux/mtd/nand_ecc.h
+++ b/include/linux/mtd/nand_ecc.h
@@ -21,6 +21,12 @@ struct mtd_info;
21int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code); 21int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code);
22 22
23/* 23/*
24 * Detect and correct a 1 bit error for eccsize byte block
25 */
26int __nand_correct_data(u_char *dat, u_char *read_ecc, u_char *calc_ecc,
27 unsigned int eccsize);
28
29/*
24 * Detect and correct a 1 bit error for 256 byte block 30 * Detect and correct a 1 bit error for 256 byte block
25 */ 31 */
26int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc); 32int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc);