Skip to content

Commit 1c63aca

Browse files
mitaDavid Woodhouse
authored andcommitted
mtd: Add __nand_calculate_ecc() to NAND ECC functions
Add __nand_calculate_ecc() which does not take struct mtd_info. The built-in 256/512 software ECC calculation and correction tester will use it. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Acked-by: Vimal Singh <vimalsingh@ti.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 3cf6025 commit 1c63aca

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎drivers/mtd/nand/nand_ecc.c‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,19 @@ static const char addressbits[256] = {
150150
};
151151

152152
/**
153-
* nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
153+
* __nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
154154
* block
155-
* @mtd: MTD block structure
156155
* @buf: input buffer with raw data
156+
* @eccsize: data bytes per ecc step (256 or 512)
157157
* @code: output buffer with ECC
158158
*/
159-
int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
159+
void __nand_calculate_ecc(const unsigned char *buf, unsigned int eccsize,
160160
unsigned char *code)
161161
{
162162
int i;
163163
const uint32_t *bp = (uint32_t *)buf;
164164
/* 256 or 512 bytes/ecc */
165-
const uint32_t eccsize_mult =
166-
(((struct nand_chip *)mtd->priv)->ecc.size) >> 8;
165+
const uint32_t eccsize_mult = eccsize >> 8;
167166
uint32_t cur; /* current value in buffer */
168167
/* rp0..rp15..rp17 are the various accumulated parities (per byte) */
169168
uint32_t rp0, rp1, rp2, rp3, rp4, rp5, rp6, rp7;
@@ -412,6 +411,22 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
412411
(invparity[par & 0x55] << 2) |
413412
(invparity[rp17] << 1) |
414413
(invparity[rp16] << 0);
414+
}
415+
EXPORT_SYMBOL(__nand_calculate_ecc);
416+
417+
/**
418+
* nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
419+
* block
420+
* @mtd: MTD block structure
421+
* @buf: input buffer with raw data
422+
* @code: output buffer with ECC
423+
*/
424+
int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
425+
unsigned char *code)
426+
{
427+
__nand_calculate_ecc(buf,
428+
((struct nand_chip *)mtd->priv)->ecc.size, code);
429+
415430
return 0;
416431
}
417432
EXPORT_SYMBOL(nand_calculate_ecc);

‎include/linux/mtd/nand_ecc.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
struct mtd_info;
1717

1818
/*
19-
* Calculate 3 byte ECC code for 256 byte block
19+
* Calculate 3 byte ECC code for eccsize byte block
20+
*/
21+
void __nand_calculate_ecc(const u_char *dat, unsigned int eccsize,
22+
u_char *ecc_code);
23+
24+
/*
25+
* Calculate 3 byte ECC code for 256/512 byte block
2026
*/
2127
int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code);
2228

@@ -27,7 +33,7 @@ int __nand_correct_data(u_char *dat, u_char *read_ecc, u_char *calc_ecc,
2733
unsigned int eccsize);
2834

2935
/*
30-
* Detect and correct a 1 bit error for 256 byte block
36+
* Detect and correct a 1 bit error for 256/512 byte block
3137
*/
3238
int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc);
3339

0 commit comments

Comments
 (0)