Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Akinobu Mita and committed by
David Woodhouse
1c63aca3 3cf60253

+28 -7
+20 -5
drivers/mtd/nand/nand_ecc.c
··· 150 150 }; 151 151 152 152 /** 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 154 154 * block 155 - * @mtd: MTD block structure 156 155 * @buf: input buffer with raw data 156 + * @eccsize: data bytes per ecc step (256 or 512) 157 157 * @code: output buffer with ECC 158 158 */ 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, 160 160 unsigned char *code) 161 161 { 162 162 int i; 163 163 const uint32_t *bp = (uint32_t *)buf; 164 164 /* 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; 167 166 uint32_t cur; /* current value in buffer */ 168 167 /* rp0..rp15..rp17 are the various accumulated parities (per byte) */ 169 168 uint32_t rp0, rp1, rp2, rp3, rp4, rp5, rp6, rp7; ··· 411 412 (invparity[par & 0x55] << 2) | 412 413 (invparity[rp17] << 1) | 413 414 (invparity[rp16] << 0); 415 + } 416 + EXPORT_SYMBOL(__nand_calculate_ecc); 417 + 418 + /** 419 + * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte 420 + * block 421 + * @mtd: MTD block structure 422 + * @buf: input buffer with raw data 423 + * @code: output buffer with ECC 424 + */ 425 + int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf, 426 + unsigned char *code) 427 + { 428 + __nand_calculate_ecc(buf, 429 + ((struct nand_chip *)mtd->priv)->ecc.size, code); 430 + 414 431 return 0; 415 432 } 416 433 EXPORT_SYMBOL(nand_calculate_ecc);
+8 -2
include/linux/mtd/nand_ecc.h
··· 16 16 struct mtd_info; 17 17 18 18 /* 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 20 26 */ 21 27 int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code); 22 28 ··· 33 27 unsigned int eccsize); 34 28 35 29 /* 36 - * Detect and correct a 1 bit error for 256 byte block 30 + * Detect and correct a 1 bit error for 256/512 byte block 37 31 */ 38 32 int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc); 39 33