diff options
Diffstat (limited to 'drivers/mtd/nand/nand_base.c')
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 114 |
1 files changed, 65 insertions, 49 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 1a03b7f673ce..8323ac991ad1 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -93,8 +93,7 @@ static struct nand_ecclayout nand_oob_128 = { | |||
93 | .length = 78} } | 93 | .length = 78} } |
94 | }; | 94 | }; |
95 | 95 | ||
96 | static int nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, | 96 | static int nand_get_device(struct mtd_info *mtd, int new_state); |
97 | int new_state); | ||
98 | 97 | ||
99 | static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, | 98 | static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, |
100 | struct mtd_oob_ops *ops); | 99 | struct mtd_oob_ops *ops); |
@@ -130,15 +129,12 @@ static int check_offs_len(struct mtd_info *mtd, | |||
130 | * nand_release_device - [GENERIC] release chip | 129 | * nand_release_device - [GENERIC] release chip |
131 | * @mtd: MTD device structure | 130 | * @mtd: MTD device structure |
132 | * | 131 | * |
133 | * Deselect, release chip lock and wake up anyone waiting on the device. | 132 | * Release chip lock and wake up anyone waiting on the device. |
134 | */ | 133 | */ |
135 | static void nand_release_device(struct mtd_info *mtd) | 134 | static void nand_release_device(struct mtd_info *mtd) |
136 | { | 135 | { |
137 | struct nand_chip *chip = mtd->priv; | 136 | struct nand_chip *chip = mtd->priv; |
138 | 137 | ||
139 | /* De-select the NAND device */ | ||
140 | chip->select_chip(mtd, -1); | ||
141 | |||
142 | /* Release the controller and the chip */ | 138 | /* Release the controller and the chip */ |
143 | spin_lock(&chip->controller->lock); | 139 | spin_lock(&chip->controller->lock); |
144 | chip->controller->active = NULL; | 140 | chip->controller->active = NULL; |
@@ -160,7 +156,7 @@ static uint8_t nand_read_byte(struct mtd_info *mtd) | |||
160 | } | 156 | } |
161 | 157 | ||
162 | /** | 158 | /** |
163 | * nand_read_byte16 - [DEFAULT] read one byte endianess aware from the chip | 159 | * nand_read_byte16 - [DEFAULT] read one byte endianness aware from the chip |
164 | * nand_read_byte16 - [DEFAULT] read one byte endianness aware from the chip | 160 | * nand_read_byte16 - [DEFAULT] read one byte endianness aware from the chip |
165 | * @mtd: MTD device structure | 161 | * @mtd: MTD device structure |
166 | * | 162 | * |
@@ -303,7 +299,7 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) | |||
303 | if (getchip) { | 299 | if (getchip) { |
304 | chipnr = (int)(ofs >> chip->chip_shift); | 300 | chipnr = (int)(ofs >> chip->chip_shift); |
305 | 301 | ||
306 | nand_get_device(chip, mtd, FL_READING); | 302 | nand_get_device(mtd, FL_READING); |
307 | 303 | ||
308 | /* Select the NAND device */ | 304 | /* Select the NAND device */ |
309 | chip->select_chip(mtd, chipnr); | 305 | chip->select_chip(mtd, chipnr); |
@@ -333,8 +329,10 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) | |||
333 | i++; | 329 | i++; |
334 | } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE)); | 330 | } while (!res && i < 2 && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE)); |
335 | 331 | ||
336 | if (getchip) | 332 | if (getchip) { |
333 | chip->select_chip(mtd, -1); | ||
337 | nand_release_device(mtd); | 334 | nand_release_device(mtd); |
335 | } | ||
338 | 336 | ||
339 | return res; | 337 | return res; |
340 | } | 338 | } |
@@ -383,7 +381,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) | |||
383 | struct mtd_oob_ops ops; | 381 | struct mtd_oob_ops ops; |
384 | loff_t wr_ofs = ofs; | 382 | loff_t wr_ofs = ofs; |
385 | 383 | ||
386 | nand_get_device(chip, mtd, FL_WRITING); | 384 | nand_get_device(mtd, FL_WRITING); |
387 | 385 | ||
388 | ops.datbuf = NULL; | 386 | ops.datbuf = NULL; |
389 | ops.oobbuf = buf; | 387 | ops.oobbuf = buf; |
@@ -492,7 +490,7 @@ static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo) | |||
492 | void nand_wait_ready(struct mtd_info *mtd) | 490 | void nand_wait_ready(struct mtd_info *mtd) |
493 | { | 491 | { |
494 | struct nand_chip *chip = mtd->priv; | 492 | struct nand_chip *chip = mtd->priv; |
495 | unsigned long timeo = jiffies + 2; | 493 | unsigned long timeo = jiffies + msecs_to_jiffies(20); |
496 | 494 | ||
497 | /* 400ms timeout */ | 495 | /* 400ms timeout */ |
498 | if (in_interrupt() || oops_in_progress) | 496 | if (in_interrupt() || oops_in_progress) |
@@ -750,15 +748,15 @@ static void panic_nand_get_device(struct nand_chip *chip, | |||
750 | 748 | ||
751 | /** | 749 | /** |
752 | * nand_get_device - [GENERIC] Get chip for selected access | 750 | * nand_get_device - [GENERIC] Get chip for selected access |
753 | * @chip: the nand chip descriptor | ||
754 | * @mtd: MTD device structure | 751 | * @mtd: MTD device structure |
755 | * @new_state: the state which is requested | 752 | * @new_state: the state which is requested |
756 | * | 753 | * |
757 | * Get the device and lock it for exclusive access | 754 | * Get the device and lock it for exclusive access |
758 | */ | 755 | */ |
759 | static int | 756 | static int |
760 | nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, int new_state) | 757 | nand_get_device(struct mtd_info *mtd, int new_state) |
761 | { | 758 | { |
759 | struct nand_chip *chip = mtd->priv; | ||
762 | spinlock_t *lock = &chip->controller->lock; | 760 | spinlock_t *lock = &chip->controller->lock; |
763 | wait_queue_head_t *wq = &chip->controller->wq; | 761 | wait_queue_head_t *wq = &chip->controller->wq; |
764 | DECLARE_WAITQUEUE(wait, current); | 762 | DECLARE_WAITQUEUE(wait, current); |
@@ -865,6 +863,8 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) | |||
865 | led_trigger_event(nand_led_trigger, LED_OFF); | 863 | led_trigger_event(nand_led_trigger, LED_OFF); |
866 | 864 | ||
867 | status = (int)chip->read_byte(mtd); | 865 | status = (int)chip->read_byte(mtd); |
866 | /* This can happen if in case of timeout or buggy dev_ready */ | ||
867 | WARN_ON(!(status & NAND_STATUS_READY)); | ||
868 | return status; | 868 | return status; |
869 | } | 869 | } |
870 | 870 | ||
@@ -899,7 +899,7 @@ static int __nand_unlock(struct mtd_info *mtd, loff_t ofs, | |||
899 | /* Call wait ready function */ | 899 | /* Call wait ready function */ |
900 | status = chip->waitfunc(mtd, chip); | 900 | status = chip->waitfunc(mtd, chip); |
901 | /* See if device thinks it succeeded */ | 901 | /* See if device thinks it succeeded */ |
902 | if (status & 0x01) { | 902 | if (status & NAND_STATUS_FAIL) { |
903 | pr_debug("%s: error status = 0x%08x\n", | 903 | pr_debug("%s: error status = 0x%08x\n", |
904 | __func__, status); | 904 | __func__, status); |
905 | ret = -EIO; | 905 | ret = -EIO; |
@@ -932,7 +932,7 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
932 | if (ofs + len == mtd->size) | 932 | if (ofs + len == mtd->size) |
933 | len -= mtd->erasesize; | 933 | len -= mtd->erasesize; |
934 | 934 | ||
935 | nand_get_device(chip, mtd, FL_UNLOCKING); | 935 | nand_get_device(mtd, FL_UNLOCKING); |
936 | 936 | ||
937 | /* Shift to get chip number */ | 937 | /* Shift to get chip number */ |
938 | chipnr = ofs >> chip->chip_shift; | 938 | chipnr = ofs >> chip->chip_shift; |
@@ -950,6 +950,7 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
950 | ret = __nand_unlock(mtd, ofs, len, 0); | 950 | ret = __nand_unlock(mtd, ofs, len, 0); |
951 | 951 | ||
952 | out: | 952 | out: |
953 | chip->select_chip(mtd, -1); | ||
953 | nand_release_device(mtd); | 954 | nand_release_device(mtd); |
954 | 955 | ||
955 | return ret; | 956 | return ret; |
@@ -981,7 +982,7 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
981 | if (check_offs_len(mtd, ofs, len)) | 982 | if (check_offs_len(mtd, ofs, len)) |
982 | ret = -EINVAL; | 983 | ret = -EINVAL; |
983 | 984 | ||
984 | nand_get_device(chip, mtd, FL_LOCKING); | 985 | nand_get_device(mtd, FL_LOCKING); |
985 | 986 | ||
986 | /* Shift to get chip number */ | 987 | /* Shift to get chip number */ |
987 | chipnr = ofs >> chip->chip_shift; | 988 | chipnr = ofs >> chip->chip_shift; |
@@ -1004,7 +1005,7 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
1004 | /* Call wait ready function */ | 1005 | /* Call wait ready function */ |
1005 | status = chip->waitfunc(mtd, chip); | 1006 | status = chip->waitfunc(mtd, chip); |
1006 | /* See if device thinks it succeeded */ | 1007 | /* See if device thinks it succeeded */ |
1007 | if (status & 0x01) { | 1008 | if (status & NAND_STATUS_FAIL) { |
1008 | pr_debug("%s: error status = 0x%08x\n", | 1009 | pr_debug("%s: error status = 0x%08x\n", |
1009 | __func__, status); | 1010 | __func__, status); |
1010 | ret = -EIO; | 1011 | ret = -EIO; |
@@ -1014,6 +1015,7 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | |||
1014 | ret = __nand_unlock(mtd, ofs, len, 0x1); | 1015 | ret = __nand_unlock(mtd, ofs, len, 0x1); |
1015 | 1016 | ||
1016 | out: | 1017 | out: |
1018 | chip->select_chip(mtd, -1); | ||
1017 | nand_release_device(mtd); | 1019 | nand_release_device(mtd); |
1018 | 1020 | ||
1019 | return ret; | 1021 | return ret; |
@@ -1550,6 +1552,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
1550 | chip->select_chip(mtd, chipnr); | 1552 | chip->select_chip(mtd, chipnr); |
1551 | } | 1553 | } |
1552 | } | 1554 | } |
1555 | chip->select_chip(mtd, -1); | ||
1553 | 1556 | ||
1554 | ops->retlen = ops->len - (size_t) readlen; | 1557 | ops->retlen = ops->len - (size_t) readlen; |
1555 | if (oob) | 1558 | if (oob) |
@@ -1577,11 +1580,10 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
1577 | static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, | 1580 | static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, |
1578 | size_t *retlen, uint8_t *buf) | 1581 | size_t *retlen, uint8_t *buf) |
1579 | { | 1582 | { |
1580 | struct nand_chip *chip = mtd->priv; | ||
1581 | struct mtd_oob_ops ops; | 1583 | struct mtd_oob_ops ops; |
1582 | int ret; | 1584 | int ret; |
1583 | 1585 | ||
1584 | nand_get_device(chip, mtd, FL_READING); | 1586 | nand_get_device(mtd, FL_READING); |
1585 | ops.len = len; | 1587 | ops.len = len; |
1586 | ops.datbuf = buf; | 1588 | ops.datbuf = buf; |
1587 | ops.oobbuf = NULL; | 1589 | ops.oobbuf = NULL; |
@@ -1804,6 +1806,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, | |||
1804 | chip->select_chip(mtd, chipnr); | 1806 | chip->select_chip(mtd, chipnr); |
1805 | } | 1807 | } |
1806 | } | 1808 | } |
1809 | chip->select_chip(mtd, -1); | ||
1807 | 1810 | ||
1808 | ops->oobretlen = ops->ooblen - readlen; | 1811 | ops->oobretlen = ops->ooblen - readlen; |
1809 | 1812 | ||
@@ -1827,7 +1830,6 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, | |||
1827 | static int nand_read_oob(struct mtd_info *mtd, loff_t from, | 1830 | static int nand_read_oob(struct mtd_info *mtd, loff_t from, |
1828 | struct mtd_oob_ops *ops) | 1831 | struct mtd_oob_ops *ops) |
1829 | { | 1832 | { |
1830 | struct nand_chip *chip = mtd->priv; | ||
1831 | int ret = -ENOTSUPP; | 1833 | int ret = -ENOTSUPP; |
1832 | 1834 | ||
1833 | ops->retlen = 0; | 1835 | ops->retlen = 0; |
@@ -1839,7 +1841,7 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, | |||
1839 | return -EINVAL; | 1841 | return -EINVAL; |
1840 | } | 1842 | } |
1841 | 1843 | ||
1842 | nand_get_device(chip, mtd, FL_READING); | 1844 | nand_get_device(mtd, FL_READING); |
1843 | 1845 | ||
1844 | switch (ops->mode) { | 1846 | switch (ops->mode) { |
1845 | case MTD_OPS_PLACE_OOB: | 1847 | case MTD_OPS_PLACE_OOB: |
@@ -2186,8 +2188,10 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | |||
2186 | chip->select_chip(mtd, chipnr); | 2188 | chip->select_chip(mtd, chipnr); |
2187 | 2189 | ||
2188 | /* Check, if it is write protected */ | 2190 | /* Check, if it is write protected */ |
2189 | if (nand_check_wp(mtd)) | 2191 | if (nand_check_wp(mtd)) { |
2190 | return -EIO; | 2192 | ret = -EIO; |
2193 | goto err_out; | ||
2194 | } | ||
2191 | 2195 | ||
2192 | realpage = (int)(to >> chip->page_shift); | 2196 | realpage = (int)(to >> chip->page_shift); |
2193 | page = realpage & chip->pagemask; | 2197 | page = realpage & chip->pagemask; |
@@ -2199,8 +2203,10 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | |||
2199 | chip->pagebuf = -1; | 2203 | chip->pagebuf = -1; |
2200 | 2204 | ||
2201 | /* Don't allow multipage oob writes with offset */ | 2205 | /* Don't allow multipage oob writes with offset */ |
2202 | if (oob && ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen)) | 2206 | if (oob && ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen)) { |
2203 | return -EINVAL; | 2207 | ret = -EINVAL; |
2208 | goto err_out; | ||
2209 | } | ||
2204 | 2210 | ||
2205 | while (1) { | 2211 | while (1) { |
2206 | int bytes = mtd->writesize; | 2212 | int bytes = mtd->writesize; |
@@ -2251,6 +2257,9 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | |||
2251 | ops->retlen = ops->len - writelen; | 2257 | ops->retlen = ops->len - writelen; |
2252 | if (unlikely(oob)) | 2258 | if (unlikely(oob)) |
2253 | ops->oobretlen = ops->ooblen; | 2259 | ops->oobretlen = ops->ooblen; |
2260 | |||
2261 | err_out: | ||
2262 | chip->select_chip(mtd, -1); | ||
2254 | return ret; | 2263 | return ret; |
2255 | } | 2264 | } |
2256 | 2265 | ||
@@ -2302,11 +2311,10 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
2302 | static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, | 2311 | static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, |
2303 | size_t *retlen, const uint8_t *buf) | 2312 | size_t *retlen, const uint8_t *buf) |
2304 | { | 2313 | { |
2305 | struct nand_chip *chip = mtd->priv; | ||
2306 | struct mtd_oob_ops ops; | 2314 | struct mtd_oob_ops ops; |
2307 | int ret; | 2315 | int ret; |
2308 | 2316 | ||
2309 | nand_get_device(chip, mtd, FL_WRITING); | 2317 | nand_get_device(mtd, FL_WRITING); |
2310 | ops.len = len; | 2318 | ops.len = len; |
2311 | ops.datbuf = (uint8_t *)buf; | 2319 | ops.datbuf = (uint8_t *)buf; |
2312 | ops.oobbuf = NULL; | 2320 | ops.oobbuf = NULL; |
@@ -2377,8 +2385,10 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, | |||
2377 | chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); | 2385 | chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); |
2378 | 2386 | ||
2379 | /* Check, if it is write protected */ | 2387 | /* Check, if it is write protected */ |
2380 | if (nand_check_wp(mtd)) | 2388 | if (nand_check_wp(mtd)) { |
2389 | chip->select_chip(mtd, -1); | ||
2381 | return -EROFS; | 2390 | return -EROFS; |
2391 | } | ||
2382 | 2392 | ||
2383 | /* Invalidate the page cache, if we write to the cached page */ | 2393 | /* Invalidate the page cache, if we write to the cached page */ |
2384 | if (page == chip->pagebuf) | 2394 | if (page == chip->pagebuf) |
@@ -2391,6 +2401,8 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, | |||
2391 | else | 2401 | else |
2392 | status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); | 2402 | status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); |
2393 | 2403 | ||
2404 | chip->select_chip(mtd, -1); | ||
2405 | |||
2394 | if (status) | 2406 | if (status) |
2395 | return status; | 2407 | return status; |
2396 | 2408 | ||
@@ -2408,7 +2420,6 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, | |||
2408 | static int nand_write_oob(struct mtd_info *mtd, loff_t to, | 2420 | static int nand_write_oob(struct mtd_info *mtd, loff_t to, |
2409 | struct mtd_oob_ops *ops) | 2421 | struct mtd_oob_ops *ops) |
2410 | { | 2422 | { |
2411 | struct nand_chip *chip = mtd->priv; | ||
2412 | int ret = -ENOTSUPP; | 2423 | int ret = -ENOTSUPP; |
2413 | 2424 | ||
2414 | ops->retlen = 0; | 2425 | ops->retlen = 0; |
@@ -2420,7 +2431,7 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, | |||
2420 | return -EINVAL; | 2431 | return -EINVAL; |
2421 | } | 2432 | } |
2422 | 2433 | ||
2423 | nand_get_device(chip, mtd, FL_WRITING); | 2434 | nand_get_device(mtd, FL_WRITING); |
2424 | 2435 | ||
2425 | switch (ops->mode) { | 2436 | switch (ops->mode) { |
2426 | case MTD_OPS_PLACE_OOB: | 2437 | case MTD_OPS_PLACE_OOB: |
@@ -2513,7 +2524,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | |||
2513 | return -EINVAL; | 2524 | return -EINVAL; |
2514 | 2525 | ||
2515 | /* Grab the lock and see if the device is available */ | 2526 | /* Grab the lock and see if the device is available */ |
2516 | nand_get_device(chip, mtd, FL_ERASING); | 2527 | nand_get_device(mtd, FL_ERASING); |
2517 | 2528 | ||
2518 | /* Shift to get first page */ | 2529 | /* Shift to get first page */ |
2519 | page = (int)(instr->addr >> chip->page_shift); | 2530 | page = (int)(instr->addr >> chip->page_shift); |
@@ -2623,6 +2634,7 @@ erase_exit: | |||
2623 | ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO; | 2634 | ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO; |
2624 | 2635 | ||
2625 | /* Deselect and wake up anyone waiting on the device */ | 2636 | /* Deselect and wake up anyone waiting on the device */ |
2637 | chip->select_chip(mtd, -1); | ||
2626 | nand_release_device(mtd); | 2638 | nand_release_device(mtd); |
2627 | 2639 | ||
2628 | /* Do call back function */ | 2640 | /* Do call back function */ |
@@ -2658,12 +2670,10 @@ erase_exit: | |||
2658 | */ | 2670 | */ |
2659 | static void nand_sync(struct mtd_info *mtd) | 2671 | static void nand_sync(struct mtd_info *mtd) |
2660 | { | 2672 | { |
2661 | struct nand_chip *chip = mtd->priv; | ||
2662 | |||
2663 | pr_debug("%s: called\n", __func__); | 2673 | pr_debug("%s: called\n", __func__); |
2664 | 2674 | ||
2665 | /* Grab the lock and see if the device is available */ | 2675 | /* Grab the lock and see if the device is available */ |
2666 | nand_get_device(chip, mtd, FL_SYNCING); | 2676 | nand_get_device(mtd, FL_SYNCING); |
2667 | /* Release it and go back */ | 2677 | /* Release it and go back */ |
2668 | nand_release_device(mtd); | 2678 | nand_release_device(mtd); |
2669 | } | 2679 | } |
@@ -2749,9 +2759,7 @@ static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip, | |||
2749 | */ | 2759 | */ |
2750 | static int nand_suspend(struct mtd_info *mtd) | 2760 | static int nand_suspend(struct mtd_info *mtd) |
2751 | { | 2761 | { |
2752 | struct nand_chip *chip = mtd->priv; | 2762 | return nand_get_device(mtd, FL_PM_SUSPENDED); |
2753 | |||
2754 | return nand_get_device(chip, mtd, FL_PM_SUSPENDED); | ||
2755 | } | 2763 | } |
2756 | 2764 | ||
2757 | /** | 2765 | /** |
@@ -2849,6 +2857,8 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |||
2849 | int i; | 2857 | int i; |
2850 | int val; | 2858 | int val; |
2851 | 2859 | ||
2860 | /* ONFI need to be probed in 8 bits mode */ | ||
2861 | WARN_ON(chip->options & NAND_BUSWIDTH_16); | ||
2852 | /* Try ONFI for unknown chip or LP */ | 2862 | /* Try ONFI for unknown chip or LP */ |
2853 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x20, -1); | 2863 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x20, -1); |
2854 | if (chip->read_byte(mtd) != 'O' || chip->read_byte(mtd) != 'N' || | 2864 | if (chip->read_byte(mtd) != 'O' || chip->read_byte(mtd) != 'N' || |
@@ -2913,7 +2923,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |||
2913 | * | 2923 | * |
2914 | * Check if an ID string is repeated within a given sequence of bytes at | 2924 | * Check if an ID string is repeated within a given sequence of bytes at |
2915 | * specific repetition interval period (e.g., {0x20,0x01,0x7F,0x20} has a | 2925 | * specific repetition interval period (e.g., {0x20,0x01,0x7F,0x20} has a |
2916 | * period of 2). This is a helper function for nand_id_len(). Returns non-zero | 2926 | * period of 3). This is a helper function for nand_id_len(). Returns non-zero |
2917 | * if the repetition has a period of @period; otherwise, returns zero. | 2927 | * if the repetition has a period of @period; otherwise, returns zero. |
2918 | */ | 2928 | */ |
2919 | static int nand_id_has_period(u8 *id_data, int arrlen, int period) | 2929 | static int nand_id_has_period(u8 *id_data, int arrlen, int period) |
@@ -3242,11 +3252,15 @@ ident_done: | |||
3242 | break; | 3252 | break; |
3243 | } | 3253 | } |
3244 | 3254 | ||
3245 | /* | 3255 | if (chip->options & NAND_BUSWIDTH_AUTO) { |
3246 | * Check, if buswidth is correct. Hardware drivers should set | 3256 | WARN_ON(chip->options & NAND_BUSWIDTH_16); |
3247 | * chip correct! | 3257 | chip->options |= busw; |
3248 | */ | 3258 | nand_set_defaults(chip, busw); |
3249 | if (busw != (chip->options & NAND_BUSWIDTH_16)) { | 3259 | } else if (busw != (chip->options & NAND_BUSWIDTH_16)) { |
3260 | /* | ||
3261 | * Check, if buswidth is correct. Hardware drivers should set | ||
3262 | * chip correct! | ||
3263 | */ | ||
3250 | pr_info("NAND device: Manufacturer ID:" | 3264 | pr_info("NAND device: Manufacturer ID:" |
3251 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id, | 3265 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id, |
3252 | *dev_id, nand_manuf_ids[maf_idx].name, mtd->name); | 3266 | *dev_id, nand_manuf_ids[maf_idx].name, mtd->name); |
@@ -3285,10 +3299,10 @@ ident_done: | |||
3285 | chip->cmdfunc = nand_command_lp; | 3299 | chip->cmdfunc = nand_command_lp; |
3286 | 3300 | ||
3287 | pr_info("NAND device: Manufacturer ID: 0x%02x, Chip ID: 0x%02x (%s %s)," | 3301 | pr_info("NAND device: Manufacturer ID: 0x%02x, Chip ID: 0x%02x (%s %s)," |
3288 | " page size: %d, OOB size: %d\n", | 3302 | " %dMiB, page size: %d, OOB size: %d\n", |
3289 | *maf_id, *dev_id, nand_manuf_ids[maf_idx].name, | 3303 | *maf_id, *dev_id, nand_manuf_ids[maf_idx].name, |
3290 | chip->onfi_version ? chip->onfi_params.model : type->name, | 3304 | chip->onfi_version ? chip->onfi_params.model : type->name, |
3291 | mtd->writesize, mtd->oobsize); | 3305 | (int)(chip->chipsize >> 20), mtd->writesize, mtd->oobsize); |
3292 | 3306 | ||
3293 | return type; | 3307 | return type; |
3294 | } | 3308 | } |
@@ -3327,6 +3341,8 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, | |||
3327 | return PTR_ERR(type); | 3341 | return PTR_ERR(type); |
3328 | } | 3342 | } |
3329 | 3343 | ||
3344 | chip->select_chip(mtd, -1); | ||
3345 | |||
3330 | /* Check for a chip array */ | 3346 | /* Check for a chip array */ |
3331 | for (i = 1; i < maxchips; i++) { | 3347 | for (i = 1; i < maxchips; i++) { |
3332 | chip->select_chip(mtd, i); | 3348 | chip->select_chip(mtd, i); |
@@ -3336,8 +3352,11 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, | |||
3336 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); | 3352 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); |
3337 | /* Read manufacturer and device IDs */ | 3353 | /* Read manufacturer and device IDs */ |
3338 | if (nand_maf_id != chip->read_byte(mtd) || | 3354 | if (nand_maf_id != chip->read_byte(mtd) || |
3339 | nand_dev_id != chip->read_byte(mtd)) | 3355 | nand_dev_id != chip->read_byte(mtd)) { |
3356 | chip->select_chip(mtd, -1); | ||
3340 | break; | 3357 | break; |
3358 | } | ||
3359 | chip->select_chip(mtd, -1); | ||
3341 | } | 3360 | } |
3342 | if (i > 1) | 3361 | if (i > 1) |
3343 | pr_info("%d NAND chips detected\n", i); | 3362 | pr_info("%d NAND chips detected\n", i); |
@@ -3596,9 +3615,6 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3596 | /* Initialize state */ | 3615 | /* Initialize state */ |
3597 | chip->state = FL_READY; | 3616 | chip->state = FL_READY; |
3598 | 3617 | ||
3599 | /* De-select the device */ | ||
3600 | chip->select_chip(mtd, -1); | ||
3601 | |||
3602 | /* Invalidate the pagebuffer reference */ | 3618 | /* Invalidate the pagebuffer reference */ |
3603 | chip->pagebuf = -1; | 3619 | chip->pagebuf = -1; |
3604 | 3620 | ||