diff options
author | Linus Torvalds <torvalds@g5.osdl.org> | 2005-11-07 13:24:08 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-11-07 13:24:08 -0500 |
commit | b3ce1debe2685383a9ad6ace9c49869c3968c013 (patch) | |
tree | dcb606fac467d6ce78a9c608a1e0d2323af44f2b /drivers/mtd/nand/nand_base.c | |
parent | 5b2f7ffcb734d3046144dfbd5ac6d76254a9e522 (diff) | |
parent | c2965f1129ee54afcc4ef293ff0f25fa3a7e7392 (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/tglx/mtd-2.6
Some manual fixups for clashing kfree() cleanups etc.
Diffstat (limited to 'drivers/mtd/nand/nand_base.c')
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 529 |
1 files changed, 282 insertions, 247 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 8e78d7b96a56..5d222460b42a 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -5,14 +5,14 @@ | |||
5 | * This is the generic MTD driver for NAND flash devices. It should be | 5 | * This is the generic MTD driver for NAND flash devices. It should be |
6 | * capable of working with almost all NAND chips currently available. | 6 | * capable of working with almost all NAND chips currently available. |
7 | * Basic support for AG-AND chips is provided. | 7 | * Basic support for AG-AND chips is provided. |
8 | * | 8 | * |
9 | * Additional technical information is available on | 9 | * Additional technical information is available on |
10 | * http://www.linux-mtd.infradead.org/tech/nand.html | 10 | * http://www.linux-mtd.infradead.org/tech/nand.html |
11 | * | 11 | * |
12 | * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com) | 12 | * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com) |
13 | * 2002 Thomas Gleixner (tglx@linutronix.de) | 13 | * 2002 Thomas Gleixner (tglx@linutronix.de) |
14 | * | 14 | * |
15 | * 02-08-2004 tglx: support for strange chips, which cannot auto increment | 15 | * 02-08-2004 tglx: support for strange chips, which cannot auto increment |
16 | * pages on read / read_oob | 16 | * pages on read / read_oob |
17 | * | 17 | * |
18 | * 03-17-2004 tglx: Check ready before auto increment check. Simon Bayes | 18 | * 03-17-2004 tglx: Check ready before auto increment check. Simon Bayes |
@@ -21,7 +21,7 @@ | |||
21 | * Make reads over block boundaries work too | 21 | * Make reads over block boundaries work too |
22 | * | 22 | * |
23 | * 04-14-2004 tglx: first working version for 2k page size chips | 23 | * 04-14-2004 tglx: first working version for 2k page size chips |
24 | * | 24 | * |
25 | * 05-19-2004 tglx: Basic support for Renesas AG-AND chips | 25 | * 05-19-2004 tglx: Basic support for Renesas AG-AND chips |
26 | * | 26 | * |
27 | * 09-24-2004 tglx: add support for hardware controllers (e.g. ECC) shared | 27 | * 09-24-2004 tglx: add support for hardware controllers (e.g. ECC) shared |
@@ -30,25 +30,27 @@ | |||
30 | * | 30 | * |
31 | * 12-05-2004 dmarlin: add workaround for Renesas AG-AND chips "disturb" issue. | 31 | * 12-05-2004 dmarlin: add workaround for Renesas AG-AND chips "disturb" issue. |
32 | * Basically, any block not rewritten may lose data when surrounding blocks | 32 | * Basically, any block not rewritten may lose data when surrounding blocks |
33 | * are rewritten many times. JFFS2 ensures this doesn't happen for blocks | 33 | * are rewritten many times. JFFS2 ensures this doesn't happen for blocks |
34 | * it uses, but the Bad Block Table(s) may not be rewritten. To ensure they | 34 | * it uses, but the Bad Block Table(s) may not be rewritten. To ensure they |
35 | * do not lose data, force them to be rewritten when some of the surrounding | 35 | * do not lose data, force them to be rewritten when some of the surrounding |
36 | * blocks are erased. Rather than tracking a specific nearby block (which | 36 | * blocks are erased. Rather than tracking a specific nearby block (which |
37 | * could itself go bad), use a page address 'mask' to select several blocks | 37 | * could itself go bad), use a page address 'mask' to select several blocks |
38 | * in the same area, and rewrite the BBT when any of them are erased. | 38 | * in the same area, and rewrite the BBT when any of them are erased. |
39 | * | 39 | * |
40 | * 01-03-2005 dmarlin: added support for the device recovery command sequence for Renesas | 40 | * 01-03-2005 dmarlin: added support for the device recovery command sequence for Renesas |
41 | * AG-AND chips. If there was a sudden loss of power during an erase operation, | 41 | * AG-AND chips. If there was a sudden loss of power during an erase operation, |
42 | * a "device recovery" operation must be performed when power is restored | 42 | * a "device recovery" operation must be performed when power is restored |
43 | * to ensure correct operation. | 43 | * to ensure correct operation. |
44 | * | 44 | * |
45 | * 01-20-2005 dmarlin: added support for optional hardware specific callback routine to | 45 | * 01-20-2005 dmarlin: added support for optional hardware specific callback routine to |
46 | * perform extra error status checks on erase and write failures. This required | 46 | * perform extra error status checks on erase and write failures. This required |
47 | * adding a wrapper function for nand_read_ecc. | 47 | * adding a wrapper function for nand_read_ecc. |
48 | * | 48 | * |
49 | * 08-20-2005 vwool: suspend/resume added | ||
50 | * | ||
49 | * Credits: | 51 | * Credits: |
50 | * David Woodhouse for adding multichip support | 52 | * David Woodhouse for adding multichip support |
51 | * | 53 | * |
52 | * Aleph One Ltd. and Toby Churchill Ltd. for supporting the | 54 | * Aleph One Ltd. and Toby Churchill Ltd. for supporting the |
53 | * rework for 2K page size chips | 55 | * rework for 2K page size chips |
54 | * | 56 | * |
@@ -59,7 +61,7 @@ | |||
59 | * The AG-AND chips have nice features for speed improvement, | 61 | * The AG-AND chips have nice features for speed improvement, |
60 | * which are not supported yet. Read / program 4 pages in one go. | 62 | * which are not supported yet. Read / program 4 pages in one go. |
61 | * | 63 | * |
62 | * $Id: nand_base.c,v 1.147 2005/07/15 07:18:06 gleixner Exp $ | 64 | * $Id: nand_base.c,v 1.150 2005/09/15 13:58:48 vwool Exp $ |
63 | * | 65 | * |
64 | * This program is free software; you can redistribute it and/or modify | 66 | * This program is free software; you can redistribute it and/or modify |
65 | * it under the terms of the GNU General Public License version 2 as | 67 | * it under the terms of the GNU General Public License version 2 as |
@@ -103,8 +105,8 @@ static struct nand_oobinfo nand_oob_64 = { | |||
103 | .useecc = MTD_NANDECC_AUTOPLACE, | 105 | .useecc = MTD_NANDECC_AUTOPLACE, |
104 | .eccbytes = 24, | 106 | .eccbytes = 24, |
105 | .eccpos = { | 107 | .eccpos = { |
106 | 40, 41, 42, 43, 44, 45, 46, 47, | 108 | 40, 41, 42, 43, 44, 45, 46, 47, |
107 | 48, 49, 50, 51, 52, 53, 54, 55, | 109 | 48, 49, 50, 51, 52, 53, 54, 55, |
108 | 56, 57, 58, 59, 60, 61, 62, 63}, | 110 | 56, 57, 58, 59, 60, 61, 62, 63}, |
109 | .oobfree = { {2, 38} } | 111 | .oobfree = { {2, 38} } |
110 | }; | 112 | }; |
@@ -147,19 +149,19 @@ static void nand_sync (struct mtd_info *mtd); | |||
147 | static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, u_char *oob_buf, | 149 | static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, u_char *oob_buf, |
148 | struct nand_oobinfo *oobsel, int mode); | 150 | struct nand_oobinfo *oobsel, int mode); |
149 | #ifdef CONFIG_MTD_NAND_VERIFY_WRITE | 151 | #ifdef CONFIG_MTD_NAND_VERIFY_WRITE |
150 | static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, | 152 | static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, |
151 | u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode); | 153 | u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode); |
152 | #else | 154 | #else |
153 | #define nand_verify_pages(...) (0) | 155 | #define nand_verify_pages(...) (0) |
154 | #endif | 156 | #endif |
155 | 157 | ||
156 | static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state); | 158 | static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state); |
157 | 159 | ||
158 | /** | 160 | /** |
159 | * nand_release_device - [GENERIC] release chip | 161 | * nand_release_device - [GENERIC] release chip |
160 | * @mtd: MTD device structure | 162 | * @mtd: MTD device structure |
161 | * | 163 | * |
162 | * Deselect, release chip lock and wake up anyone waiting on the device | 164 | * Deselect, release chip lock and wake up anyone waiting on the device |
163 | */ | 165 | */ |
164 | static void nand_release_device (struct mtd_info *mtd) | 166 | static void nand_release_device (struct mtd_info *mtd) |
165 | { | 167 | { |
@@ -213,7 +215,7 @@ static void nand_write_byte(struct mtd_info *mtd, u_char byte) | |||
213 | * nand_read_byte16 - [DEFAULT] read one byte endianess aware from the chip | 215 | * nand_read_byte16 - [DEFAULT] read one byte endianess aware from the chip |
214 | * @mtd: MTD device structure | 216 | * @mtd: MTD device structure |
215 | * | 217 | * |
216 | * Default read function for 16bit buswith with | 218 | * Default read function for 16bit buswith with |
217 | * endianess conversion | 219 | * endianess conversion |
218 | */ | 220 | */ |
219 | static u_char nand_read_byte16(struct mtd_info *mtd) | 221 | static u_char nand_read_byte16(struct mtd_info *mtd) |
@@ -240,7 +242,7 @@ static void nand_write_byte16(struct mtd_info *mtd, u_char byte) | |||
240 | * nand_read_word - [DEFAULT] read one word from the chip | 242 | * nand_read_word - [DEFAULT] read one word from the chip |
241 | * @mtd: MTD device structure | 243 | * @mtd: MTD device structure |
242 | * | 244 | * |
243 | * Default read function for 16bit buswith without | 245 | * Default read function for 16bit buswith without |
244 | * endianess conversion | 246 | * endianess conversion |
245 | */ | 247 | */ |
246 | static u16 nand_read_word(struct mtd_info *mtd) | 248 | static u16 nand_read_word(struct mtd_info *mtd) |
@@ -254,7 +256,7 @@ static u16 nand_read_word(struct mtd_info *mtd) | |||
254 | * @mtd: MTD device structure | 256 | * @mtd: MTD device structure |
255 | * @word: data word to write | 257 | * @word: data word to write |
256 | * | 258 | * |
257 | * Default write function for 16bit buswith without | 259 | * Default write function for 16bit buswith without |
258 | * endianess conversion | 260 | * endianess conversion |
259 | */ | 261 | */ |
260 | static void nand_write_word(struct mtd_info *mtd, u16 word) | 262 | static void nand_write_word(struct mtd_info *mtd, u16 word) |
@@ -275,7 +277,7 @@ static void nand_select_chip(struct mtd_info *mtd, int chip) | |||
275 | struct nand_chip *this = mtd->priv; | 277 | struct nand_chip *this = mtd->priv; |
276 | switch(chip) { | 278 | switch(chip) { |
277 | case -1: | 279 | case -1: |
278 | this->hwcontrol(mtd, NAND_CTL_CLRNCE); | 280 | this->hwcontrol(mtd, NAND_CTL_CLRNCE); |
279 | break; | 281 | break; |
280 | case 0: | 282 | case 0: |
281 | this->hwcontrol(mtd, NAND_CTL_SETNCE); | 283 | this->hwcontrol(mtd, NAND_CTL_SETNCE); |
@@ -304,7 +306,7 @@ static void nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) | |||
304 | } | 306 | } |
305 | 307 | ||
306 | /** | 308 | /** |
307 | * nand_read_buf - [DEFAULT] read chip data into buffer | 309 | * nand_read_buf - [DEFAULT] read chip data into buffer |
308 | * @mtd: MTD device structure | 310 | * @mtd: MTD device structure |
309 | * @buf: buffer to store date | 311 | * @buf: buffer to store date |
310 | * @len: number of bytes to read | 312 | * @len: number of bytes to read |
@@ -321,7 +323,7 @@ static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) | |||
321 | } | 323 | } |
322 | 324 | ||
323 | /** | 325 | /** |
324 | * nand_verify_buf - [DEFAULT] Verify chip data against buffer | 326 | * nand_verify_buf - [DEFAULT] Verify chip data against buffer |
325 | * @mtd: MTD device structure | 327 | * @mtd: MTD device structure |
326 | * @buf: buffer containing the data to compare | 328 | * @buf: buffer containing the data to compare |
327 | * @len: number of bytes to compare | 329 | * @len: number of bytes to compare |
@@ -354,14 +356,14 @@ static void nand_write_buf16(struct mtd_info *mtd, const u_char *buf, int len) | |||
354 | struct nand_chip *this = mtd->priv; | 356 | struct nand_chip *this = mtd->priv; |
355 | u16 *p = (u16 *) buf; | 357 | u16 *p = (u16 *) buf; |
356 | len >>= 1; | 358 | len >>= 1; |
357 | 359 | ||
358 | for (i=0; i<len; i++) | 360 | for (i=0; i<len; i++) |
359 | writew(p[i], this->IO_ADDR_W); | 361 | writew(p[i], this->IO_ADDR_W); |
360 | 362 | ||
361 | } | 363 | } |
362 | 364 | ||
363 | /** | 365 | /** |
364 | * nand_read_buf16 - [DEFAULT] read chip data into buffer | 366 | * nand_read_buf16 - [DEFAULT] read chip data into buffer |
365 | * @mtd: MTD device structure | 367 | * @mtd: MTD device structure |
366 | * @buf: buffer to store date | 368 | * @buf: buffer to store date |
367 | * @len: number of bytes to read | 369 | * @len: number of bytes to read |
@@ -380,7 +382,7 @@ static void nand_read_buf16(struct mtd_info *mtd, u_char *buf, int len) | |||
380 | } | 382 | } |
381 | 383 | ||
382 | /** | 384 | /** |
383 | * nand_verify_buf16 - [DEFAULT] Verify chip data against buffer | 385 | * nand_verify_buf16 - [DEFAULT] Verify chip data against buffer |
384 | * @mtd: MTD device structure | 386 | * @mtd: MTD device structure |
385 | * @buf: buffer containing the data to compare | 387 | * @buf: buffer containing the data to compare |
386 | * @len: number of bytes to compare | 388 | * @len: number of bytes to compare |
@@ -407,7 +409,7 @@ static int nand_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len) | |||
407 | * @ofs: offset from device start | 409 | * @ofs: offset from device start |
408 | * @getchip: 0, if the chip is already selected | 410 | * @getchip: 0, if the chip is already selected |
409 | * | 411 | * |
410 | * Check, if the block is bad. | 412 | * Check, if the block is bad. |
411 | */ | 413 | */ |
412 | static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) | 414 | static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) |
413 | { | 415 | { |
@@ -424,14 +426,14 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) | |||
424 | 426 | ||
425 | /* Select the NAND device */ | 427 | /* Select the NAND device */ |
426 | this->select_chip(mtd, chipnr); | 428 | this->select_chip(mtd, chipnr); |
427 | } else | 429 | } else |
428 | page = (int) ofs; | 430 | page = (int) ofs; |
429 | 431 | ||
430 | if (this->options & NAND_BUSWIDTH_16) { | 432 | if (this->options & NAND_BUSWIDTH_16) { |
431 | this->cmdfunc (mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, page & this->pagemask); | 433 | this->cmdfunc (mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, page & this->pagemask); |
432 | bad = cpu_to_le16(this->read_word(mtd)); | 434 | bad = cpu_to_le16(this->read_word(mtd)); |
433 | if (this->badblockpos & 0x1) | 435 | if (this->badblockpos & 0x1) |
434 | bad >>= 1; | 436 | bad >>= 8; |
435 | if ((bad & 0xFF) != 0xff) | 437 | if ((bad & 0xFF) != 0xff) |
436 | res = 1; | 438 | res = 1; |
437 | } else { | 439 | } else { |
@@ -439,12 +441,12 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) | |||
439 | if (this->read_byte(mtd) != 0xff) | 441 | if (this->read_byte(mtd) != 0xff) |
440 | res = 1; | 442 | res = 1; |
441 | } | 443 | } |
442 | 444 | ||
443 | if (getchip) { | 445 | if (getchip) { |
444 | /* Deselect and wake up anyone waiting on the device */ | 446 | /* Deselect and wake up anyone waiting on the device */ |
445 | nand_release_device(mtd); | 447 | nand_release_device(mtd); |
446 | } | 448 | } |
447 | 449 | ||
448 | return res; | 450 | return res; |
449 | } | 451 | } |
450 | 452 | ||
@@ -462,7 +464,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) | |||
462 | u_char buf[2] = {0, 0}; | 464 | u_char buf[2] = {0, 0}; |
463 | size_t retlen; | 465 | size_t retlen; |
464 | int block; | 466 | int block; |
465 | 467 | ||
466 | /* Get block number */ | 468 | /* Get block number */ |
467 | block = ((int) ofs) >> this->bbt_erase_shift; | 469 | block = ((int) ofs) >> this->bbt_erase_shift; |
468 | if (this->bbt) | 470 | if (this->bbt) |
@@ -471,25 +473,25 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) | |||
471 | /* Do we have a flash based bad block table ? */ | 473 | /* Do we have a flash based bad block table ? */ |
472 | if (this->options & NAND_USE_FLASH_BBT) | 474 | if (this->options & NAND_USE_FLASH_BBT) |
473 | return nand_update_bbt (mtd, ofs); | 475 | return nand_update_bbt (mtd, ofs); |
474 | 476 | ||
475 | /* We write two bytes, so we dont have to mess with 16 bit access */ | 477 | /* We write two bytes, so we dont have to mess with 16 bit access */ |
476 | ofs += mtd->oobsize + (this->badblockpos & ~0x01); | 478 | ofs += mtd->oobsize + (this->badblockpos & ~0x01); |
477 | return nand_write_oob (mtd, ofs , 2, &retlen, buf); | 479 | return nand_write_oob (mtd, ofs , 2, &retlen, buf); |
478 | } | 480 | } |
479 | 481 | ||
480 | /** | 482 | /** |
481 | * nand_check_wp - [GENERIC] check if the chip is write protected | 483 | * nand_check_wp - [GENERIC] check if the chip is write protected |
482 | * @mtd: MTD device structure | 484 | * @mtd: MTD device structure |
483 | * Check, if the device is write protected | 485 | * Check, if the device is write protected |
484 | * | 486 | * |
485 | * The function expects, that the device is already selected | 487 | * The function expects, that the device is already selected |
486 | */ | 488 | */ |
487 | static int nand_check_wp (struct mtd_info *mtd) | 489 | static int nand_check_wp (struct mtd_info *mtd) |
488 | { | 490 | { |
489 | struct nand_chip *this = mtd->priv; | 491 | struct nand_chip *this = mtd->priv; |
490 | /* Check the WP bit */ | 492 | /* Check the WP bit */ |
491 | this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); | 493 | this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); |
492 | return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1; | 494 | return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1; |
493 | } | 495 | } |
494 | 496 | ||
495 | /** | 497 | /** |
@@ -505,15 +507,15 @@ static int nand_check_wp (struct mtd_info *mtd) | |||
505 | static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt) | 507 | static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt) |
506 | { | 508 | { |
507 | struct nand_chip *this = mtd->priv; | 509 | struct nand_chip *this = mtd->priv; |
508 | 510 | ||
509 | if (!this->bbt) | 511 | if (!this->bbt) |
510 | return this->block_bad(mtd, ofs, getchip); | 512 | return this->block_bad(mtd, ofs, getchip); |
511 | 513 | ||
512 | /* Return info from the table */ | 514 | /* Return info from the table */ |
513 | return nand_isbad_bbt (mtd, ofs, allowbbt); | 515 | return nand_isbad_bbt (mtd, ofs, allowbbt); |
514 | } | 516 | } |
515 | 517 | ||
516 | /* | 518 | /* |
517 | * Wait for the ready pin, after a command | 519 | * Wait for the ready pin, after a command |
518 | * The timeout is catched later. | 520 | * The timeout is catched later. |
519 | */ | 521 | */ |
@@ -527,7 +529,7 @@ static void nand_wait_ready(struct mtd_info *mtd) | |||
527 | if (this->dev_ready(mtd)) | 529 | if (this->dev_ready(mtd)) |
528 | return; | 530 | return; |
529 | touch_softlockup_watchdog(); | 531 | touch_softlockup_watchdog(); |
530 | } while (time_before(jiffies, timeo)); | 532 | } while (time_before(jiffies, timeo)); |
531 | } | 533 | } |
532 | 534 | ||
533 | /** | 535 | /** |
@@ -590,13 +592,13 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in | |||
590 | /* Latch in address */ | 592 | /* Latch in address */ |
591 | this->hwcontrol(mtd, NAND_CTL_CLRALE); | 593 | this->hwcontrol(mtd, NAND_CTL_CLRALE); |
592 | } | 594 | } |
593 | 595 | ||
594 | /* | 596 | /* |
595 | * program and erase have their own busy handlers | 597 | * program and erase have their own busy handlers |
596 | * status and sequential in needs no delay | 598 | * status and sequential in needs no delay |
597 | */ | 599 | */ |
598 | switch (command) { | 600 | switch (command) { |
599 | 601 | ||
600 | case NAND_CMD_PAGEPROG: | 602 | case NAND_CMD_PAGEPROG: |
601 | case NAND_CMD_ERASE1: | 603 | case NAND_CMD_ERASE1: |
602 | case NAND_CMD_ERASE2: | 604 | case NAND_CMD_ERASE2: |
@@ -605,7 +607,7 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in | |||
605 | return; | 607 | return; |
606 | 608 | ||
607 | case NAND_CMD_RESET: | 609 | case NAND_CMD_RESET: |
608 | if (this->dev_ready) | 610 | if (this->dev_ready) |
609 | break; | 611 | break; |
610 | udelay(this->chip_delay); | 612 | udelay(this->chip_delay); |
611 | this->hwcontrol(mtd, NAND_CTL_SETCLE); | 613 | this->hwcontrol(mtd, NAND_CTL_SETCLE); |
@@ -614,16 +616,16 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in | |||
614 | while ( !(this->read_byte(mtd) & NAND_STATUS_READY)); | 616 | while ( !(this->read_byte(mtd) & NAND_STATUS_READY)); |
615 | return; | 617 | return; |
616 | 618 | ||
617 | /* This applies to read commands */ | 619 | /* This applies to read commands */ |
618 | default: | 620 | default: |
619 | /* | 621 | /* |
620 | * If we don't have access to the busy pin, we apply the given | 622 | * If we don't have access to the busy pin, we apply the given |
621 | * command delay | 623 | * command delay |
622 | */ | 624 | */ |
623 | if (!this->dev_ready) { | 625 | if (!this->dev_ready) { |
624 | udelay (this->chip_delay); | 626 | udelay (this->chip_delay); |
625 | return; | 627 | return; |
626 | } | 628 | } |
627 | } | 629 | } |
628 | /* Apply this short delay always to ensure that we do wait tWB in | 630 | /* Apply this short delay always to ensure that we do wait tWB in |
629 | * any case on any machine. */ | 631 | * any case on any machine. */ |
@@ -653,8 +655,8 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
653 | column += mtd->oobblock; | 655 | column += mtd->oobblock; |
654 | command = NAND_CMD_READ0; | 656 | command = NAND_CMD_READ0; |
655 | } | 657 | } |
656 | 658 | ||
657 | 659 | ||
658 | /* Begin command latch cycle */ | 660 | /* Begin command latch cycle */ |
659 | this->hwcontrol(mtd, NAND_CTL_SETCLE); | 661 | this->hwcontrol(mtd, NAND_CTL_SETCLE); |
660 | /* Write out the command to the device. */ | 662 | /* Write out the command to the device. */ |
@@ -672,7 +674,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
672 | column >>= 1; | 674 | column >>= 1; |
673 | this->write_byte(mtd, column & 0xff); | 675 | this->write_byte(mtd, column & 0xff); |
674 | this->write_byte(mtd, column >> 8); | 676 | this->write_byte(mtd, column >> 8); |
675 | } | 677 | } |
676 | if (page_addr != -1) { | 678 | if (page_addr != -1) { |
677 | this->write_byte(mtd, (unsigned char) (page_addr & 0xff)); | 679 | this->write_byte(mtd, (unsigned char) (page_addr & 0xff)); |
678 | this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff)); | 680 | this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff)); |
@@ -683,13 +685,13 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
683 | /* Latch in address */ | 685 | /* Latch in address */ |
684 | this->hwcontrol(mtd, NAND_CTL_CLRALE); | 686 | this->hwcontrol(mtd, NAND_CTL_CLRALE); |
685 | } | 687 | } |
686 | 688 | ||
687 | /* | 689 | /* |
688 | * program and erase have their own busy handlers | 690 | * program and erase have their own busy handlers |
689 | * status, sequential in, and deplete1 need no delay | 691 | * status, sequential in, and deplete1 need no delay |
690 | */ | 692 | */ |
691 | switch (command) { | 693 | switch (command) { |
692 | 694 | ||
693 | case NAND_CMD_CACHEDPROG: | 695 | case NAND_CMD_CACHEDPROG: |
694 | case NAND_CMD_PAGEPROG: | 696 | case NAND_CMD_PAGEPROG: |
695 | case NAND_CMD_ERASE1: | 697 | case NAND_CMD_ERASE1: |
@@ -699,7 +701,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
699 | case NAND_CMD_DEPLETE1: | 701 | case NAND_CMD_DEPLETE1: |
700 | return; | 702 | return; |
701 | 703 | ||
702 | /* | 704 | /* |
703 | * read error status commands require only a short delay | 705 | * read error status commands require only a short delay |
704 | */ | 706 | */ |
705 | case NAND_CMD_STATUS_ERROR: | 707 | case NAND_CMD_STATUS_ERROR: |
@@ -711,7 +713,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
711 | return; | 713 | return; |
712 | 714 | ||
713 | case NAND_CMD_RESET: | 715 | case NAND_CMD_RESET: |
714 | if (this->dev_ready) | 716 | if (this->dev_ready) |
715 | break; | 717 | break; |
716 | udelay(this->chip_delay); | 718 | udelay(this->chip_delay); |
717 | this->hwcontrol(mtd, NAND_CTL_SETCLE); | 719 | this->hwcontrol(mtd, NAND_CTL_SETCLE); |
@@ -728,17 +730,17 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
728 | /* End command latch cycle */ | 730 | /* End command latch cycle */ |
729 | this->hwcontrol(mtd, NAND_CTL_CLRCLE); | 731 | this->hwcontrol(mtd, NAND_CTL_CLRCLE); |
730 | /* Fall through into ready check */ | 732 | /* Fall through into ready check */ |
731 | 733 | ||
732 | /* This applies to read commands */ | 734 | /* This applies to read commands */ |
733 | default: | 735 | default: |
734 | /* | 736 | /* |
735 | * If we don't have access to the busy pin, we apply the given | 737 | * If we don't have access to the busy pin, we apply the given |
736 | * command delay | 738 | * command delay |
737 | */ | 739 | */ |
738 | if (!this->dev_ready) { | 740 | if (!this->dev_ready) { |
739 | udelay (this->chip_delay); | 741 | udelay (this->chip_delay); |
740 | return; | 742 | return; |
741 | } | 743 | } |
742 | } | 744 | } |
743 | 745 | ||
744 | /* Apply this short delay always to ensure that we do wait tWB in | 746 | /* Apply this short delay always to ensure that we do wait tWB in |
@@ -752,11 +754,11 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
752 | * nand_get_device - [GENERIC] Get chip for selected access | 754 | * nand_get_device - [GENERIC] Get chip for selected access |
753 | * @this: the nand chip descriptor | 755 | * @this: the nand chip descriptor |
754 | * @mtd: MTD device structure | 756 | * @mtd: MTD device structure |
755 | * @new_state: the state which is requested | 757 | * @new_state: the state which is requested |
756 | * | 758 | * |
757 | * Get the device and lock it for exclusive access | 759 | * Get the device and lock it for exclusive access |
758 | */ | 760 | */ |
759 | static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state) | 761 | static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state) |
760 | { | 762 | { |
761 | struct nand_chip *active; | 763 | struct nand_chip *active; |
762 | spinlock_t *lock; | 764 | spinlock_t *lock; |
@@ -779,7 +781,11 @@ retry: | |||
779 | if (active == this && this->state == FL_READY) { | 781 | if (active == this && this->state == FL_READY) { |
780 | this->state = new_state; | 782 | this->state = new_state; |
781 | spin_unlock(lock); | 783 | spin_unlock(lock); |
782 | return; | 784 | return 0; |
785 | } | ||
786 | if (new_state == FL_PM_SUSPENDED) { | ||
787 | spin_unlock(lock); | ||
788 | return (this->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN; | ||
783 | } | 789 | } |
784 | set_current_state(TASK_UNINTERRUPTIBLE); | 790 | set_current_state(TASK_UNINTERRUPTIBLE); |
785 | add_wait_queue(wq, &wait); | 791 | add_wait_queue(wq, &wait); |
@@ -796,7 +802,7 @@ retry: | |||
796 | * @state: state to select the max. timeout value | 802 | * @state: state to select the max. timeout value |
797 | * | 803 | * |
798 | * Wait for command done. This applies to erase and program only | 804 | * Wait for command done. This applies to erase and program only |
799 | * Erase can take up to 400ms and program up to 20ms according to | 805 | * Erase can take up to 400ms and program up to 20ms according to |
800 | * general NAND and SmartMedia specs | 806 | * general NAND and SmartMedia specs |
801 | * | 807 | * |
802 | */ | 808 | */ |
@@ -805,7 +811,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) | |||
805 | 811 | ||
806 | unsigned long timeo = jiffies; | 812 | unsigned long timeo = jiffies; |
807 | int status; | 813 | int status; |
808 | 814 | ||
809 | if (state == FL_ERASING) | 815 | if (state == FL_ERASING) |
810 | timeo += (HZ * 400) / 1000; | 816 | timeo += (HZ * 400) / 1000; |
811 | else | 817 | else |
@@ -817,17 +823,17 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) | |||
817 | 823 | ||
818 | if ((state == FL_ERASING) && (this->options & NAND_IS_AND)) | 824 | if ((state == FL_ERASING) && (this->options & NAND_IS_AND)) |
819 | this->cmdfunc (mtd, NAND_CMD_STATUS_MULTI, -1, -1); | 825 | this->cmdfunc (mtd, NAND_CMD_STATUS_MULTI, -1, -1); |
820 | else | 826 | else |
821 | this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); | 827 | this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); |
822 | 828 | ||
823 | while (time_before(jiffies, timeo)) { | 829 | while (time_before(jiffies, timeo)) { |
824 | /* Check, if we were interrupted */ | 830 | /* Check, if we were interrupted */ |
825 | if (this->state != state) | 831 | if (this->state != state) |
826 | return 0; | 832 | return 0; |
827 | 833 | ||
828 | if (this->dev_ready) { | 834 | if (this->dev_ready) { |
829 | if (this->dev_ready(mtd)) | 835 | if (this->dev_ready(mtd)) |
830 | break; | 836 | break; |
831 | } else { | 837 | } else { |
832 | if (this->read_byte(mtd) & NAND_STATUS_READY) | 838 | if (this->read_byte(mtd) & NAND_STATUS_READY) |
833 | break; | 839 | break; |
@@ -853,7 +859,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) | |||
853 | * | 859 | * |
854 | * Cached programming is not supported yet. | 860 | * Cached programming is not supported yet. |
855 | */ | 861 | */ |
856 | static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, | 862 | static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, |
857 | u_char *oob_buf, struct nand_oobinfo *oobsel, int cached) | 863 | u_char *oob_buf, struct nand_oobinfo *oobsel, int cached) |
858 | { | 864 | { |
859 | int i, status; | 865 | int i, status; |
@@ -862,10 +868,10 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa | |||
862 | int *oob_config = oobsel->eccpos; | 868 | int *oob_config = oobsel->eccpos; |
863 | int datidx = 0, eccidx = 0, eccsteps = this->eccsteps; | 869 | int datidx = 0, eccidx = 0, eccsteps = this->eccsteps; |
864 | int eccbytes = 0; | 870 | int eccbytes = 0; |
865 | 871 | ||
866 | /* FIXME: Enable cached programming */ | 872 | /* FIXME: Enable cached programming */ |
867 | cached = 0; | 873 | cached = 0; |
868 | 874 | ||
869 | /* Send command to begin auto page programming */ | 875 | /* Send command to begin auto page programming */ |
870 | this->cmdfunc (mtd, NAND_CMD_SEQIN, 0x00, page); | 876 | this->cmdfunc (mtd, NAND_CMD_SEQIN, 0x00, page); |
871 | 877 | ||
@@ -876,7 +882,7 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa | |||
876 | printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n"); | 882 | printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n"); |
877 | this->write_buf(mtd, this->data_poi, mtd->oobblock); | 883 | this->write_buf(mtd, this->data_poi, mtd->oobblock); |
878 | break; | 884 | break; |
879 | 885 | ||
880 | /* Software ecc 3/256, write all */ | 886 | /* Software ecc 3/256, write all */ |
881 | case NAND_ECC_SOFT: | 887 | case NAND_ECC_SOFT: |
882 | for (; eccsteps; eccsteps--) { | 888 | for (; eccsteps; eccsteps--) { |
@@ -905,11 +911,11 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa | |||
905 | } | 911 | } |
906 | break; | 912 | break; |
907 | } | 913 | } |
908 | 914 | ||
909 | /* Write out OOB data */ | 915 | /* Write out OOB data */ |
910 | if (this->options & NAND_HWECC_SYNDROME) | 916 | if (this->options & NAND_HWECC_SYNDROME) |
911 | this->write_buf(mtd, &oob_buf[oobsel->eccbytes], mtd->oobsize - oobsel->eccbytes); | 917 | this->write_buf(mtd, &oob_buf[oobsel->eccbytes], mtd->oobsize - oobsel->eccbytes); |
912 | else | 918 | else |
913 | this->write_buf(mtd, oob_buf, mtd->oobsize); | 919 | this->write_buf(mtd, oob_buf, mtd->oobsize); |
914 | 920 | ||
915 | /* Send command to actually program the data */ | 921 | /* Send command to actually program the data */ |
@@ -934,7 +940,7 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa | |||
934 | /* wait until cache is ready*/ | 940 | /* wait until cache is ready*/ |
935 | // status = this->waitfunc (mtd, this, FL_CACHEDRPG); | 941 | // status = this->waitfunc (mtd, this, FL_CACHEDRPG); |
936 | } | 942 | } |
937 | return 0; | 943 | return 0; |
938 | } | 944 | } |
939 | 945 | ||
940 | #ifdef CONFIG_MTD_NAND_VERIFY_WRITE | 946 | #ifdef CONFIG_MTD_NAND_VERIFY_WRITE |
@@ -950,19 +956,19 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa | |||
950 | * @oobmode: 1 = full buffer verify, 0 = ecc only | 956 | * @oobmode: 1 = full buffer verify, 0 = ecc only |
951 | * | 957 | * |
952 | * The NAND device assumes that it is always writing to a cleanly erased page. | 958 | * The NAND device assumes that it is always writing to a cleanly erased page. |
953 | * Hence, it performs its internal write verification only on bits that | 959 | * Hence, it performs its internal write verification only on bits that |
954 | * transitioned from 1 to 0. The device does NOT verify the whole page on a | 960 | * transitioned from 1 to 0. The device does NOT verify the whole page on a |
955 | * byte by byte basis. It is possible that the page was not completely erased | 961 | * byte by byte basis. It is possible that the page was not completely erased |
956 | * or the page is becoming unusable due to wear. The read with ECC would catch | 962 | * or the page is becoming unusable due to wear. The read with ECC would catch |
957 | * the error later when the ECC page check fails, but we would rather catch | 963 | * the error later when the ECC page check fails, but we would rather catch |
958 | * it early in the page write stage. Better to write no data than invalid data. | 964 | * it early in the page write stage. Better to write no data than invalid data. |
959 | */ | 965 | */ |
960 | static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, | 966 | static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, |
961 | u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode) | 967 | u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode) |
962 | { | 968 | { |
963 | int i, j, datidx = 0, oobofs = 0, res = -EIO; | 969 | int i, j, datidx = 0, oobofs = 0, res = -EIO; |
964 | int eccsteps = this->eccsteps; | 970 | int eccsteps = this->eccsteps; |
965 | int hweccbytes; | 971 | int hweccbytes; |
966 | u_char oobdata[64]; | 972 | u_char oobdata[64]; |
967 | 973 | ||
968 | hweccbytes = (this->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0; | 974 | hweccbytes = (this->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0; |
@@ -1002,7 +1008,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int | |||
1002 | 1008 | ||
1003 | if (oobsel->useecc != MTD_NANDECC_OFF && !hweccbytes) { | 1009 | if (oobsel->useecc != MTD_NANDECC_OFF && !hweccbytes) { |
1004 | int ecccnt = oobsel->eccbytes; | 1010 | int ecccnt = oobsel->eccbytes; |
1005 | 1011 | ||
1006 | for (i = 0; i < ecccnt; i++) { | 1012 | for (i = 0; i < ecccnt; i++) { |
1007 | int idx = oobsel->eccpos[i]; | 1013 | int idx = oobsel->eccpos[i]; |
1008 | if (oobdata[idx] != oob_buf[oobofs + idx] ) { | 1014 | if (oobdata[idx] != oob_buf[oobofs + idx] ) { |
@@ -1012,20 +1018,20 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int | |||
1012 | goto out; | 1018 | goto out; |
1013 | } | 1019 | } |
1014 | } | 1020 | } |
1015 | } | 1021 | } |
1016 | } | 1022 | } |
1017 | oobofs += mtd->oobsize - hweccbytes * eccsteps; | 1023 | oobofs += mtd->oobsize - hweccbytes * eccsteps; |
1018 | page++; | 1024 | page++; |
1019 | numpages--; | 1025 | numpages--; |
1020 | 1026 | ||
1021 | /* Apply delay or wait for ready/busy pin | 1027 | /* Apply delay or wait for ready/busy pin |
1022 | * Do this before the AUTOINCR check, so no problems | 1028 | * Do this before the AUTOINCR check, so no problems |
1023 | * arise if a chip which does auto increment | 1029 | * arise if a chip which does auto increment |
1024 | * is marked as NOAUTOINCR by the board driver. | 1030 | * is marked as NOAUTOINCR by the board driver. |
1025 | * Do this also before returning, so the chip is | 1031 | * Do this also before returning, so the chip is |
1026 | * ready for the next command. | 1032 | * ready for the next command. |
1027 | */ | 1033 | */ |
1028 | if (!this->dev_ready) | 1034 | if (!this->dev_ready) |
1029 | udelay (this->chip_delay); | 1035 | udelay (this->chip_delay); |
1030 | else | 1036 | else |
1031 | nand_wait_ready(mtd); | 1037 | nand_wait_ready(mtd); |
@@ -1033,17 +1039,17 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int | |||
1033 | /* All done, return happy */ | 1039 | /* All done, return happy */ |
1034 | if (!numpages) | 1040 | if (!numpages) |
1035 | return 0; | 1041 | return 0; |
1036 | 1042 | ||
1037 | 1043 | ||
1038 | /* Check, if the chip supports auto page increment */ | 1044 | /* Check, if the chip supports auto page increment */ |
1039 | if (!NAND_CANAUTOINCR(this)) | 1045 | if (!NAND_CANAUTOINCR(this)) |
1040 | this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); | 1046 | this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); |
1041 | } | 1047 | } |
1042 | /* | 1048 | /* |
1043 | * Terminate the read command. We come here in case of an error | 1049 | * Terminate the read command. We come here in case of an error |
1044 | * So we must issue a reset command. | 1050 | * So we must issue a reset command. |
1045 | */ | 1051 | */ |
1046 | out: | 1052 | out: |
1047 | this->cmdfunc (mtd, NAND_CMD_RESET, -1, -1); | 1053 | this->cmdfunc (mtd, NAND_CMD_RESET, -1, -1); |
1048 | return res; | 1054 | return res; |
1049 | } | 1055 | } |
@@ -1105,7 +1111,7 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1105 | * NAND read with ECC | 1111 | * NAND read with ECC |
1106 | */ | 1112 | */ |
1107 | int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | 1113 | int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, |
1108 | size_t * retlen, u_char * buf, u_char * oob_buf, | 1114 | size_t * retlen, u_char * buf, u_char * oob_buf, |
1109 | struct nand_oobinfo *oobsel, int flags) | 1115 | struct nand_oobinfo *oobsel, int flags) |
1110 | { | 1116 | { |
1111 | 1117 | ||
@@ -1139,7 +1145,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1139 | /* Autoplace of oob data ? Use the default placement scheme */ | 1145 | /* Autoplace of oob data ? Use the default placement scheme */ |
1140 | if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) | 1146 | if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) |
1141 | oobsel = this->autooob; | 1147 | oobsel = this->autooob; |
1142 | 1148 | ||
1143 | eccmode = oobsel->useecc ? this->eccmode : NAND_ECC_NONE; | 1149 | eccmode = oobsel->useecc ? this->eccmode : NAND_ECC_NONE; |
1144 | oob_config = oobsel->eccpos; | 1150 | oob_config = oobsel->eccpos; |
1145 | 1151 | ||
@@ -1157,28 +1163,28 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1157 | end = mtd->oobblock; | 1163 | end = mtd->oobblock; |
1158 | ecc = this->eccsize; | 1164 | ecc = this->eccsize; |
1159 | eccbytes = this->eccbytes; | 1165 | eccbytes = this->eccbytes; |
1160 | 1166 | ||
1161 | if ((eccmode == NAND_ECC_NONE) || (this->options & NAND_HWECC_SYNDROME)) | 1167 | if ((eccmode == NAND_ECC_NONE) || (this->options & NAND_HWECC_SYNDROME)) |
1162 | compareecc = 0; | 1168 | compareecc = 0; |
1163 | 1169 | ||
1164 | oobreadlen = mtd->oobsize; | 1170 | oobreadlen = mtd->oobsize; |
1165 | if (this->options & NAND_HWECC_SYNDROME) | 1171 | if (this->options & NAND_HWECC_SYNDROME) |
1166 | oobreadlen -= oobsel->eccbytes; | 1172 | oobreadlen -= oobsel->eccbytes; |
1167 | 1173 | ||
1168 | /* Loop until all data read */ | 1174 | /* Loop until all data read */ |
1169 | while (read < len) { | 1175 | while (read < len) { |
1170 | 1176 | ||
1171 | int aligned = (!col && (len - read) >= end); | 1177 | int aligned = (!col && (len - read) >= end); |
1172 | /* | 1178 | /* |
1173 | * If the read is not page aligned, we have to read into data buffer | 1179 | * If the read is not page aligned, we have to read into data buffer |
1174 | * due to ecc, else we read into return buffer direct | 1180 | * due to ecc, else we read into return buffer direct |
1175 | */ | 1181 | */ |
1176 | if (aligned) | 1182 | if (aligned) |
1177 | data_poi = &buf[read]; | 1183 | data_poi = &buf[read]; |
1178 | else | 1184 | else |
1179 | data_poi = this->data_buf; | 1185 | data_poi = this->data_buf; |
1180 | 1186 | ||
1181 | /* Check, if we have this page in the buffer | 1187 | /* Check, if we have this page in the buffer |
1182 | * | 1188 | * |
1183 | * FIXME: Make it work when we must provide oob data too, | 1189 | * FIXME: Make it work when we must provide oob data too, |
1184 | * check the usage of data_buf oob field | 1190 | * check the usage of data_buf oob field |
@@ -1194,7 +1200,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1194 | if (sndcmd) { | 1200 | if (sndcmd) { |
1195 | this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); | 1201 | this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); |
1196 | sndcmd = 0; | 1202 | sndcmd = 0; |
1197 | } | 1203 | } |
1198 | 1204 | ||
1199 | /* get oob area, if we have no oob buffer from fs-driver */ | 1205 | /* get oob area, if we have no oob buffer from fs-driver */ |
1200 | if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE || | 1206 | if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE || |
@@ -1202,7 +1208,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1202 | oob_data = &this->data_buf[end]; | 1208 | oob_data = &this->data_buf[end]; |
1203 | 1209 | ||
1204 | eccsteps = this->eccsteps; | 1210 | eccsteps = this->eccsteps; |
1205 | 1211 | ||
1206 | switch (eccmode) { | 1212 | switch (eccmode) { |
1207 | case NAND_ECC_NONE: { /* No ECC, Read in a page */ | 1213 | case NAND_ECC_NONE: { /* No ECC, Read in a page */ |
1208 | static unsigned long lastwhinge = 0; | 1214 | static unsigned long lastwhinge = 0; |
@@ -1213,12 +1219,12 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1213 | this->read_buf(mtd, data_poi, end); | 1219 | this->read_buf(mtd, data_poi, end); |
1214 | break; | 1220 | break; |
1215 | } | 1221 | } |
1216 | 1222 | ||
1217 | case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */ | 1223 | case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */ |
1218 | this->read_buf(mtd, data_poi, end); | 1224 | this->read_buf(mtd, data_poi, end); |
1219 | for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=3, datidx += ecc) | 1225 | for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=3, datidx += ecc) |
1220 | this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]); | 1226 | this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]); |
1221 | break; | 1227 | break; |
1222 | 1228 | ||
1223 | default: | 1229 | default: |
1224 | for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=eccbytes, datidx += ecc) { | 1230 | for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=eccbytes, datidx += ecc) { |
@@ -1237,15 +1243,15 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1237 | * does the error correction on the fly */ | 1243 | * does the error correction on the fly */ |
1238 | ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]); | 1244 | ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]); |
1239 | if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { | 1245 | if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { |
1240 | DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " | 1246 | DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " |
1241 | "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr); | 1247 | "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr); |
1242 | ecc_failed++; | 1248 | ecc_failed++; |
1243 | } | 1249 | } |
1244 | } else { | 1250 | } else { |
1245 | this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]); | 1251 | this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]); |
1246 | } | 1252 | } |
1247 | } | 1253 | } |
1248 | break; | 1254 | break; |
1249 | } | 1255 | } |
1250 | 1256 | ||
1251 | /* read oobdata */ | 1257 | /* read oobdata */ |
@@ -1253,8 +1259,8 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1253 | 1259 | ||
1254 | /* Skip ECC check, if not requested (ECC_NONE or HW_ECC with syndromes) */ | 1260 | /* Skip ECC check, if not requested (ECC_NONE or HW_ECC with syndromes) */ |
1255 | if (!compareecc) | 1261 | if (!compareecc) |
1256 | goto readoob; | 1262 | goto readoob; |
1257 | 1263 | ||
1258 | /* Pick the ECC bytes out of the oob data */ | 1264 | /* Pick the ECC bytes out of the oob data */ |
1259 | for (j = 0; j < oobsel->eccbytes; j++) | 1265 | for (j = 0; j < oobsel->eccbytes; j++) |
1260 | ecc_code[j] = oob_data[oob_config[j]]; | 1266 | ecc_code[j] = oob_data[oob_config[j]]; |
@@ -1262,24 +1268,24 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1262 | /* correct data, if neccecary */ | 1268 | /* correct data, if neccecary */ |
1263 | for (i = 0, j = 0, datidx = 0; i < this->eccsteps; i++, datidx += ecc) { | 1269 | for (i = 0, j = 0, datidx = 0; i < this->eccsteps; i++, datidx += ecc) { |
1264 | ecc_status = this->correct_data(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]); | 1270 | ecc_status = this->correct_data(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]); |
1265 | 1271 | ||
1266 | /* Get next chunk of ecc bytes */ | 1272 | /* Get next chunk of ecc bytes */ |
1267 | j += eccbytes; | 1273 | j += eccbytes; |
1268 | 1274 | ||
1269 | /* Check, if we have a fs supplied oob-buffer, | 1275 | /* Check, if we have a fs supplied oob-buffer, |
1270 | * This is the legacy mode. Used by YAFFS1 | 1276 | * This is the legacy mode. Used by YAFFS1 |
1271 | * Should go away some day | 1277 | * Should go away some day |
1272 | */ | 1278 | */ |
1273 | if (oob_buf && oobsel->useecc == MTD_NANDECC_PLACE) { | 1279 | if (oob_buf && oobsel->useecc == MTD_NANDECC_PLACE) { |
1274 | int *p = (int *)(&oob_data[mtd->oobsize]); | 1280 | int *p = (int *)(&oob_data[mtd->oobsize]); |
1275 | p[i] = ecc_status; | 1281 | p[i] = ecc_status; |
1276 | } | 1282 | } |
1277 | 1283 | ||
1278 | if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { | 1284 | if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { |
1279 | DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page); | 1285 | DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page); |
1280 | ecc_failed++; | 1286 | ecc_failed++; |
1281 | } | 1287 | } |
1282 | } | 1288 | } |
1283 | 1289 | ||
1284 | readoob: | 1290 | readoob: |
1285 | /* check, if we have a fs supplied oob-buffer */ | 1291 | /* check, if we have a fs supplied oob-buffer */ |
@@ -1305,25 +1311,25 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1305 | } | 1311 | } |
1306 | readdata: | 1312 | readdata: |
1307 | /* Partial page read, transfer data into fs buffer */ | 1313 | /* Partial page read, transfer data into fs buffer */ |
1308 | if (!aligned) { | 1314 | if (!aligned) { |
1309 | for (j = col; j < end && read < len; j++) | 1315 | for (j = col; j < end && read < len; j++) |
1310 | buf[read++] = data_poi[j]; | 1316 | buf[read++] = data_poi[j]; |
1311 | this->pagebuf = realpage; | 1317 | this->pagebuf = realpage; |
1312 | } else | 1318 | } else |
1313 | read += mtd->oobblock; | 1319 | read += mtd->oobblock; |
1314 | 1320 | ||
1315 | /* Apply delay or wait for ready/busy pin | 1321 | /* Apply delay or wait for ready/busy pin |
1316 | * Do this before the AUTOINCR check, so no problems | 1322 | * Do this before the AUTOINCR check, so no problems |
1317 | * arise if a chip which does auto increment | 1323 | * arise if a chip which does auto increment |
1318 | * is marked as NOAUTOINCR by the board driver. | 1324 | * is marked as NOAUTOINCR by the board driver. |
1319 | */ | 1325 | */ |
1320 | if (!this->dev_ready) | 1326 | if (!this->dev_ready) |
1321 | udelay (this->chip_delay); | 1327 | udelay (this->chip_delay); |
1322 | else | 1328 | else |
1323 | nand_wait_ready(mtd); | 1329 | nand_wait_ready(mtd); |
1324 | 1330 | ||
1325 | if (read == len) | 1331 | if (read == len) |
1326 | break; | 1332 | break; |
1327 | 1333 | ||
1328 | /* For subsequent reads align to page boundary. */ | 1334 | /* For subsequent reads align to page boundary. */ |
1329 | col = 0; | 1335 | col = 0; |
@@ -1337,11 +1343,11 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1337 | this->select_chip(mtd, -1); | 1343 | this->select_chip(mtd, -1); |
1338 | this->select_chip(mtd, chipnr); | 1344 | this->select_chip(mtd, chipnr); |
1339 | } | 1345 | } |
1340 | /* Check, if the chip supports auto page increment | 1346 | /* Check, if the chip supports auto page increment |
1341 | * or if we have hit a block boundary. | 1347 | * or if we have hit a block boundary. |
1342 | */ | 1348 | */ |
1343 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) | 1349 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) |
1344 | sndcmd = 1; | 1350 | sndcmd = 1; |
1345 | } | 1351 | } |
1346 | 1352 | ||
1347 | /* Deselect and wake up anyone waiting on the device */ | 1353 | /* Deselect and wake up anyone waiting on the device */ |
@@ -1378,7 +1384,7 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t | |||
1378 | /* Shift to get page */ | 1384 | /* Shift to get page */ |
1379 | page = (int)(from >> this->page_shift); | 1385 | page = (int)(from >> this->page_shift); |
1380 | chipnr = (int)(from >> this->chip_shift); | 1386 | chipnr = (int)(from >> this->chip_shift); |
1381 | 1387 | ||
1382 | /* Mask to get column */ | 1388 | /* Mask to get column */ |
1383 | col = from & (mtd->oobsize - 1); | 1389 | col = from & (mtd->oobsize - 1); |
1384 | 1390 | ||
@@ -1400,7 +1406,7 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t | |||
1400 | 1406 | ||
1401 | /* Send the read command */ | 1407 | /* Send the read command */ |
1402 | this->cmdfunc (mtd, NAND_CMD_READOOB, col, page & this->pagemask); | 1408 | this->cmdfunc (mtd, NAND_CMD_READOOB, col, page & this->pagemask); |
1403 | /* | 1409 | /* |
1404 | * Read the data, if we read more than one page | 1410 | * Read the data, if we read more than one page |
1405 | * oob data, let the device transfer the data ! | 1411 | * oob data, let the device transfer the data ! |
1406 | */ | 1412 | */ |
@@ -1422,20 +1428,20 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t | |||
1422 | this->select_chip(mtd, -1); | 1428 | this->select_chip(mtd, -1); |
1423 | this->select_chip(mtd, chipnr); | 1429 | this->select_chip(mtd, chipnr); |
1424 | } | 1430 | } |
1425 | 1431 | ||
1426 | /* Apply delay or wait for ready/busy pin | 1432 | /* Apply delay or wait for ready/busy pin |
1427 | * Do this before the AUTOINCR check, so no problems | 1433 | * Do this before the AUTOINCR check, so no problems |
1428 | * arise if a chip which does auto increment | 1434 | * arise if a chip which does auto increment |
1429 | * is marked as NOAUTOINCR by the board driver. | 1435 | * is marked as NOAUTOINCR by the board driver. |
1430 | */ | 1436 | */ |
1431 | if (!this->dev_ready) | 1437 | if (!this->dev_ready) |
1432 | udelay (this->chip_delay); | 1438 | udelay (this->chip_delay); |
1433 | else | 1439 | else |
1434 | nand_wait_ready(mtd); | 1440 | nand_wait_ready(mtd); |
1435 | 1441 | ||
1436 | /* Check, if the chip supports auto page increment | 1442 | /* Check, if the chip supports auto page increment |
1437 | * or if we have hit a block boundary. | 1443 | * or if we have hit a block boundary. |
1438 | */ | 1444 | */ |
1439 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) { | 1445 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) { |
1440 | /* For subsequent page reads set offset to 0 */ | 1446 | /* For subsequent page reads set offset to 0 */ |
1441 | this->cmdfunc (mtd, NAND_CMD_READOOB, 0x0, page & this->pagemask); | 1447 | this->cmdfunc (mtd, NAND_CMD_READOOB, 0x0, page & this->pagemask); |
@@ -1481,27 +1487,27 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, | |||
1481 | nand_get_device (this, mtd , FL_READING); | 1487 | nand_get_device (this, mtd , FL_READING); |
1482 | 1488 | ||
1483 | this->select_chip (mtd, chip); | 1489 | this->select_chip (mtd, chip); |
1484 | 1490 | ||
1485 | /* Add requested oob length */ | 1491 | /* Add requested oob length */ |
1486 | len += ooblen; | 1492 | len += ooblen; |
1487 | 1493 | ||
1488 | while (len) { | 1494 | while (len) { |
1489 | if (sndcmd) | 1495 | if (sndcmd) |
1490 | this->cmdfunc (mtd, NAND_CMD_READ0, 0, page & this->pagemask); | 1496 | this->cmdfunc (mtd, NAND_CMD_READ0, 0, page & this->pagemask); |
1491 | sndcmd = 0; | 1497 | sndcmd = 0; |
1492 | 1498 | ||
1493 | this->read_buf (mtd, &buf[cnt], pagesize); | 1499 | this->read_buf (mtd, &buf[cnt], pagesize); |
1494 | 1500 | ||
1495 | len -= pagesize; | 1501 | len -= pagesize; |
1496 | cnt += pagesize; | 1502 | cnt += pagesize; |
1497 | page++; | 1503 | page++; |
1498 | 1504 | ||
1499 | if (!this->dev_ready) | 1505 | if (!this->dev_ready) |
1500 | udelay (this->chip_delay); | 1506 | udelay (this->chip_delay); |
1501 | else | 1507 | else |
1502 | nand_wait_ready(mtd); | 1508 | nand_wait_ready(mtd); |
1503 | 1509 | ||
1504 | /* Check, if the chip supports auto page increment */ | 1510 | /* Check, if the chip supports auto page increment */ |
1505 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) | 1511 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) |
1506 | sndcmd = 1; | 1512 | sndcmd = 1; |
1507 | } | 1513 | } |
@@ -1512,8 +1518,8 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, | |||
1512 | } | 1518 | } |
1513 | 1519 | ||
1514 | 1520 | ||
1515 | /** | 1521 | /** |
1516 | * nand_prepare_oobbuf - [GENERIC] Prepare the out of band buffer | 1522 | * nand_prepare_oobbuf - [GENERIC] Prepare the out of band buffer |
1517 | * @mtd: MTD device structure | 1523 | * @mtd: MTD device structure |
1518 | * @fsbuf: buffer given by fs driver | 1524 | * @fsbuf: buffer given by fs driver |
1519 | * @oobsel: out of band selection structre | 1525 | * @oobsel: out of band selection structre |
@@ -1542,20 +1548,20 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct | |||
1542 | int i, len, ofs; | 1548 | int i, len, ofs; |
1543 | 1549 | ||
1544 | /* Zero copy fs supplied buffer */ | 1550 | /* Zero copy fs supplied buffer */ |
1545 | if (fsbuf && !autoplace) | 1551 | if (fsbuf && !autoplace) |
1546 | return fsbuf; | 1552 | return fsbuf; |
1547 | 1553 | ||
1548 | /* Check, if the buffer must be filled with ff again */ | 1554 | /* Check, if the buffer must be filled with ff again */ |
1549 | if (this->oobdirty) { | 1555 | if (this->oobdirty) { |
1550 | memset (this->oob_buf, 0xff, | 1556 | memset (this->oob_buf, 0xff, |
1551 | mtd->oobsize << (this->phys_erase_shift - this->page_shift)); | 1557 | mtd->oobsize << (this->phys_erase_shift - this->page_shift)); |
1552 | this->oobdirty = 0; | 1558 | this->oobdirty = 0; |
1553 | } | 1559 | } |
1554 | 1560 | ||
1555 | /* If we have no autoplacement or no fs buffer use the internal one */ | 1561 | /* If we have no autoplacement or no fs buffer use the internal one */ |
1556 | if (!autoplace || !fsbuf) | 1562 | if (!autoplace || !fsbuf) |
1557 | return this->oob_buf; | 1563 | return this->oob_buf; |
1558 | 1564 | ||
1559 | /* Walk through the pages and place the data */ | 1565 | /* Walk through the pages and place the data */ |
1560 | this->oobdirty = 1; | 1566 | this->oobdirty = 1; |
1561 | ofs = 0; | 1567 | ofs = 0; |
@@ -1589,7 +1595,7 @@ static int nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * ret | |||
1589 | { | 1595 | { |
1590 | return (nand_write_ecc (mtd, to, len, retlen, buf, NULL, NULL)); | 1596 | return (nand_write_ecc (mtd, to, len, retlen, buf, NULL, NULL)); |
1591 | } | 1597 | } |
1592 | 1598 | ||
1593 | /** | 1599 | /** |
1594 | * nand_write_ecc - [MTD Interface] NAND write with ECC | 1600 | * nand_write_ecc - [MTD Interface] NAND write with ECC |
1595 | * @mtd: MTD device structure | 1601 | * @mtd: MTD device structure |
@@ -1622,7 +1628,7 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1622 | return -EINVAL; | 1628 | return -EINVAL; |
1623 | } | 1629 | } |
1624 | 1630 | ||
1625 | /* reject writes, which are not page aligned */ | 1631 | /* reject writes, which are not page aligned */ |
1626 | if (NOTALIGNED (to) || NOTALIGNED(len)) { | 1632 | if (NOTALIGNED (to) || NOTALIGNED(len)) { |
1627 | printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); | 1633 | printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); |
1628 | return -EINVAL; | 1634 | return -EINVAL; |
@@ -1641,14 +1647,14 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1641 | goto out; | 1647 | goto out; |
1642 | 1648 | ||
1643 | /* if oobsel is NULL, use chip defaults */ | 1649 | /* if oobsel is NULL, use chip defaults */ |
1644 | if (oobsel == NULL) | 1650 | if (oobsel == NULL) |
1645 | oobsel = &mtd->oobinfo; | 1651 | oobsel = &mtd->oobinfo; |
1646 | 1652 | ||
1647 | /* Autoplace of oob data ? Use the default placement scheme */ | 1653 | /* Autoplace of oob data ? Use the default placement scheme */ |
1648 | if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) { | 1654 | if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) { |
1649 | oobsel = this->autooob; | 1655 | oobsel = this->autooob; |
1650 | autoplace = 1; | 1656 | autoplace = 1; |
1651 | } | 1657 | } |
1652 | if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR) | 1658 | if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR) |
1653 | autoplace = 1; | 1659 | autoplace = 1; |
1654 | 1660 | ||
@@ -1656,9 +1662,9 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1656 | totalpages = len >> this->page_shift; | 1662 | totalpages = len >> this->page_shift; |
1657 | page = (int) (to >> this->page_shift); | 1663 | page = (int) (to >> this->page_shift); |
1658 | /* Invalidate the page cache, if we write to the cached page */ | 1664 | /* Invalidate the page cache, if we write to the cached page */ |
1659 | if (page <= this->pagebuf && this->pagebuf < (page + totalpages)) | 1665 | if (page <= this->pagebuf && this->pagebuf < (page + totalpages)) |
1660 | this->pagebuf = -1; | 1666 | this->pagebuf = -1; |
1661 | 1667 | ||
1662 | /* Set it relative to chip */ | 1668 | /* Set it relative to chip */ |
1663 | page &= this->pagemask; | 1669 | page &= this->pagemask; |
1664 | startpage = page; | 1670 | startpage = page; |
@@ -1680,14 +1686,14 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1680 | if (ret) { | 1686 | if (ret) { |
1681 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: write_page failed %d\n", ret); | 1687 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: write_page failed %d\n", ret); |
1682 | goto out; | 1688 | goto out; |
1683 | } | 1689 | } |
1684 | /* Next oob page */ | 1690 | /* Next oob page */ |
1685 | oob += mtd->oobsize; | 1691 | oob += mtd->oobsize; |
1686 | /* Update written bytes count */ | 1692 | /* Update written bytes count */ |
1687 | written += mtd->oobblock; | 1693 | written += mtd->oobblock; |
1688 | if (written == len) | 1694 | if (written == len) |
1689 | goto cmp; | 1695 | goto cmp; |
1690 | 1696 | ||
1691 | /* Increment page address */ | 1697 | /* Increment page address */ |
1692 | page++; | 1698 | page++; |
1693 | 1699 | ||
@@ -1698,13 +1704,13 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1698 | if (!(page & (ppblock - 1))){ | 1704 | if (!(page & (ppblock - 1))){ |
1699 | int ofs; | 1705 | int ofs; |
1700 | this->data_poi = bufstart; | 1706 | this->data_poi = bufstart; |
1701 | ret = nand_verify_pages (mtd, this, startpage, | 1707 | ret = nand_verify_pages (mtd, this, startpage, |
1702 | page - startpage, | 1708 | page - startpage, |
1703 | oobbuf, oobsel, chipnr, (eccbuf != NULL)); | 1709 | oobbuf, oobsel, chipnr, (eccbuf != NULL)); |
1704 | if (ret) { | 1710 | if (ret) { |
1705 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); | 1711 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); |
1706 | goto out; | 1712 | goto out; |
1707 | } | 1713 | } |
1708 | *retlen = written; | 1714 | *retlen = written; |
1709 | 1715 | ||
1710 | ofs = autoplace ? mtd->oobavail : mtd->oobsize; | 1716 | ofs = autoplace ? mtd->oobavail : mtd->oobsize; |
@@ -1714,8 +1720,9 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1714 | numpages = min (totalpages, ppblock); | 1720 | numpages = min (totalpages, ppblock); |
1715 | page &= this->pagemask; | 1721 | page &= this->pagemask; |
1716 | startpage = page; | 1722 | startpage = page; |
1717 | oobbuf = nand_prepare_oobbuf (mtd, eccbuf, oobsel, | 1723 | oobbuf = nand_prepare_oobbuf (mtd, eccbuf, oobsel, |
1718 | autoplace, numpages); | 1724 | autoplace, numpages); |
1725 | oob = 0; | ||
1719 | /* Check, if we cross a chip boundary */ | 1726 | /* Check, if we cross a chip boundary */ |
1720 | if (!page) { | 1727 | if (!page) { |
1721 | chipnr++; | 1728 | chipnr++; |
@@ -1731,7 +1738,7 @@ cmp: | |||
1731 | oobbuf, oobsel, chipnr, (eccbuf != NULL)); | 1738 | oobbuf, oobsel, chipnr, (eccbuf != NULL)); |
1732 | if (!ret) | 1739 | if (!ret) |
1733 | *retlen = written; | 1740 | *retlen = written; |
1734 | else | 1741 | else |
1735 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); | 1742 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); |
1736 | 1743 | ||
1737 | out: | 1744 | out: |
@@ -1791,7 +1798,7 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * | |||
1791 | /* Check, if it is write protected */ | 1798 | /* Check, if it is write protected */ |
1792 | if (nand_check_wp(mtd)) | 1799 | if (nand_check_wp(mtd)) |
1793 | goto out; | 1800 | goto out; |
1794 | 1801 | ||
1795 | /* Invalidate the page cache, if we write to the cached page */ | 1802 | /* Invalidate the page cache, if we write to the cached page */ |
1796 | if (page == this->pagebuf) | 1803 | if (page == this->pagebuf) |
1797 | this->pagebuf = -1; | 1804 | this->pagebuf = -1; |
@@ -1854,10 +1861,10 @@ out: | |||
1854 | * | 1861 | * |
1855 | * NAND write with kvec. This just calls the ecc function | 1862 | * NAND write with kvec. This just calls the ecc function |
1856 | */ | 1863 | */ |
1857 | static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, | 1864 | static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, |
1858 | loff_t to, size_t * retlen) | 1865 | loff_t to, size_t * retlen) |
1859 | { | 1866 | { |
1860 | return (nand_writev_ecc (mtd, vecs, count, to, retlen, NULL, NULL)); | 1867 | return (nand_writev_ecc (mtd, vecs, count, to, retlen, NULL, NULL)); |
1861 | } | 1868 | } |
1862 | 1869 | ||
1863 | /** | 1870 | /** |
@@ -1872,7 +1879,7 @@ static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned | |||
1872 | * | 1879 | * |
1873 | * NAND write with iovec with ecc | 1880 | * NAND write with iovec with ecc |
1874 | */ | 1881 | */ |
1875 | static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, | 1882 | static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, |
1876 | loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel) | 1883 | loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel) |
1877 | { | 1884 | { |
1878 | int i, page, len, total_len, ret = -EIO, written = 0, chipnr; | 1885 | int i, page, len, total_len, ret = -EIO, written = 0, chipnr; |
@@ -1898,7 +1905,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1898 | return -EINVAL; | 1905 | return -EINVAL; |
1899 | } | 1906 | } |
1900 | 1907 | ||
1901 | /* reject writes, which are not page aligned */ | 1908 | /* reject writes, which are not page aligned */ |
1902 | if (NOTALIGNED (to) || NOTALIGNED(total_len)) { | 1909 | if (NOTALIGNED (to) || NOTALIGNED(total_len)) { |
1903 | printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); | 1910 | printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); |
1904 | return -EINVAL; | 1911 | return -EINVAL; |
@@ -1917,21 +1924,21 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1917 | goto out; | 1924 | goto out; |
1918 | 1925 | ||
1919 | /* if oobsel is NULL, use chip defaults */ | 1926 | /* if oobsel is NULL, use chip defaults */ |
1920 | if (oobsel == NULL) | 1927 | if (oobsel == NULL) |
1921 | oobsel = &mtd->oobinfo; | 1928 | oobsel = &mtd->oobinfo; |
1922 | 1929 | ||
1923 | /* Autoplace of oob data ? Use the default placement scheme */ | 1930 | /* Autoplace of oob data ? Use the default placement scheme */ |
1924 | if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) { | 1931 | if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) { |
1925 | oobsel = this->autooob; | 1932 | oobsel = this->autooob; |
1926 | autoplace = 1; | 1933 | autoplace = 1; |
1927 | } | 1934 | } |
1928 | if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR) | 1935 | if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR) |
1929 | autoplace = 1; | 1936 | autoplace = 1; |
1930 | 1937 | ||
1931 | /* Setup start page */ | 1938 | /* Setup start page */ |
1932 | page = (int) (to >> this->page_shift); | 1939 | page = (int) (to >> this->page_shift); |
1933 | /* Invalidate the page cache, if we write to the cached page */ | 1940 | /* Invalidate the page cache, if we write to the cached page */ |
1934 | if (page <= this->pagebuf && this->pagebuf < ((to + total_len) >> this->page_shift)) | 1941 | if (page <= this->pagebuf && this->pagebuf < ((to + total_len) >> this->page_shift)) |
1935 | this->pagebuf = -1; | 1942 | this->pagebuf = -1; |
1936 | 1943 | ||
1937 | startpage = page & this->pagemask; | 1944 | startpage = page & this->pagemask; |
@@ -1955,10 +1962,10 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1955 | oob = 0; | 1962 | oob = 0; |
1956 | for (i = 1; i <= numpages; i++) { | 1963 | for (i = 1; i <= numpages; i++) { |
1957 | /* Write one page. If this is the last page to write | 1964 | /* Write one page. If this is the last page to write |
1958 | * then use the real pageprogram command, else select | 1965 | * then use the real pageprogram command, else select |
1959 | * cached programming if supported by the chip. | 1966 | * cached programming if supported by the chip. |
1960 | */ | 1967 | */ |
1961 | ret = nand_write_page (mtd, this, page & this->pagemask, | 1968 | ret = nand_write_page (mtd, this, page & this->pagemask, |
1962 | &oobbuf[oob], oobsel, i != numpages); | 1969 | &oobbuf[oob], oobsel, i != numpages); |
1963 | if (ret) | 1970 | if (ret) |
1964 | goto out; | 1971 | goto out; |
@@ -1974,12 +1981,12 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1974 | count--; | 1981 | count--; |
1975 | } | 1982 | } |
1976 | } else { | 1983 | } else { |
1977 | /* We must use the internal buffer, read data out of each | 1984 | /* We must use the internal buffer, read data out of each |
1978 | * tuple until we have a full page to write | 1985 | * tuple until we have a full page to write |
1979 | */ | 1986 | */ |
1980 | int cnt = 0; | 1987 | int cnt = 0; |
1981 | while (cnt < mtd->oobblock) { | 1988 | while (cnt < mtd->oobblock) { |
1982 | if (vecs->iov_base != NULL && vecs->iov_len) | 1989 | if (vecs->iov_base != NULL && vecs->iov_len) |
1983 | this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++]; | 1990 | this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++]; |
1984 | /* Check, if we have to switch to the next tuple */ | 1991 | /* Check, if we have to switch to the next tuple */ |
1985 | if (len >= (int) vecs->iov_len) { | 1992 | if (len >= (int) vecs->iov_len) { |
@@ -1988,10 +1995,10 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1988 | count--; | 1995 | count--; |
1989 | } | 1996 | } |
1990 | } | 1997 | } |
1991 | this->pagebuf = page; | 1998 | this->pagebuf = page; |
1992 | this->data_poi = this->data_buf; | 1999 | this->data_poi = this->data_buf; |
1993 | bufstart = this->data_poi; | 2000 | bufstart = this->data_poi; |
1994 | numpages = 1; | 2001 | numpages = 1; |
1995 | oobbuf = nand_prepare_oobbuf (mtd, NULL, oobsel, autoplace, numpages); | 2002 | oobbuf = nand_prepare_oobbuf (mtd, NULL, oobsel, autoplace, numpages); |
1996 | ret = nand_write_page (mtd, this, page & this->pagemask, | 2003 | ret = nand_write_page (mtd, this, page & this->pagemask, |
1997 | oobbuf, oobsel, 0); | 2004 | oobbuf, oobsel, 0); |
@@ -2004,7 +2011,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
2004 | ret = nand_verify_pages (mtd, this, startpage, numpages, oobbuf, oobsel, chipnr, 0); | 2011 | ret = nand_verify_pages (mtd, this, startpage, numpages, oobbuf, oobsel, chipnr, 0); |
2005 | if (ret) | 2012 | if (ret) |
2006 | goto out; | 2013 | goto out; |
2007 | 2014 | ||
2008 | written += mtd->oobblock * numpages; | 2015 | written += mtd->oobblock * numpages; |
2009 | /* All done ? */ | 2016 | /* All done ? */ |
2010 | if (!count) | 2017 | if (!count) |
@@ -2072,7 +2079,7 @@ static int nand_erase (struct mtd_info *mtd, struct erase_info *instr) | |||
2072 | { | 2079 | { |
2073 | return nand_erase_nand (mtd, instr, 0); | 2080 | return nand_erase_nand (mtd, instr, 0); |
2074 | } | 2081 | } |
2075 | 2082 | ||
2076 | #define BBT_PAGE_MASK 0xffffff3f | 2083 | #define BBT_PAGE_MASK 0xffffff3f |
2077 | /** | 2084 | /** |
2078 | * nand_erase_intern - [NAND Interface] erase block(s) | 2085 | * nand_erase_intern - [NAND Interface] erase block(s) |
@@ -2154,14 +2161,14 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb | |||
2154 | instr->state = MTD_ERASE_FAILED; | 2161 | instr->state = MTD_ERASE_FAILED; |
2155 | goto erase_exit; | 2162 | goto erase_exit; |
2156 | } | 2163 | } |
2157 | 2164 | ||
2158 | /* Invalidate the page cache, if we erase the block which contains | 2165 | /* Invalidate the page cache, if we erase the block which contains |
2159 | the current cached page */ | 2166 | the current cached page */ |
2160 | if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block)) | 2167 | if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block)) |
2161 | this->pagebuf = -1; | 2168 | this->pagebuf = -1; |
2162 | 2169 | ||
2163 | this->erase_cmd (mtd, page & this->pagemask); | 2170 | this->erase_cmd (mtd, page & this->pagemask); |
2164 | 2171 | ||
2165 | status = this->waitfunc (mtd, this, FL_ERASING); | 2172 | status = this->waitfunc (mtd, this, FL_ERASING); |
2166 | 2173 | ||
2167 | /* See if operation failed and additional status checks are available */ | 2174 | /* See if operation failed and additional status checks are available */ |
@@ -2179,12 +2186,12 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb | |||
2179 | 2186 | ||
2180 | /* if BBT requires refresh, set the BBT rewrite flag to the page being erased */ | 2187 | /* if BBT requires refresh, set the BBT rewrite flag to the page being erased */ |
2181 | if (this->options & BBT_AUTO_REFRESH) { | 2188 | if (this->options & BBT_AUTO_REFRESH) { |
2182 | if (((page & BBT_PAGE_MASK) == bbt_masked_page) && | 2189 | if (((page & BBT_PAGE_MASK) == bbt_masked_page) && |
2183 | (page != this->bbt_td->pages[chipnr])) { | 2190 | (page != this->bbt_td->pages[chipnr])) { |
2184 | rewrite_bbt[chipnr] = (page << this->page_shift); | 2191 | rewrite_bbt[chipnr] = (page << this->page_shift); |
2185 | } | 2192 | } |
2186 | } | 2193 | } |
2187 | 2194 | ||
2188 | /* Increment page address and decrement length */ | 2195 | /* Increment page address and decrement length */ |
2189 | len -= (1 << this->phys_erase_shift); | 2196 | len -= (1 << this->phys_erase_shift); |
2190 | page += pages_per_block; | 2197 | page += pages_per_block; |
@@ -2195,7 +2202,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb | |||
2195 | this->select_chip(mtd, -1); | 2202 | this->select_chip(mtd, -1); |
2196 | this->select_chip(mtd, chipnr); | 2203 | this->select_chip(mtd, chipnr); |
2197 | 2204 | ||
2198 | /* if BBT requires refresh and BBT-PERCHIP, | 2205 | /* if BBT requires refresh and BBT-PERCHIP, |
2199 | * set the BBT page mask to see if this BBT should be rewritten */ | 2206 | * set the BBT page mask to see if this BBT should be rewritten */ |
2200 | if ((this->options & BBT_AUTO_REFRESH) && (this->bbt_td->options & NAND_BBT_PERCHIP)) { | 2207 | if ((this->options & BBT_AUTO_REFRESH) && (this->bbt_td->options & NAND_BBT_PERCHIP)) { |
2201 | bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK; | 2208 | bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK; |
@@ -2220,7 +2227,7 @@ erase_exit: | |||
2220 | for (chipnr = 0; chipnr < this->numchips; chipnr++) { | 2227 | for (chipnr = 0; chipnr < this->numchips; chipnr++) { |
2221 | if (rewrite_bbt[chipnr]) { | 2228 | if (rewrite_bbt[chipnr]) { |
2222 | /* update the BBT for chip */ | 2229 | /* update the BBT for chip */ |
2223 | DEBUG (MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n", | 2230 | DEBUG (MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n", |
2224 | chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]); | 2231 | chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]); |
2225 | nand_update_bbt (mtd, rewrite_bbt[chipnr]); | 2232 | nand_update_bbt (mtd, rewrite_bbt[chipnr]); |
2226 | } | 2233 | } |
@@ -2258,9 +2265,9 @@ static void nand_sync (struct mtd_info *mtd) | |||
2258 | static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs) | 2265 | static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs) |
2259 | { | 2266 | { |
2260 | /* Check for invalid offset */ | 2267 | /* Check for invalid offset */ |
2261 | if (ofs > mtd->size) | 2268 | if (ofs > mtd->size) |
2262 | return -EINVAL; | 2269 | return -EINVAL; |
2263 | 2270 | ||
2264 | return nand_block_checkbad (mtd, ofs, 1, 0); | 2271 | return nand_block_checkbad (mtd, ofs, 1, 0); |
2265 | } | 2272 | } |
2266 | 2273 | ||
@@ -2285,6 +2292,34 @@ static int nand_block_markbad (struct mtd_info *mtd, loff_t ofs) | |||
2285 | } | 2292 | } |
2286 | 2293 | ||
2287 | /** | 2294 | /** |
2295 | * nand_suspend - [MTD Interface] Suspend the NAND flash | ||
2296 | * @mtd: MTD device structure | ||
2297 | */ | ||
2298 | static int nand_suspend(struct mtd_info *mtd) | ||
2299 | { | ||
2300 | struct nand_chip *this = mtd->priv; | ||
2301 | |||
2302 | return nand_get_device (this, mtd, FL_PM_SUSPENDED); | ||
2303 | } | ||
2304 | |||
2305 | /** | ||
2306 | * nand_resume - [MTD Interface] Resume the NAND flash | ||
2307 | * @mtd: MTD device structure | ||
2308 | */ | ||
2309 | static void nand_resume(struct mtd_info *mtd) | ||
2310 | { | ||
2311 | struct nand_chip *this = mtd->priv; | ||
2312 | |||
2313 | if (this->state == FL_PM_SUSPENDED) | ||
2314 | nand_release_device(mtd); | ||
2315 | else | ||
2316 | printk(KERN_ERR "resume() called for the chip which is not " | ||
2317 | "in suspended state\n"); | ||
2318 | |||
2319 | } | ||
2320 | |||
2321 | |||
2322 | /** | ||
2288 | * nand_scan - [NAND Interface] Scan for the NAND device | 2323 | * nand_scan - [NAND Interface] Scan for the NAND device |
2289 | * @mtd: MTD device structure | 2324 | * @mtd: MTD device structure |
2290 | * @maxchips: Number of chips to scan for | 2325 | * @maxchips: Number of chips to scan for |
@@ -2351,13 +2386,13 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2351 | 2386 | ||
2352 | /* Print and store flash device information */ | 2387 | /* Print and store flash device information */ |
2353 | for (i = 0; nand_flash_ids[i].name != NULL; i++) { | 2388 | for (i = 0; nand_flash_ids[i].name != NULL; i++) { |
2354 | 2389 | ||
2355 | if (nand_dev_id != nand_flash_ids[i].id) | 2390 | if (nand_dev_id != nand_flash_ids[i].id) |
2356 | continue; | 2391 | continue; |
2357 | 2392 | ||
2358 | if (!mtd->name) mtd->name = nand_flash_ids[i].name; | 2393 | if (!mtd->name) mtd->name = nand_flash_ids[i].name; |
2359 | this->chipsize = nand_flash_ids[i].chipsize << 20; | 2394 | this->chipsize = nand_flash_ids[i].chipsize << 20; |
2360 | 2395 | ||
2361 | /* New devices have all the information in additional id bytes */ | 2396 | /* New devices have all the information in additional id bytes */ |
2362 | if (!nand_flash_ids[i].pagesize) { | 2397 | if (!nand_flash_ids[i].pagesize) { |
2363 | int extid; | 2398 | int extid; |
@@ -2369,14 +2404,14 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2369 | mtd->oobblock = 1024 << (extid & 0x3); | 2404 | mtd->oobblock = 1024 << (extid & 0x3); |
2370 | extid >>= 2; | 2405 | extid >>= 2; |
2371 | /* Calc oobsize */ | 2406 | /* Calc oobsize */ |
2372 | mtd->oobsize = (8 << (extid & 0x03)) * (mtd->oobblock / 512); | 2407 | mtd->oobsize = (8 << (extid & 0x01)) * (mtd->oobblock >> 9); |
2373 | extid >>= 2; | 2408 | extid >>= 2; |
2374 | /* Calc blocksize. Blocksize is multiples of 64KiB */ | 2409 | /* Calc blocksize. Blocksize is multiples of 64KiB */ |
2375 | mtd->erasesize = (64 * 1024) << (extid & 0x03); | 2410 | mtd->erasesize = (64 * 1024) << (extid & 0x03); |
2376 | extid >>= 2; | 2411 | extid >>= 2; |
2377 | /* Get buswidth information */ | 2412 | /* Get buswidth information */ |
2378 | busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; | 2413 | busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; |
2379 | 2414 | ||
2380 | } else { | 2415 | } else { |
2381 | /* Old devices have this data hardcoded in the | 2416 | /* Old devices have this data hardcoded in the |
2382 | * device id table */ | 2417 | * device id table */ |
@@ -2396,23 +2431,23 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2396 | * this correct ! */ | 2431 | * this correct ! */ |
2397 | if (busw != (this->options & NAND_BUSWIDTH_16)) { | 2432 | if (busw != (this->options & NAND_BUSWIDTH_16)) { |
2398 | printk (KERN_INFO "NAND device: Manufacturer ID:" | 2433 | printk (KERN_INFO "NAND device: Manufacturer ID:" |
2399 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, | 2434 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, |
2400 | nand_manuf_ids[maf_id].name , mtd->name); | 2435 | nand_manuf_ids[maf_id].name , mtd->name); |
2401 | printk (KERN_WARNING | 2436 | printk (KERN_WARNING |
2402 | "NAND bus width %d instead %d bit\n", | 2437 | "NAND bus width %d instead %d bit\n", |
2403 | (this->options & NAND_BUSWIDTH_16) ? 16 : 8, | 2438 | (this->options & NAND_BUSWIDTH_16) ? 16 : 8, |
2404 | busw ? 16 : 8); | 2439 | busw ? 16 : 8); |
2405 | this->select_chip(mtd, -1); | 2440 | this->select_chip(mtd, -1); |
2406 | return 1; | 2441 | return 1; |
2407 | } | 2442 | } |
2408 | 2443 | ||
2409 | /* Calculate the address shift from the page size */ | 2444 | /* Calculate the address shift from the page size */ |
2410 | this->page_shift = ffs(mtd->oobblock) - 1; | 2445 | this->page_shift = ffs(mtd->oobblock) - 1; |
2411 | this->bbt_erase_shift = this->phys_erase_shift = ffs(mtd->erasesize) - 1; | 2446 | this->bbt_erase_shift = this->phys_erase_shift = ffs(mtd->erasesize) - 1; |
2412 | this->chip_shift = ffs(this->chipsize) - 1; | 2447 | this->chip_shift = ffs(this->chipsize) - 1; |
2413 | 2448 | ||
2414 | /* Set the bad block position */ | 2449 | /* Set the bad block position */ |
2415 | this->badblockpos = mtd->oobblock > 512 ? | 2450 | this->badblockpos = mtd->oobblock > 512 ? |
2416 | NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS; | 2451 | NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS; |
2417 | 2452 | ||
2418 | /* Get chip options, preserve non chip based options */ | 2453 | /* Get chip options, preserve non chip based options */ |
@@ -2422,10 +2457,10 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2422 | this->options |= NAND_NO_AUTOINCR; | 2457 | this->options |= NAND_NO_AUTOINCR; |
2423 | /* Check if this is a not a samsung device. Do not clear the options | 2458 | /* Check if this is a not a samsung device. Do not clear the options |
2424 | * for chips which are not having an extended id. | 2459 | * for chips which are not having an extended id. |
2425 | */ | 2460 | */ |
2426 | if (nand_maf_id != NAND_MFR_SAMSUNG && !nand_flash_ids[i].pagesize) | 2461 | if (nand_maf_id != NAND_MFR_SAMSUNG && !nand_flash_ids[i].pagesize) |
2427 | this->options &= ~NAND_SAMSUNG_LP_OPTIONS; | 2462 | this->options &= ~NAND_SAMSUNG_LP_OPTIONS; |
2428 | 2463 | ||
2429 | /* Check for AND chips with 4 page planes */ | 2464 | /* Check for AND chips with 4 page planes */ |
2430 | if (this->options & NAND_4PAGE_ARRAY) | 2465 | if (this->options & NAND_4PAGE_ARRAY) |
2431 | this->erase_cmd = multi_erase_cmd; | 2466 | this->erase_cmd = multi_erase_cmd; |
@@ -2435,9 +2470,9 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2435 | /* Do not replace user supplied command function ! */ | 2470 | /* Do not replace user supplied command function ! */ |
2436 | if (mtd->oobblock > 512 && this->cmdfunc == nand_command) | 2471 | if (mtd->oobblock > 512 && this->cmdfunc == nand_command) |
2437 | this->cmdfunc = nand_command_lp; | 2472 | this->cmdfunc = nand_command_lp; |
2438 | 2473 | ||
2439 | printk (KERN_INFO "NAND device: Manufacturer ID:" | 2474 | printk (KERN_INFO "NAND device: Manufacturer ID:" |
2440 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, | 2475 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, |
2441 | nand_manuf_ids[maf_id].name , nand_flash_ids[i].name); | 2476 | nand_manuf_ids[maf_id].name , nand_flash_ids[i].name); |
2442 | break; | 2477 | break; |
2443 | } | 2478 | } |
@@ -2461,7 +2496,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2461 | } | 2496 | } |
2462 | if (i > 1) | 2497 | if (i > 1) |
2463 | printk(KERN_INFO "%d NAND chips detected\n", i); | 2498 | printk(KERN_INFO "%d NAND chips detected\n", i); |
2464 | 2499 | ||
2465 | /* Allocate buffers, if neccecary */ | 2500 | /* Allocate buffers, if neccecary */ |
2466 | if (!this->oob_buf) { | 2501 | if (!this->oob_buf) { |
2467 | size_t len; | 2502 | size_t len; |
@@ -2473,7 +2508,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2473 | } | 2508 | } |
2474 | this->options |= NAND_OOBBUF_ALLOC; | 2509 | this->options |= NAND_OOBBUF_ALLOC; |
2475 | } | 2510 | } |
2476 | 2511 | ||
2477 | if (!this->data_buf) { | 2512 | if (!this->data_buf) { |
2478 | size_t len; | 2513 | size_t len; |
2479 | len = mtd->oobblock + mtd->oobsize; | 2514 | len = mtd->oobblock + mtd->oobsize; |
@@ -2500,7 +2535,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2500 | if (!this->autooob) { | 2535 | if (!this->autooob) { |
2501 | /* Select the appropriate default oob placement scheme for | 2536 | /* Select the appropriate default oob placement scheme for |
2502 | * placement agnostic filesystems */ | 2537 | * placement agnostic filesystems */ |
2503 | switch (mtd->oobsize) { | 2538 | switch (mtd->oobsize) { |
2504 | case 8: | 2539 | case 8: |
2505 | this->autooob = &nand_oob_8; | 2540 | this->autooob = &nand_oob_8; |
2506 | break; | 2541 | break; |
@@ -2516,19 +2551,19 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2516 | BUG(); | 2551 | BUG(); |
2517 | } | 2552 | } |
2518 | } | 2553 | } |
2519 | 2554 | ||
2520 | /* The number of bytes available for the filesystem to place fs dependend | 2555 | /* The number of bytes available for the filesystem to place fs dependend |
2521 | * oob data */ | 2556 | * oob data */ |
2522 | mtd->oobavail = 0; | 2557 | mtd->oobavail = 0; |
2523 | for (i = 0; this->autooob->oobfree[i][1]; i++) | 2558 | for (i = 0; this->autooob->oobfree[i][1]; i++) |
2524 | mtd->oobavail += this->autooob->oobfree[i][1]; | 2559 | mtd->oobavail += this->autooob->oobfree[i][1]; |
2525 | 2560 | ||
2526 | /* | 2561 | /* |
2527 | * check ECC mode, default to software | 2562 | * check ECC mode, default to software |
2528 | * if 3byte/512byte hardware ECC is selected and we have 256 byte pagesize | 2563 | * if 3byte/512byte hardware ECC is selected and we have 256 byte pagesize |
2529 | * fallback to software ECC | 2564 | * fallback to software ECC |
2530 | */ | 2565 | */ |
2531 | this->eccsize = 256; /* set default eccsize */ | 2566 | this->eccsize = 256; /* set default eccsize */ |
2532 | this->eccbytes = 3; | 2567 | this->eccbytes = 3; |
2533 | 2568 | ||
2534 | switch (this->eccmode) { | 2569 | switch (this->eccmode) { |
@@ -2543,56 +2578,56 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2543 | this->eccsize = 2048; | 2578 | this->eccsize = 2048; |
2544 | break; | 2579 | break; |
2545 | 2580 | ||
2546 | case NAND_ECC_HW3_512: | 2581 | case NAND_ECC_HW3_512: |
2547 | case NAND_ECC_HW6_512: | 2582 | case NAND_ECC_HW6_512: |
2548 | case NAND_ECC_HW8_512: | 2583 | case NAND_ECC_HW8_512: |
2549 | if (mtd->oobblock == 256) { | 2584 | if (mtd->oobblock == 256) { |
2550 | printk (KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n"); | 2585 | printk (KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n"); |
2551 | this->eccmode = NAND_ECC_SOFT; | 2586 | this->eccmode = NAND_ECC_SOFT; |
2552 | this->calculate_ecc = nand_calculate_ecc; | 2587 | this->calculate_ecc = nand_calculate_ecc; |
2553 | this->correct_data = nand_correct_data; | 2588 | this->correct_data = nand_correct_data; |
2554 | } else | 2589 | } else |
2555 | this->eccsize = 512; /* set eccsize to 512 */ | 2590 | this->eccsize = 512; /* set eccsize to 512 */ |
2556 | break; | 2591 | break; |
2557 | 2592 | ||
2558 | case NAND_ECC_HW3_256: | 2593 | case NAND_ECC_HW3_256: |
2559 | break; | 2594 | break; |
2560 | 2595 | ||
2561 | case NAND_ECC_NONE: | 2596 | case NAND_ECC_NONE: |
2562 | printk (KERN_WARNING "NAND_ECC_NONE selected by board driver. This is not recommended !!\n"); | 2597 | printk (KERN_WARNING "NAND_ECC_NONE selected by board driver. This is not recommended !!\n"); |
2563 | this->eccmode = NAND_ECC_NONE; | 2598 | this->eccmode = NAND_ECC_NONE; |
2564 | break; | 2599 | break; |
2565 | 2600 | ||
2566 | case NAND_ECC_SOFT: | 2601 | case NAND_ECC_SOFT: |
2567 | this->calculate_ecc = nand_calculate_ecc; | 2602 | this->calculate_ecc = nand_calculate_ecc; |
2568 | this->correct_data = nand_correct_data; | 2603 | this->correct_data = nand_correct_data; |
2569 | break; | 2604 | break; |
2570 | 2605 | ||
2571 | default: | 2606 | default: |
2572 | printk (KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode); | 2607 | printk (KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode); |
2573 | BUG(); | 2608 | BUG(); |
2574 | } | 2609 | } |
2575 | 2610 | ||
2576 | /* Check hardware ecc function availability and adjust number of ecc bytes per | 2611 | /* Check hardware ecc function availability and adjust number of ecc bytes per |
2577 | * calculation step | 2612 | * calculation step |
2578 | */ | 2613 | */ |
2579 | switch (this->eccmode) { | 2614 | switch (this->eccmode) { |
2580 | case NAND_ECC_HW12_2048: | 2615 | case NAND_ECC_HW12_2048: |
2581 | this->eccbytes += 4; | 2616 | this->eccbytes += 4; |
2582 | case NAND_ECC_HW8_512: | 2617 | case NAND_ECC_HW8_512: |
2583 | this->eccbytes += 2; | 2618 | this->eccbytes += 2; |
2584 | case NAND_ECC_HW6_512: | 2619 | case NAND_ECC_HW6_512: |
2585 | this->eccbytes += 3; | 2620 | this->eccbytes += 3; |
2586 | case NAND_ECC_HW3_512: | 2621 | case NAND_ECC_HW3_512: |
2587 | case NAND_ECC_HW3_256: | 2622 | case NAND_ECC_HW3_256: |
2588 | if (this->calculate_ecc && this->correct_data && this->enable_hwecc) | 2623 | if (this->calculate_ecc && this->correct_data && this->enable_hwecc) |
2589 | break; | 2624 | break; |
2590 | printk (KERN_WARNING "No ECC functions supplied, Hardware ECC not possible\n"); | 2625 | printk (KERN_WARNING "No ECC functions supplied, Hardware ECC not possible\n"); |
2591 | BUG(); | 2626 | BUG(); |
2592 | } | 2627 | } |
2593 | 2628 | ||
2594 | mtd->eccsize = this->eccsize; | 2629 | mtd->eccsize = this->eccsize; |
2595 | 2630 | ||
2596 | /* Set the number of read / write steps for one page to ensure ECC generation */ | 2631 | /* Set the number of read / write steps for one page to ensure ECC generation */ |
2597 | switch (this->eccmode) { | 2632 | switch (this->eccmode) { |
2598 | case NAND_ECC_HW12_2048: | 2633 | case NAND_ECC_HW12_2048: |
@@ -2604,15 +2639,15 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2604 | this->eccsteps = mtd->oobblock / 512; | 2639 | this->eccsteps = mtd->oobblock / 512; |
2605 | break; | 2640 | break; |
2606 | case NAND_ECC_HW3_256: | 2641 | case NAND_ECC_HW3_256: |
2607 | case NAND_ECC_SOFT: | 2642 | case NAND_ECC_SOFT: |
2608 | this->eccsteps = mtd->oobblock / 256; | 2643 | this->eccsteps = mtd->oobblock / 256; |
2609 | break; | 2644 | break; |
2610 | 2645 | ||
2611 | case NAND_ECC_NONE: | 2646 | case NAND_ECC_NONE: |
2612 | this->eccsteps = 1; | 2647 | this->eccsteps = 1; |
2613 | break; | 2648 | break; |
2614 | } | 2649 | } |
2615 | 2650 | ||
2616 | /* Initialize state, waitqueue and spinlock */ | 2651 | /* Initialize state, waitqueue and spinlock */ |
2617 | this->state = FL_READY; | 2652 | this->state = FL_READY; |
2618 | init_waitqueue_head (&this->wq); | 2653 | init_waitqueue_head (&this->wq); |
@@ -2643,8 +2678,8 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2643 | mtd->sync = nand_sync; | 2678 | mtd->sync = nand_sync; |
2644 | mtd->lock = NULL; | 2679 | mtd->lock = NULL; |
2645 | mtd->unlock = NULL; | 2680 | mtd->unlock = NULL; |
2646 | mtd->suspend = NULL; | 2681 | mtd->suspend = nand_suspend; |
2647 | mtd->resume = NULL; | 2682 | mtd->resume = nand_resume; |
2648 | mtd->block_isbad = nand_block_isbad; | 2683 | mtd->block_isbad = nand_block_isbad; |
2649 | mtd->block_markbad = nand_block_markbad; | 2684 | mtd->block_markbad = nand_block_markbad; |
2650 | 2685 | ||
@@ -2652,7 +2687,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2652 | memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo)); | 2687 | memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo)); |
2653 | 2688 | ||
2654 | mtd->owner = THIS_MODULE; | 2689 | mtd->owner = THIS_MODULE; |
2655 | 2690 | ||
2656 | /* Check, if we should skip the bad block table scan */ | 2691 | /* Check, if we should skip the bad block table scan */ |
2657 | if (this->options & NAND_SKIP_BBTSCAN) | 2692 | if (this->options & NAND_SKIP_BBTSCAN) |
2658 | return 0; | 2693 | return 0; |
@@ -2662,7 +2697,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2662 | } | 2697 | } |
2663 | 2698 | ||
2664 | /** | 2699 | /** |
2665 | * nand_release - [NAND Interface] Free resources held by the NAND device | 2700 | * nand_release - [NAND Interface] Free resources held by the NAND device |
2666 | * @mtd: MTD device structure | 2701 | * @mtd: MTD device structure |
2667 | */ | 2702 | */ |
2668 | void nand_release (struct mtd_info *mtd) | 2703 | void nand_release (struct mtd_info *mtd) |