Merge branch 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / drivers / mtd / nand / nand_base.c
index 596a9b0503dafcf581041d0fa988ebbc97a9f3c4..557b8462f55ed6f46961d2201affedd2c2746401 100644 (file)
@@ -313,13 +313,12 @@ static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
  * nand_block_bad - [DEFAULT] Read bad block marker from the chip
  * @mtd: MTD device structure
  * @ofs: offset from device start
- * @getchip: 0, if the chip is already selected
  *
  * Check, if the block is bad.
  */
-static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
+static int nand_block_bad(struct mtd_info *mtd, loff_t ofs)
 {
-       int page, chipnr, res = 0, i = 0;
+       int page, res = 0, i = 0;
        struct nand_chip *chip = mtd_to_nand(mtd);
        u16 bad;
 
@@ -328,15 +327,6 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
 
        page = (int)(ofs >> chip->page_shift) & chip->pagemask;
 
-       if (getchip) {
-               chipnr = (int)(ofs >> chip->chip_shift);
-
-               nand_get_device(mtd, FL_READING);
-
-               /* Select the NAND device */
-               chip->select_chip(mtd, chipnr);
-       }
-
        do {
                if (chip->options & NAND_BUSWIDTH_16) {
                        chip->cmdfunc(mtd, NAND_CMD_READOOB,
@@ -361,11 +351,6 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
                i++;
        } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE));
 
-       if (getchip) {
-               chip->select_chip(mtd, -1);
-               nand_release_device(mtd);
-       }
-
        return res;
 }
 
@@ -503,19 +488,17 @@ static int nand_block_isreserved(struct mtd_info *mtd, loff_t ofs)
  * nand_block_checkbad - [GENERIC] Check if a block is marked bad
  * @mtd: MTD device structure
  * @ofs: offset from device start
- * @getchip: 0, if the chip is already selected
  * @allowbbt: 1, if its allowed to access the bbt area
  *
  * Check, if the block is bad. Either by reading the bad block table or
  * calling of the scan function.
  */
-static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
-                              int allowbbt)
+static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int allowbbt)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (!chip->bbt)
-               return chip->block_bad(mtd, ofs, getchip);
+               return chip->block_bad(mtd, ofs);
 
        /* Return info from the table */
        return nand_isbad_bbt(mtd, ofs, allowbbt);
@@ -1723,8 +1706,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
        int ret = 0;
        uint32_t readlen = ops->len;
        uint32_t oobreadlen = ops->ooblen;
-       uint32_t max_oobsize = ops->mode == MTD_OPS_AUTO_OOB ?
-               mtd->oobavail : mtd->oobsize;
+       uint32_t max_oobsize = mtd_oobavail(mtd, ops);
 
        uint8_t *bufpoi, *oob, *buf;
        int use_bufpoi;
@@ -2075,10 +2057,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
 
        stats = mtd->ecc_stats;
 
