Merge git://git.infradead.org/mtd-2.6
[firefly-linux-kernel-4.4.55.git] / drivers / mtd / onenand / onenand_base.c
index bac41caa8df72d8967caf93fd4f2fc96309f07c7..ac9e959802a7b113e838ecb8d6e24aee5b7df524 100644 (file)
@@ -65,11 +65,11 @@ MODULE_PARM_DESC(otp,       "Corresponding behaviour of OneNAND in OTP"
                        "          : 2 -> 1st Block lock"
                        "          : 3 -> BOTH OTP Block and 1st Block lock");
 
-/**
- *  onenand_oob_128 - oob info for Flex-Onenand with 4KB page
- *  For now, we expose only 64 out of 80 ecc bytes
+/*
+ * flexonenand_oob_128 - oob info for Flex-Onenand with 4KB page
+ * For now, we expose only 64 out of 80 ecc bytes
  */
-static struct nand_ecclayout onenand_oob_128 = {
+static struct nand_ecclayout flexonenand_oob_128 = {
        .eccbytes       = 64,
        .eccpos         = {
                6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
@@ -86,6 +86,35 @@ static struct nand_ecclayout onenand_oob_128 = {
        }
 };
 
+/*
+ * onenand_oob_128 - oob info for OneNAND with 4KB page
+ *
+ * Based on specification:
+ * 4Gb M-die OneNAND Flash (KFM4G16Q4M, KFN8G16Q4M). Rev. 1.3, Apr. 2010
+ *
+ * For eccpos we expose only 64 bytes out of 72 (see struct nand_ecclayout)
+ *
+ * oobfree uses the spare area fields marked as
+ * "Managed by internal ECC logic for Logical Sector Number area"
+ */
+static struct nand_ecclayout onenand_oob_128 = {
+       .eccbytes       = 64,
+       .eccpos         = {
+               7, 8, 9, 10, 11, 12, 13, 14, 15,
+               23, 24, 25, 26, 27, 28, 29, 30, 31,
+               39, 40, 41, 42, 43, 44, 45, 46, 47,
+               55, 56, 57, 58, 59, 60, 61, 62, 63,
+               71, 72, 73, 74, 75, 76, 77, 78, 79,
+               87, 88, 89, 90, 91, 92, 93, 94, 95,
+               103, 104, 105, 106, 107, 108, 109, 110, 111,
+               119
+       },
+       .oobfree        = {
+               {2, 3}, {18, 3}, {34, 3}, {50, 3},
+               {66, 3}, {82, 3}, {98, 3}, {114, 3}
+       }
+};
+
 /**
  * onenand_oob_64 - oob info for large (2KB) page
  */
@@ -1132,6 +1161,8 @@ static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from,
                        onenand_update_bufferram(mtd, from, !ret);
                        if (ret == -EBADMSG)
                                ret = 0;
+                       if (ret)
+                               break;
                }
 
                this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen);
@@ -1646,11 +1677,10 @@ static int onenand_verify(struct mtd_info *mtd, const u_char *buf, loff_t addr,
        int ret = 0;
        int thislen, column;
 
+       column = addr & (this->writesize - 1);
+
        while (len != 0) {
-               thislen = min_t(int, this->writesize, len);
-               column = addr & (this->writesize - 1);
-               if (column + thislen > this->writesize)
-                       thislen = this->writesize - column;
+               thislen = min_t(int, this->writesize - column, len);
 
                this->command(mtd, ONENAND_CMD_READ, addr, this->writesize);
 
@@ -1664,12 +1694,13 @@ static int onenand_verify(struct mtd_info *mtd, const u_char *buf, loff_t addr,
 
                this->read_bufferram(mtd, ONENAND_DATARAM, this->verify_buf, 0, mtd->writesize);
 
-               if (memcmp(buf, this->verify_buf, thislen))
+               if (memcmp(buf, this->verify_buf + column, thislen))
                        return -EBADMSG;
 
                len -= thislen;
                buf += thislen;
                addr += thislen;
+               column = 0;
        }
 
        return 0;
@@ -2422,7 +2453,7 @@ static int onenand_block_by_block_erase(struct mtd_info *mtd,
                len -= block_size;
                addr += block_size;
 
-               if (addr == region_end) {
+               if (region && addr == region_end) {
                        if (!len)
                                break;
                        region++;
@@ -4016,8 +4047,13 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
         */
        switch (mtd->oobsize) {
        case 128:
-               this->ecclayout = &onenand_oob_128;
-               mtd->subpage_sft = 0;
+               if (FLEXONENAND(this)) {
+                       this->ecclayout = &flexonenand_oob_128;
+                       mtd->subpage_sft = 0;
+               } else {
+                       this->ecclayout = &onenand_oob_128;
+                       mtd->subpage_sft = 2;
+               }
                break;
        case 64:
                this->ecclayout = &onenand_oob_64;
@@ -4083,7 +4119,8 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
        mtd->writebufsize = mtd->writesize;
 
        /* Unlock whole block */
-       this->unlock_all(mtd);
+       if (!(this->options & ONENAND_SKIP_INITIAL_UNLOCKING))
+               this->unlock_all(mtd);
 
        ret = this->scan_bbt(mtd);
        if ((!FLEXONENAND(this)) || ret)
@@ -4105,12 +4142,8 @@ void onenand_release(struct mtd_info *mtd)
 {
        struct onenand_chip *this = mtd->priv;
 
-#ifdef CONFIG_MTD_PARTITIONS
        /* Deregister partitions */
-       del_mtd_partitions (mtd);
-#endif
-       /* Deregister the device */
-       del_mtd_device (mtd);
+       mtd_device_unregister(mtd);
 
        /* Free bad block table memory, if allocated */
        if (this->bbm) {