Skip to content

Commit

Permalink
mtd: nand: add __nand_correct_data helper function
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Dmitry Eremin-Solenikov <[email protected]>
Acked-by: Vimal Singh <[email protected]>
Signed-off-by: David Woodhouse <[email protected]>
  • Loading branch information
atsushi-nemoto authored and David Woodhouse committed Sep 19, 2009
1 parent 23af51e commit be2f092
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
31 changes: 24 additions & 7 deletions drivers/mtd/nand/nand_ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,22 +417,22 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
EXPORT_SYMBOL(nand_calculate_ecc);

/**
* nand_correct_data - [NAND Interface] Detect and correct bit error(s)
* @mtd: MTD block structure
* __nand_correct_data - [NAND Interface] Detect and correct bit error(s)
* @buf: raw data read from the chip
* @read_ecc: ECC from the chip
* @calc_ecc: the ECC calculated from raw data
* @eccsize: data bytes per ecc step (256 or 512)
*
* Detect and correct a 1 bit error for 256/512 byte block
* Detect and correct a 1 bit error for eccsize byte block
*/
int nand_correct_data(struct mtd_info *mtd, unsigned char *buf,
unsigned char *read_ecc, unsigned char *calc_ecc)
int __nand_correct_data(unsigned char *buf,
unsigned char *read_ecc, unsigned char *calc_ecc,
unsigned int eccsize)
{
unsigned char b0, b1, b2, bit_addr;
unsigned int byte_addr;
/* 256 or 512 bytes/ecc */
const uint32_t eccsize_mult =
(((struct nand_chip *)mtd->priv)->ecc.size) >> 8;
const uint32_t eccsize_mult = eccsize >> 8;

/*
* b0 to b2 indicate which bit is faulty (if any)
Expand Down Expand Up @@ -495,6 +495,23 @@ int nand_correct_data(struct mtd_info *mtd, unsigned char *buf,
printk(KERN_ERR "uncorrectable error : ");
return -1;
}
EXPORT_SYMBOL(__nand_correct_data);

/**
* nand_correct_data - [NAND Interface] Detect and correct bit error(s)
* @mtd: MTD block structure
* @buf: raw data read from the chip
* @read_ecc: ECC from the chip
* @calc_ecc: the ECC calculated from raw data
*
* Detect and correct a 1 bit error for 256/512 byte block
*/
int nand_correct_data(struct mtd_info *mtd, unsigned char *buf,
unsigned char *read_ecc, unsigned char *calc_ecc)
{
return __nand_correct_data(buf, read_ecc, calc_ecc,
((struct nand_chip *)mtd->priv)->ecc.size);
}
EXPORT_SYMBOL(nand_correct_data);

MODULE_LICENSE("GPL");
Expand Down
6 changes: 6 additions & 0 deletions include/linux/mtd/nand_ecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ struct mtd_info;
*/
int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code);

/*
* Detect and correct a 1 bit error for eccsize byte block
*/
int __nand_correct_data(u_char *dat, u_char *read_ecc, u_char *calc_ecc,
unsigned int eccsize);

/*
* Detect and correct a 1 bit error for 256 byte block
*/
Expand Down

0 comments on commit be2f092

Please sign in to comment.