-       if (ops->mode == MTD_OPS_AUTO_OOB)
-               len = chip->ecc.layout->oobavail;
-       else
-               len = mtd->oobsize;
+       len = mtd_oobavail(mtd, ops);
 
        if (unlikely(ops->ooboffs >= len)) {
                pr_debug("%s: attempt to start read outside oob\n",
@@ -2575,8 +2554,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
        uint32_t writelen = ops->len;
 
        uint32_t oobwritelen = ops->ooblen;
-       uint32_t oobmaxlen = ops->mode == MTD_OPS_AUTO_OOB ?
-                               mtd->oobavail : mtd->oobsize;
+       uint32_t oobmaxlen = mtd_oobavail(mtd, ops);
 
        uint8_t *oob = ops->oobbuf;
        uint8_t *buf = ops->datbuf;
@@ -2766,10 +2744,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
        pr_debug("%s: to = 0x%08x, len = %i\n",
                         __func__, (unsigned int)to, (int)ops->ooblen);
 
-       if (ops->mode == MTD_OPS_AUTO_OOB)
-               len = chip->ecc.layout->oobavail;
-       else
-               len = mtd->oobsize;
+       len = mtd_oobavail(mtd, ops);
 
        /* Do not allow write past end of page */
        if ((ops->ooboffs + ops->ooblen) > len) {
@@ -2957,7 +2932,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
        while (len) {
                /* Check if we have a bad block, we do not erase bad blocks! */
                if (nand_block_checkbad(mtd, ((loff_t) page) <<
-                                       chip->page_shift, 0, allowbbt)) {
+                                       chip->page_shift, allowbbt)) {
                        pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
                                    __func__, page);
                        instr->state = MTD_ERASE_FAILED;
@@ -3044,7 +3019,20 @@ static void nand_sync(struct mtd_info *mtd)
  */
 static int nand_block_isbad(struct mtd_info *mtd, loff_t offs)
 {
-       return nand_block_checkbad(mtd, offs, 1, 0);
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       int chipnr = (int)(offs >> chip->chip_shift);
+       int ret;
+
+       /* Select the NAND device */
+       nand_get_device(mtd, FL_READING);
+       chip->select_chip(mtd, chipnr);
+
+       ret = nand_block_checkbad(mtd, offs, 0);
+
+       chip->select_chip(mtd, -1);
+       nand_release_device(mtd);
+
+       return ret;
 }
 
 /**
@@ -4021,7 +4009,6 @@ static int nand_dt_init(struct nand_chip *chip)
  * This is the first phase of the normal nand_scan() function. It reads the
  * flash ID and sets up MTD fields accordingly.
  *
- * The mtd->owner field must be set to the module of the caller.
  */
 int nand_scan_ident(struct mtd_info *mtd, int maxchips,
                    struct nand_flash_dev *table)
@@ -4287,10 +4274,8 @@ int nand_scan_tail(struct mtd_info *mtd)
                }
 
                /* See nand_bch_init() for details. */
-               ecc->bytes = DIV_ROUND_UP(
-                               ecc->strength * fls(8 * ecc->size), 8);
-               ecc->priv = nand_bch_init(mtd, ecc->size, ecc->bytes,
-                                              &ecc->layout);
+               ecc->bytes = 0;
+               ecc->priv = nand_bch_init(mtd);
                if (!ecc->priv) {
                        pr_warn("BCH ECC initialization failed!\n");
                        BUG();
@@ -4325,11 +4310,11 @@ int nand_scan_tail(struct mtd_info *mtd)
         * The number of bytes available for a client to place data into
         * the out of band area.
         */
-       ecc->layout->oobavail = 0;
-       for (i = 0; ecc->layout->oobfree[i].length
-                       && i < ARRAY_SIZE(ecc->layout->oobfree); i++)
-               ecc->layout->oobavail += ecc->layout->oobfree[i].length;
-       mtd->oobavail = ecc->layout->oobavail;
+       mtd->oobavail = 0;
+       if (ecc->layout) {
+               for (i = 0; ecc->layout->oobfree[i].length; i++)
+                       mtd->oobavail += ecc->layout->oobfree[i].length;
+       }
 
        /* ECC sanity check: warn if it's too weak */
        if (!nand_ecc_strength_good(mtd))
@@ -4443,19 +4428,12 @@ EXPORT_SYMBOL(nand_scan_tail);
  *
  * This fills out all the uninitialized function pointers with the defaults.
  * The flash ID is read and the mtd/chip structures are filled with the
- * appropriate values. The mtd->owner field must be set to the module of the
- * caller.
+ * appropriate values.
  */
 int nand_scan(struct mtd_info *mtd, int maxchips)
 {
        int ret;
 
-       /* Many callers got this wrong, so check for it for a while... */
-       if (!mtd->owner && caller_is_module()) {
-               pr_crit("%s called with NULL mtd->owner!\n", __func__);
-               BUG();
-       }
-
        ret = nand_scan_ident(mtd, maxchips, NULL);
        if (!ret)
                ret = nand_scan_tail(mtd);