22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/bitops.h>
52 int nand_bch_calculate_ecc(
struct mtd_info *mtd,
const unsigned char *
buf,
63 for (i = 0; i < chip->
ecc.bytes; i++)
79 int nand_bch_correct_data(
struct mtd_info *mtd,
unsigned char *
buf,
80 unsigned char *read_ecc,
unsigned char *calc_ecc)
90 for (i = 0; i <
count; i++) {
91 if (errloc[i] < (chip->
ecc.size*8))
93 buf[errloc[
i] >> 3] ^= (1 << (errloc[
i] & 7));
96 pr_debug(
"%s: corrected bitflip %u\n", __func__,
99 }
else if (count < 0) {
127 nand_bch_init(
struct mtd_info *mtd,
unsigned int eccsize,
unsigned int eccbytes,
130 unsigned int m,
t, eccsteps,
i;
133 unsigned char *erased_page;
135 if (!eccsize || !eccbytes) {
140 m = fls(1+8*eccsize);
152 if (nbc->
bch->ecc_bytes != eccbytes) {
154 eccbytes, nbc->
bch->ecc_bytes);
171 layout->
eccbytes = eccsteps*eccbytes;
176 "for oobsize %d eccbytes %u\n", mtd->
oobsize,
181 for (i = 0; i < layout->
eccbytes; i++)
191 if (8*(eccsize+eccbytes) >= (1 << m)) {
195 if ((*ecclayout)->eccbytes != (eccsteps*eccbytes)) {
211 memset(erased_page, 0xff, eccsize);
216 for (i = 0; i < eccbytes; i++)