aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/nand_base.c
diff options
context:
space:
mode:
authorHuang Shijie <b32955@freescale.com>2012-11-19 01:43:29 -0500
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-12-03 09:36:51 -0500
commitb0bb6903c8fca2d5ebef1f8ae63d420eb931bb1e (patch)
tree02befc88e37c78c80e7a7efbfe4fc402a4735b11 /drivers/mtd/nand/nand_base.c
parent98a9e2450667e497246449f96eab06eb3fb4d24b (diff)
mtd: remove the de-select chip code in nand_release_device()
The nand_get_device() does not select the chip, but nand_release_device() does de-select the chip. It is really strange. With the current code, nand_sync() will de-select the chip, even if the chip has never been selected. To make the balance of select/de-select chip, it's better to remove the de-select chip code in nand_release_device() which makes the code more clear. Signed-off-by: Huang Shijie <b32955@freescale.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd/nand/nand_base.c')
-rw-r--r--drivers/mtd/nand/nand_base.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 6eef7fbe8fdb..861a87d4d16b 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -130,15 +130,12 @@ static int check_offs_len(struct mtd_info *mtd,
130 * nand_release_device - [GENERIC] release chip 130 * nand_release_device - [GENERIC] release chip
131 * @mtd: MTD device structure 131 * @mtd: MTD device structure
132 * 132 *
133 * Deselect, release chip lock and wake up anyone waiting on the device. 133 * Release chip lock and wake up anyone waiting on the device.
134 */ 134 */
135static void nand_release_device(struct mtd_info *mtd) 135static void nand_release_device(struct mtd_info *mtd)
136{ 136{
137 struct nand_chip *chip = mtd->priv; 137 struct nand_chip *chip = mtd->priv;
138 138
139 /* De-select the NAND device */
140 chip->select_chip(mtd, -1);
141
142 /* Release the controller and the chip */ 139 /* Release the controller and the chip */
143 spin_lock(&chip->controller->lock); 140 spin_lock(&chip->controller->lock);
144 chip->controller->active = NULL; 141 chip->controller->active = NULL;
@@ -333,8 +330,10 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
333 i++; 330 i++;
334 } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE)); 331 } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE));
335 332
336 if (getchip) 333 if (getchip) {
334 chip->select_chip(mtd, -1);
337 nand_release_device(mtd); 335 nand_release_device(mtd);
336 }
338 337
339 return res; 338 return res;
340} 339}
@@ -952,6 +951,7 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
952 ret = __nand_unlock(mtd, ofs, len, 0); 951 ret = __nand_unlock(mtd, ofs, len, 0);
953 952
954out: 953out:
954 chip->select_chip(mtd, -1);
955 nand_release_device(mtd); 955 nand_release_device(mtd);
956 956
957 return ret; 957 return ret;
@@ -1016,6 +1016,7 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1016 ret = __nand_unlock(mtd, ofs, len, 0x1); 1016 ret = __nand_unlock(mtd, ofs, len, 0x1);
1017 1017
1018out: 1018out:
1019 chip->select_chip(mtd, -1);
1019 nand_release_device(mtd); 1020 nand_release_device(mtd);
1020 1021
1021 return ret; 1022 return ret;
@@ -1552,6 +1553,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1552 chip->select_chip(mtd, chipnr); 1553 chip->select_chip(mtd, chipnr);
1553 } 1554 }
1554 } 1555 }
1556 chip->select_chip(mtd, -1);
1555 1557
1556 ops->retlen = ops->len - (size_t) readlen; 1558 ops->retlen = ops->len - (size_t) readlen;
1557 if (oob) 1559 if (oob)
@@ -1806,6 +1808,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1806 chip->select_chip(mtd, chipnr); 1808 chip->select_chip(mtd, chipnr);
1807 } 1809 }
1808 } 1810 }
1811 chip->select_chip(mtd, -1);
1809 1812
1810 ops->oobretlen = ops->ooblen - readlen; 1813 ops->oobretlen = ops->ooblen - readlen;
1811 1814
@@ -2188,8 +2191,10 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2188 chip->select_chip(mtd, chipnr); 2191 chip->select_chip(mtd, chipnr);
2189 2192
2190 /* Check, if it is write protected */ 2193 /* Check, if it is write protected */
2191 if (nand_check_wp(mtd)) 2194 if (nand_check_wp(mtd)) {
2192 return -EIO; 2195 ret = -EIO;
2196 goto err_out;
2197 }
2193 2198
2194 realpage = (int)(to >> chip->page_shift); 2199 realpage = (int)(to >> chip->page_shift);
2195 page = realpage & chip->pagemask; 2200 page = realpage & chip->pagemask;
@@ -2201,8 +2206,10 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2201 chip->pagebuf = -1; 2206 chip->pagebuf = -1;
2202 2207
2203 /* Don't allow multipage oob writes with offset */ 2208 /* Don't allow multipage oob writes with offset */
2204 if (oob && ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen)) 2209 if (oob && ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen)) {
2205 return -EINVAL; 2210 ret = -EINVAL;
2211 goto err_out;
2212 }
2206 2213
2207 while (1) { 2214 while (1) {
2208 int bytes = mtd->writesize; 2215 int bytes = mtd->writesize;
@@ -2253,6 +2260,9 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2253 ops->retlen = ops->len - writelen; 2260 ops->retlen = ops->len - writelen;
2254 if (unlikely(oob)) 2261 if (unlikely(oob))
2255 ops->oobretlen = ops->ooblen; 2262 ops->oobretlen = ops->ooblen;
2263
2264err_out:
2265 chip->select_chip(mtd, -1);
2256 return ret; 2266 return ret;
2257} 2267}
2258 2268
@@ -2379,8 +2389,10 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
2379 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 2389 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
2380 2390
2381 /* Check, if it is write protected */ 2391 /* Check, if it is write protected */
2382 if (nand_check_wp(mtd)) 2392 if (nand_check_wp(mtd)) {
2393 chip->select_chip(mtd, -1);
2383 return -EROFS; 2394 return -EROFS;
2395 }
2384 2396
2385 /* Invalidate the page cache, if we write to the cached page */ 2397 /* Invalidate the page cache, if we write to the cached page */
2386 if (page == chip->pagebuf) 2398 if (page == chip->pagebuf)
@@ -2393,6 +2405,8 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
2393 else 2405 else
2394 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); 2406 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask);
2395 2407
2408 chip->select_chip(mtd, -1);
2409
2396 if (status) 2410 if (status)
2397 return status; 2411 return status;
2398 2412
@@ -2625,6 +2639,7 @@ erase_exit:
2625 ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO; 2639 ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;
2626 2640
2627 /* Deselect and wake up anyone waiting on the device */ 2641 /* Deselect and wake up anyone waiting on the device */
2642 chip->select_chip(mtd, -1);
2628 nand_release_device(mtd); 2643 nand_release_device(mtd);
2629 2644
2630 /* Do call back function */ 2645 /* Do call back function */