]> git.sur5r.net Git - u-boot/blobdiff - drivers/mtd/nand/nand_bch.c
mtd: nand: Sync with Linux v4.6
[u-boot] / drivers / mtd / nand / nand_bch.c
index d7f6ce0acfd8d3479fe82d88afd08af821981fd1..c14520380e6324b36854a9f2c99ff6d42741b4af 100644 (file)
@@ -86,7 +86,7 @@ int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
                }
        } else if (count < 0) {
                printk(KERN_ERR "ecc unrecoverable error\n");
-               count = -1;
+               count = -EBADMSG;
        }
        return count;
 }
@@ -94,9 +94,6 @@ int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
 /**
  * nand_bch_init - [NAND Interface] Initialize NAND BCH error correction
  * @mtd:       MTD block structure
- * @eccsize:   ecc block size in bytes
- * @eccbytes:  ecc length in bytes
- * @ecclayout: output default layout
  *
  * Returns:
  *  a pointer to a new NAND BCH control structure, or NULL upon failure
@@ -110,14 +107,21 @@ int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
  * @eccsize = 512  (thus, m=13 is the smallest integer such that 2^m-1 > 512*8)
  * @eccbytes = 7   (7 bytes are required to store m*t = 13*4 = 52 bits)
  */
-struct nand_bch_control *
-nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, unsigned int eccbytes,
-             struct nand_ecclayout **ecclayout)
+struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
 {
+       struct nand_chip *nand = mtd_to_nand(mtd);
        unsigned int m, t, eccsteps, i;
-       struct nand_ecclayout *layout;
+       struct nand_ecclayout *layout = nand->ecc.layout;
        struct nand_bch_control *nbc = NULL;
        unsigned char *erased_page;
+       unsigned int eccsize = nand->ecc.size;
+       unsigned int eccbytes = nand->ecc.bytes;
+       unsigned int eccstrength = nand->ecc.strength;
+
+       if (!eccbytes && eccstrength) {
+               eccbytes = DIV_ROUND_UP(eccstrength * fls(8 * eccsize), 8);
+               nand->ecc.bytes = eccbytes;
+       }
 
        if (!eccsize || !eccbytes) {
                printk(KERN_WARNING "ecc parameters not supplied\n");
@@ -145,7 +149,7 @@ nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, unsigned int eccbytes,
        eccsteps = mtd->writesize/eccsize;
 
        /* if no ecc placement scheme was provided, build one */
-       if (!*ecclayout) {
+       if (!layout) {
 
                /* handle large page devices only */
                if (mtd->oobsize < 64) {
@@ -171,7 +175,7 @@ nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, unsigned int eccbytes,
                layout->oobfree[0].offset = 2;
                layout->oobfree[0].length = mtd->oobsize-2-layout->eccbytes;
 
-               *ecclayout = layout;
+               nand->ecc.layout = layout;
        }
 
        /* sanity checks */
@@ -179,7 +183,7 @@ nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, unsigned int eccbytes,
                printk(KERN_WARNING "eccsize %u is too large\n", eccsize);
                goto fail;
        }
-       if ((*ecclayout)->eccbytes != (eccsteps*eccbytes)) {
+       if (layout->eccbytes != (eccsteps*eccbytes)) {
                printk(KERN_WARNING "invalid ecc layout\n");
                goto fail;
        }
@@ -203,6 +207,9 @@ nand_bch_init(struct mtd_info *mtd, unsigned int eccsize, unsigned int eccbytes,
        for (i = 0; i < eccbytes; i++)
                nbc->eccmask[i] ^= 0xff;
 
+       if (!eccstrength)
+               nand->ecc.strength = (eccbytes * 8) / fls(8 * eccsize);
+
        return nbc;
 fail:
        nand_bch_free(nbc);