diff options
author | Brian Norris <norris@broadcom.com> | 2011-05-25 17:59:01 -0400 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@intel.com> | 2011-09-11 08:02:04 -0400 |
commit | 8b6e50c9eba8bf44b2dfd931d359706a461d2cfd (patch) | |
tree | 23f9deda954030fc7d7ab6ffe9c06abb6a1f89de /drivers/mtd/nand | |
parent | 18f8eb1b23619736872740f8c4697b6534a0524b (diff) |
mtd: nand: multi-line comment style fixups
Artem: while on it, do other commentaries clean-ups:
1. Start one-line comments with capital letter and no dot at the end
2. Turn sparse multi-line comments into one-line comments
3. Change "phrase ?" to "phrase?" and the same with "!".
4. Remove tabs from the kerneldoc parameters comments - they are mixed
with tabs often, and inconsistent.
5. Put dot at the end of descriptions in kerneldoc comments.
6. Some other small commentaries clean-ups
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/nand')
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 703 | ||||
-rw-r--r-- | drivers/mtd/nand/nand_bbt.c | 365 |
2 files changed, 521 insertions, 547 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 1380bf6c44c7..1525cd01dacd 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -136,9 +136,9 @@ static int check_offs_len(struct mtd_info *mtd, | |||
136 | 136 | ||
137 | /** | 137 | /** |
138 | * nand_release_device - [GENERIC] release chip | 138 | * nand_release_device - [GENERIC] release chip |
139 | * @mtd: MTD device structure | 139 | * @mtd: MTD device structure |
140 | * | 140 | * |
141 | * Deselect, release chip lock and wake up anyone waiting on the device | 141 | * Deselect, release chip lock and wake up anyone waiting on the device. |
142 | */ | 142 | */ |
143 | static void nand_release_device(struct mtd_info *mtd) | 143 | static void nand_release_device(struct mtd_info *mtd) |
144 | { | 144 | { |
@@ -157,9 +157,9 @@ static void nand_release_device(struct mtd_info *mtd) | |||
157 | 157 | ||
158 | /** | 158 | /** |
159 | * nand_read_byte - [DEFAULT] read one byte from the chip | 159 | * nand_read_byte - [DEFAULT] read one byte from the chip |
160 | * @mtd: MTD device structure | 160 | * @mtd: MTD device structure |
161 | * | 161 | * |
162 | * Default read function for 8bit buswith | 162 | * Default read function for 8bit buswith. |
163 | */ | 163 | */ |
164 | static uint8_t nand_read_byte(struct mtd_info *mtd) | 164 | static uint8_t nand_read_byte(struct mtd_info *mtd) |
165 | { | 165 | { |
@@ -169,10 +169,9 @@ static uint8_t nand_read_byte(struct mtd_info *mtd) | |||
169 | 169 | ||
170 | /** | 170 | /** |
171 | * nand_read_byte16 - [DEFAULT] read one byte endianess aware from the chip | 171 | * nand_read_byte16 - [DEFAULT] read one byte endianess aware from the chip |
172 | * @mtd: MTD device structure | 172 | * @mtd: MTD device structure |
173 | * | 173 | * |
174 | * Default read function for 16bit buswith with | 174 | * Default read function for 16bit buswith with endianess conversion. |
175 | * endianess conversion | ||
176 | */ | 175 | */ |
177 | static uint8_t nand_read_byte16(struct mtd_info *mtd) | 176 | static uint8_t nand_read_byte16(struct mtd_info *mtd) |
178 | { | 177 | { |
@@ -182,10 +181,9 @@ static uint8_t nand_read_byte16(struct mtd_info *mtd) | |||
182 | 181 | ||
183 | /** | 182 | /** |
184 | * nand_read_word - [DEFAULT] read one word from the chip | 183 | * nand_read_word - [DEFAULT] read one word from the chip |
185 | * @mtd: MTD device structure | 184 | * @mtd: MTD device structure |
186 | * | 185 | * |
187 | * Default read function for 16bit buswith without | 186 | * Default read function for 16bit buswith without endianess conversion. |
188 | * endianess conversion | ||
189 | */ | 187 | */ |
190 | static u16 nand_read_word(struct mtd_info *mtd) | 188 | static u16 nand_read_word(struct mtd_info *mtd) |
191 | { | 189 | { |
@@ -195,8 +193,8 @@ static u16 nand_read_word(struct mtd_info *mtd) | |||
195 | 193 | ||
196 | /** | 194 | /** |
197 | * nand_select_chip - [DEFAULT] control CE line | 195 | * nand_select_chip - [DEFAULT] control CE line |
198 | * @mtd: MTD device structure | 196 | * @mtd: MTD device structure |
199 | * @chipnr: chipnumber to select, -1 for deselect | 197 | * @chipnr: chipnumber to select, -1 for deselect |
200 | * | 198 | * |
201 | * Default select function for 1 chip devices. | 199 | * Default select function for 1 chip devices. |
202 | */ | 200 | */ |
@@ -218,11 +216,11 @@ static void nand_select_chip(struct mtd_info *mtd, int chipnr) | |||
218 | 216 | ||
219 | /** | 217 | /** |
220 | * nand_write_buf - [DEFAULT] write buffer to chip | 218 | * nand_write_buf - [DEFAULT] write buffer to chip |
221 | * @mtd: MTD device structure | 219 | * @mtd: MTD device structure |
222 | * @buf: data buffer | 220 | * @buf: data buffer |
223 | * @len: number of bytes to write | 221 | * @len: number of bytes to write |
224 | * | 222 | * |
225 | * Default write function for 8bit buswith | 223 | * Default write function for 8bit buswith. |
226 | */ | 224 | */ |
227 | static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) | 225 | static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) |
228 | { | 226 | { |
@@ -235,11 +233,11 @@ static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) | |||
235 | 233 | ||
236 | /** | 234 | /** |
237 | * nand_read_buf - [DEFAULT] read chip data into buffer | 235 | * nand_read_buf - [DEFAULT] read chip data into buffer |
238 | * @mtd: MTD device structure | 236 | * @mtd: MTD device structure |
239 | * @buf: buffer to store date | 237 | * @buf: buffer to store date |
240 | * @len: number of bytes to read | 238 | * @len: number of bytes to read |
241 | * | 239 | * |
242 | * Default read function for 8bit buswith | 240 | * Default read function for 8bit buswith. |
243 | */ | 241 | */ |
244 | static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) | 242 | static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) |
245 | { | 243 | { |
@@ -252,11 +250,11 @@ static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) | |||
252 | 250 | ||
253 | /** | 251 | /** |
254 | * nand_verify_buf - [DEFAULT] Verify chip data against buffer | 252 | * nand_verify_buf - [DEFAULT] Verify chip data against buffer |
255 | * @mtd: MTD device structure | 253 | * @mtd: MTD device structure |
256 | * @buf: buffer containing the data to compare | 254 | * @buf: buffer containing the data to compare |
257 | * @len: number of bytes to compare | 255 | * @len: number of bytes to compare |
258 | * | 256 | * |
259 | * Default verify function for 8bit buswith | 257 | * Default verify function for 8bit buswith. |
260 | */ | 258 | */ |
261 | static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len) | 259 | static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len) |
262 | { | 260 | { |
@@ -271,11 +269,11 @@ static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len) | |||
271 | 269 | ||
272 | /** | 270 | /** |
273 | * nand_write_buf16 - [DEFAULT] write buffer to chip | 271 | * nand_write_buf16 - [DEFAULT] write buffer to chip |
274 | * @mtd: MTD device structure | 272 | * @mtd: MTD device structure |
275 | * @buf: data buffer | 273 | * @buf: data buffer |
276 | * @len: number of bytes to write | 274 | * @len: number of bytes to write |
277 | * | 275 | * |
278 | * Default write function for 16bit buswith | 276 | * Default write function for 16bit buswith. |
279 | */ | 277 | */ |
280 | static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) | 278 | static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) |
281 | { | 279 | { |
@@ -291,11 +289,11 @@ static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) | |||
291 | 289 | ||
292 | /** | 290 | /** |
293 | * nand_read_buf16 - [DEFAULT] read chip data into buffer | 291 | * nand_read_buf16 - [DEFAULT] read chip data into buffer |
294 | * @mtd: MTD device structure | 292 | * @mtd: MTD device structure |
295 | * @buf: buffer to store date | 293 | * @buf: buffer to store date |
296 | * @len: number of bytes to read | 294 | * @len: number of bytes to read |
297 | * | 295 | * |
298 | * Default read function for 16bit buswith | 296 | * Default read function for 16bit buswith. |
299 | */ | 297 | */ |
300 | static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len) | 298 | static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len) |
301 | { | 299 | { |
@@ -310,11 +308,11 @@ static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len) | |||
310 | 308 | ||
311 | /** | 309 | /** |
312 | * nand_verify_buf16 - [DEFAULT] Verify chip data against buffer | 310 | * nand_verify_buf16 - [DEFAULT] Verify chip data against buffer |
313 | * @mtd: MTD device structure | 311 | * @mtd: MTD device structure |
314 | * @buf: buffer containing the data to compare | 312 | * @buf: buffer containing the data to compare |
315 | * @len: number of bytes to compare | 313 | * @len: number of bytes to compare |
316 | * | 314 | * |
317 | * Default verify function for 16bit buswith | 315 | * Default verify function for 16bit buswith. |
318 | */ | 316 | */ |
319 | static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) | 317 | static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) |
320 | { | 318 | { |
@@ -332,9 +330,9 @@ static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) | |||
332 | 330 | ||
333 | /** | 331 | /** |
334 | * nand_block_bad - [DEFAULT] Read bad block marker from the chip | 332 | * nand_block_bad - [DEFAULT] Read bad block marker from the chip |
335 | * @mtd: MTD device structure | 333 | * @mtd: MTD device structure |
336 | * @ofs: offset from device start | 334 | * @ofs: offset from device start |
337 | * @getchip: 0, if the chip is already selected | 335 | * @getchip: 0, if the chip is already selected |
338 | * | 336 | * |
339 | * Check, if the block is bad. | 337 | * Check, if the block is bad. |
340 | */ | 338 | */ |
@@ -384,11 +382,11 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) | |||
384 | 382 | ||
385 | /** | 383 | /** |
386 | * nand_default_block_markbad - [DEFAULT] mark a block bad | 384 | * nand_default_block_markbad - [DEFAULT] mark a block bad |
387 | * @mtd: MTD device structure | 385 | * @mtd: MTD device structure |
388 | * @ofs: offset from device start | 386 | * @ofs: offset from device start |
389 | * | 387 | * |
390 | * This is the default implementation, which can be overridden by | 388 | * This is the default implementation, which can be overridden by a hardware |
391 | * a hardware specific driver. | 389 | * specific driver. |
392 | */ | 390 | */ |
393 | static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) | 391 | static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) |
394 | { | 392 | { |
@@ -404,7 +402,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) | |||
404 | if (chip->bbt) | 402 | if (chip->bbt) |
405 | chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); | 403 | chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); |
406 | 404 | ||
407 | /* Do we have a flash based bad block table ? */ | 405 | /* Do we have a flash based bad block table? */ |
408 | if (chip->bbt_options & NAND_BBT_USE_FLASH) | 406 | if (chip->bbt_options & NAND_BBT_USE_FLASH) |
409 | ret = nand_update_bbt(mtd, ofs); | 407 | ret = nand_update_bbt(mtd, ofs); |
410 | else { | 408 | else { |
@@ -439,16 +437,16 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) | |||
439 | 437 | ||
440 | /** | 438 | /** |
441 | * nand_check_wp - [GENERIC] check if the chip is write protected | 439 | * nand_check_wp - [GENERIC] check if the chip is write protected |
442 | * @mtd: MTD device structure | 440 | * @mtd: MTD device structure |
443 | * Check, if the device is write protected | ||
444 | * | 441 | * |
445 | * The function expects, that the device is already selected | 442 | * Check, if the device is write protected. The function expects, that the |
443 | * device is already selected. | ||
446 | */ | 444 | */ |
447 | static int nand_check_wp(struct mtd_info *mtd) | 445 | static int nand_check_wp(struct mtd_info *mtd) |
448 | { | 446 | { |
449 | struct nand_chip *chip = mtd->priv; | 447 | struct nand_chip *chip = mtd->priv; |
450 | 448 | ||
451 | /* broken xD cards report WP despite being writable */ | 449 | /* Broken xD cards report WP despite being writable */ |
452 | if (chip->options & NAND_BROKEN_XD) | 450 | if (chip->options & NAND_BROKEN_XD) |
453 | return 0; | 451 | return 0; |
454 | 452 | ||
@@ -459,10 +457,10 @@ static int nand_check_wp(struct mtd_info *mtd) | |||
459 | 457 | ||
460 | /** | 458 | /** |
461 | * nand_block_checkbad - [GENERIC] Check if a block is marked bad | 459 | * nand_block_checkbad - [GENERIC] Check if a block is marked bad |
462 | * @mtd: MTD device structure | 460 | * @mtd: MTD device structure |
463 | * @ofs: offset from device start | 461 | * @ofs: offset from device start |
464 | * @getchip: 0, if the chip is already selected | 462 | * @getchip: 0, if the chip is already selected |
465 | * @allowbbt: 1, if its allowed to access the bbt area | 463 | * @allowbbt: 1, if its allowed to access the bbt area |
466 | * | 464 | * |
467 | * Check, if the block is bad. Either by reading the bad block table or | 465 | * Check, if the block is bad. Either by reading the bad block table or |
468 | * calling of the scan function. | 466 | * calling of the scan function. |
@@ -481,8 +479,8 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, | |||
481 | 479 | ||
482 | /** | 480 | /** |
483 | * panic_nand_wait_ready - [GENERIC] Wait for the ready pin after commands. | 481 | * panic_nand_wait_ready - [GENERIC] Wait for the ready pin after commands. |
484 | * @mtd: MTD device structure | 482 | * @mtd: MTD device structure |
485 | * @timeo: Timeout | 483 | * @timeo: Timeout |
486 | * | 484 | * |
487 | * Helper function for nand_wait_ready used when needing to wait in interrupt | 485 | * Helper function for nand_wait_ready used when needing to wait in interrupt |
488 | * context. | 486 | * context. |
@@ -501,10 +499,7 @@ static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo) | |||
501 | } | 499 | } |
502 | } | 500 | } |
503 | 501 | ||
504 | /* | 502 | /* Wait for the ready pin, after a command. The timeout is catched later */ |
505 | * Wait for the ready pin, after a command | ||
506 | * The timeout is catched later. | ||
507 | */ | ||
508 | void nand_wait_ready(struct mtd_info *mtd) | 503 | void nand_wait_ready(struct mtd_info *mtd) |
509 | { | 504 | { |
510 | struct nand_chip *chip = mtd->priv; | 505 | struct nand_chip *chip = mtd->priv; |
@@ -515,7 +510,7 @@ void nand_wait_ready(struct mtd_info *mtd) | |||
515 | return panic_nand_wait_ready(mtd, 400); | 510 | return panic_nand_wait_ready(mtd, 400); |
516 | 511 | ||
517 | led_trigger_event(nand_led_trigger, LED_FULL); | 512 | led_trigger_event(nand_led_trigger, LED_FULL); |
518 | /* wait until command is processed or timeout occures */ | 513 | /* Wait until command is processed or timeout occures */ |
519 | do { | 514 | do { |
520 | if (chip->dev_ready(mtd)) | 515 | if (chip->dev_ready(mtd)) |
521 | break; | 516 | break; |
@@ -527,13 +522,13 @@ EXPORT_SYMBOL_GPL(nand_wait_ready); | |||
527 | 522 | ||
528 | /** | 523 | /** |
529 | * nand_command - [DEFAULT] Send command to NAND device | 524 | * nand_command - [DEFAULT] Send command to NAND device |
530 | * @mtd: MTD device structure | 525 | * @mtd: MTD device structure |
531 | * @command: the command to be sent | 526 | * @command: the command to be sent |
532 | * @column: the column address for this command, -1 if none | 527 | * @column: the column address for this command, -1 if none |
533 | * @page_addr: the page address for this command, -1 if none | 528 | * @page_addr: the page address for this command, -1 if none |
534 | * | 529 | * |
535 | * Send command to NAND device. This function is used for small page | 530 | * Send command to NAND device. This function is used for small page devices |
536 | * devices (256/512 Bytes per page) | 531 | * (256/512 Bytes per page). |
537 | */ | 532 | */ |
538 | static void nand_command(struct mtd_info *mtd, unsigned int command, | 533 | static void nand_command(struct mtd_info *mtd, unsigned int command, |
539 | int column, int page_addr) | 534 | int column, int page_addr) |
@@ -541,9 +536,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, | |||
541 | register struct nand_chip *chip = mtd->priv; | 536 | register struct nand_chip *chip = mtd->priv; |
542 | int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE; | 537 | int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE; |
543 | 538 | ||
544 | /* | 539 | /* Write out the command to the device */ |
545 | * Write out the command to the device. | ||
546 | */ | ||
547 | if (command == NAND_CMD_SEQIN) { | 540 | if (command == NAND_CMD_SEQIN) { |
548 | int readcmd; | 541 | int readcmd; |
549 | 542 | ||
@@ -563,9 +556,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, | |||
563 | } | 556 | } |
564 | chip->cmd_ctrl(mtd, command, ctrl); | 557 | chip->cmd_ctrl(mtd, command, ctrl); |
565 | 558 | ||
566 | /* | 559 | /* Address cycle, when necessary */ |
567 | * Address cycle, when necessary | ||
568 | */ | ||
569 | ctrl = NAND_CTRL_ALE | NAND_CTRL_CHANGE; | 560 | ctrl = NAND_CTRL_ALE | NAND_CTRL_CHANGE; |
570 | /* Serially input address */ | 561 | /* Serially input address */ |
571 | if (column != -1) { | 562 | if (column != -1) { |
@@ -586,8 +577,8 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, | |||
586 | chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); | 577 | chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); |
587 | 578 | ||
588 | /* | 579 | /* |
589 | * program and erase have their own busy handlers | 580 | * Program and erase have their own busy handlers status and sequential |
590 | * status and sequential in needs no delay | 581 | * in needs no delay |
591 | */ | 582 | */ |
592 | switch (command) { | 583 | switch (command) { |
593 | 584 | ||
@@ -621,8 +612,10 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, | |||
621 | return; | 612 | return; |
622 | } | 613 | } |
623 | } | 614 | } |
624 | /* Apply this short delay always to ensure that we do wait tWB in | 615 | /* |
625 | * any case on any machine. */ | 616 | * Apply this short delay always to ensure that we do wait tWB in |
617 | * any case on any machine. | ||
618 | */ | ||
626 | ndelay(100); | 619 | ndelay(100); |
627 | 620 | ||
628 | nand_wait_ready(mtd); | 621 | nand_wait_ready(mtd); |
@@ -630,10 +623,10 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, | |||
630 | 623 | ||
631 | /** | 624 | /** |
632 | * nand_command_lp - [DEFAULT] Send command to NAND large page device | 625 | * nand_command_lp - [DEFAULT] Send command to NAND large page device |
633 | * @mtd: MTD device structure | 626 | * @mtd: MTD device structure |
634 | * @command: the command to be sent | 627 | * @command: the command to be sent |
635 | * @column: the column address for this command, -1 if none | 628 | * @column: the column address for this command, -1 if none |
636 | * @page_addr: the page address for this command, -1 if none | 629 | * @page_addr: the page address for this command, -1 if none |
637 | * | 630 | * |
638 | * Send command to NAND device. This is the version for the new large page | 631 | * Send command to NAND device. This is the version for the new large page |
639 | * devices We dont have the separate regions as we have in the small page | 632 | * devices We dont have the separate regions as we have in the small page |
@@ -679,8 +672,8 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, | |||
679 | chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); | 672 | chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); |
680 | 673 | ||
681 | /* | 674 | /* |
682 | * program and erase have their own busy handlers | 675 | * Program and erase have their own busy handlers status, sequential |
683 | * status, sequential in, and deplete1 need no delay | 676 | * in, and deplete1 need no delay. |
684 | */ | 677 | */ |
685 | switch (command) { | 678 | switch (command) { |
686 | 679 | ||
@@ -694,14 +687,12 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, | |||
694 | case NAND_CMD_DEPLETE1: | 687 | case NAND_CMD_DEPLETE1: |
695 | return; | 688 | return; |
696 | 689 | ||
697 | /* | ||
698 | * read error status commands require only a short delay | ||
699 | */ | ||
700 | case NAND_CMD_STATUS_ERROR: | 690 | case NAND_CMD_STATUS_ERROR: |
701 | case NAND_CMD_STATUS_ERROR0: | 691 | case NAND_CMD_STATUS_ERROR0: |
702 | case NAND_CMD_STATUS_ERROR1: | 692 | case NAND_CMD_STATUS_ERROR1: |
703 | case NAND_CMD_STATUS_ERROR2: | 693 | case NAND_CMD_STATUS_ERROR2: |
704 | case NAND_CMD_STATUS_ERROR3: | 694 | case NAND_CMD_STATUS_ERROR3: |
695 | /* Read error status commands require only a short delay */ | ||
705 | udelay(chip->chip_delay); | 696 | udelay(chip->chip_delay); |
706 | return; | 697 | return; |
707 | 698 | ||
@@ -735,7 +726,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, | |||
735 | default: | 726 | default: |
736 | /* | 727 | /* |
737 | * If we don't have access to the busy pin, we apply the given | 728 | * If we don't have access to the busy pin, we apply the given |
738 | * command delay | 729 | * command delay. |
739 | */ | 730 | */ |
740 | if (!chip->dev_ready) { | 731 | if (!chip->dev_ready) { |
741 | udelay(chip->chip_delay); | 732 | udelay(chip->chip_delay); |
@@ -743,8 +734,10 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, | |||
743 | } | 734 | } |
744 | } | 735 | } |
745 | 736 | ||
746 | /* Apply this short delay always to ensure that we do wait tWB in | 737 | /* |
747 | * any case on any machine. */ | 738 | * Apply this short delay always to ensure that we do wait tWB in |
739 | * any case on any machine. | ||
740 | */ | ||
748 | ndelay(100); | 741 | ndelay(100); |
749 | 742 | ||
750 | nand_wait_ready(mtd); | 743 | nand_wait_ready(mtd); |
@@ -752,9 +745,9 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, | |||
752 | 745 | ||
753 | /** | 746 | /** |
754 | * panic_nand_get_device - [GENERIC] Get chip for selected access | 747 | * panic_nand_get_device - [GENERIC] Get chip for selected access |
755 | * @chip: the nand chip descriptor | 748 | * @chip: the nand chip descriptor |
756 | * @mtd: MTD device structure | 749 | * @mtd: MTD device structure |
757 | * @new_state: the state which is requested | 750 | * @new_state: the state which is requested |
758 | * | 751 | * |
759 | * Used when in panic, no locks are taken. | 752 | * Used when in panic, no locks are taken. |
760 | */ | 753 | */ |
@@ -768,9 +761,9 @@ static void panic_nand_get_device(struct nand_chip *chip, | |||
768 | 761 | ||
769 | /** | 762 | /** |
770 | * nand_get_device - [GENERIC] Get chip for selected access | 763 | * nand_get_device - [GENERIC] Get chip for selected access |
771 | * @chip: the nand chip descriptor | 764 | * @chip: the nand chip descriptor |
772 | * @mtd: MTD device structure | 765 | * @mtd: MTD device structure |
773 | * @new_state: the state which is requested | 766 | * @new_state: the state which is requested |
774 | * | 767 | * |
775 | * Get the device and lock it for exclusive access | 768 | * Get the device and lock it for exclusive access |
776 | */ | 769 | */ |
@@ -808,10 +801,10 @@ retry: | |||
808 | } | 801 | } |
809 | 802 | ||
810 | /** | 803 | /** |
811 | * panic_nand_wait - [GENERIC] wait until the command is done | 804 | * panic_nand_wait - [GENERIC] wait until the command is done |
812 | * @mtd: MTD device structure | 805 | * @mtd: MTD device structure |
813 | * @chip: NAND chip structure | 806 | * @chip: NAND chip structure |
814 | * @timeo: Timeout | 807 | * @timeo: timeout |
815 | * | 808 | * |
816 | * Wait for command done. This is a helper function for nand_wait used when | 809 | * Wait for command done. This is a helper function for nand_wait used when |
817 | * we are in interrupt context. May happen when in panic and trying to write | 810 | * we are in interrupt context. May happen when in panic and trying to write |
@@ -834,13 +827,13 @@ static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip, | |||
834 | } | 827 | } |
835 | 828 | ||
836 | /** | 829 | /** |
837 | * nand_wait - [DEFAULT] wait until the command is done | 830 | * nand_wait - [DEFAULT] wait until the command is done |
838 | * @mtd: MTD device structure | 831 | * @mtd: MTD device structure |
839 | * @chip: NAND chip structure | 832 | * @chip: NAND chip structure |
840 | * | 833 | * |
841 | * Wait for command done. This applies to erase and program only | 834 | * Wait for command done. This applies to erase and program only. Erase can |
842 | * Erase can take up to 400ms and program up to 20ms according to | 835 | * take up to 400ms and program up to 20ms according to general NAND and |
843 | * general NAND and SmartMedia specs | 836 | * SmartMedia specs. |
844 | */ | 837 | */ |
845 | static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) | 838 | static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) |
846 | { | 839 | { |
@@ -855,8 +848,10 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) | |||
855 | 848 | ||
856 | led_trigger_event(nand_led_trigger, LED_FULL); | 849 | led_trigger_event(nand_led_trigger, LED_FULL); |
857 | 850 | ||
858 | /* Apply this short delay always to ensure that we do wait tWB in | 851 | /* |
859 | * any case on any machine. */ | 852 | * Apply this short delay always to ensure that we do wait tWB in any |
853 | * case on any machine. | ||
854 | */ | ||
860 | ndelay(100); | 855 | ndelay(100); |
861 | 856 | ||
862 | if ((state == FL_ERASING) && (chip->options & NAND_IS_AND)) | 857 | if ((state == FL_ERASING) && (chip->options & NAND_IS_AND)) |
@@ -886,16 +881,15 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) | |||
886 | 881 | ||
887 | /** | 882 | /** |
888 | * __nand_unlock - [REPLACEABLE] unlocks specified locked blocks | 883 | * __nand_unlock - [REPLACEABLE] unlocks specified locked blocks |
889 | * | ||
890 | * @mtd: mtd info | 884 | * @mtd: mtd info |
891 | * @ofs: offset to start unlock from | 885 | * @ofs: offset to start unlock from |
892 | * @len: length to unlock | 886 | * @len: length to unlock |
893 | * @invert: when = 0, unlock the range of blocks within the lower and | 887 | * @invert: when = 0, unlock the range of blocks within the lower and |
894 | * upper boundary address | 888 | * upper boundary address |
895 | * when = 1, unlock the range of blocks outside the boundaries | 889 | * when = 1, unlock the range of blocks outside the boundaries |
896 | * of the lower and upper boundary address | 890 | * of the lower and upper boundary address |
897 | * | 891 | * |
898 | * return - unlock status | 892 | * Returs unlock status. |
899 | */ | 893 | */ |
900 | static int __nand_unlock(struct mtd_info *mtd, loff_t ofs, | 894 | static int __nand_unlock(struct mtd_info *mtd, loff_t ofs, |
901 | uint64_t len, int invert) | 895 | uint64_t len, int invert) |
@@ -927,12 +921,11 @@ static int __nand_unlock(struct mtd_info *mtd, loff_t ofs, | |||
927 | 921 | ||
928 | /** | 922 | /** |
929 | * nand_unlock - [REPLACEABLE] unlocks specified locked blocks | 923 | * nand_unlock - [REPLACEABLE] unlocks specified locked blocks |
930 | * | ||
931 | * @mtd: mtd info | 924 | * @mtd: mtd info |
932 | * @ofs: offset to start unlock from | 925 | * @ofs: offset to start unlock from |
933 | * @len: length to unlock | 926 | * @len: length to unlock |
934 | * | 927 | * |
935 | * return - unlock status | 928 | * Returns unlock status. |
936 | */ | 929 | */ |
937 | int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | 930 | int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) |
938 | { | 931 | { |
@@ -976,18 +969,16 @@ EXPORT_SYMBOL(nand_unlock); | |||
976 | 969 | ||
977 | /** | 970 | /** |
978 | * nand_lock - [REPLACEABLE] locks all blocks present in the device | 971 | * nand_lock - [REPLACEABLE] locks all blocks present in the device |
979 | * | ||
980 | * @mtd: mtd info | 972 | * @mtd: mtd info |
981 | * @ofs: offset to start unlock from | 973 | * @ofs: offset to start unlock from |
982 | * @len: length to unlock | 974 | * @len: length to unlock |
983 | * | 975 | * |
984 | * return - lock status | 976 | * This feature is not supported in many NAND parts. 'Micron' NAND parts do |
985 | * | 977 | * have this feature, but it allows only to lock all blocks, not for specified |
986 | * This feature is not supported in many NAND parts. 'Micron' NAND parts | 978 | * range for block. Implementing 'lock' feature by making use of 'unlock', for |
987 | * do have this feature, but it allows only to lock all blocks, not for | 979 | * now. |
988 | * specified range for block. | ||
989 | * | 980 | * |
990 | * Implementing 'lock' feature by making use of 'unlock', for now. | 981 | * Returns lock status. |
991 | */ | 982 | */ |
992 | int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) | 983 | int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) |
993 | { | 984 | { |
@@ -1042,12 +1033,13 @@ EXPORT_SYMBOL(nand_lock); | |||
1042 | 1033 | ||
1043 | /** | 1034 | /** |
1044 | * nand_read_page_raw - [Intern] read raw page data without ecc | 1035 | * nand_read_page_raw - [Intern] read raw page data without ecc |
1045 | * @mtd: mtd info structure | 1036 | * @mtd: mtd info structure |
1046 | * @chip: nand chip info structure | 1037 | * @chip: nand chip info structure |
1047 | * @buf: buffer to store read data | 1038 | * @buf: buffer to store read data |
1048 | * @page: page number to read | 1039 | * @page: page number to read |
1049 | * | 1040 | * |
1050 | * Not for syndrome calculating ecc controllers, which use a special oob layout | 1041 | * Not for syndrome calculating ecc controllers, which use a special oob |
1042 | * layout. | ||
1051 | */ | 1043 | */ |
1052 | static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, | 1044 | static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, |
1053 | uint8_t *buf, int page) | 1045 | uint8_t *buf, int page) |
@@ -1059,10 +1051,10 @@ static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, | |||
1059 | 1051 | ||
1060 | /** | 1052 | /** |
1061 | * nand_read_page_raw_syndrome - [Intern] read raw page data without ecc | 1053 | * nand_read_page_raw_syndrome - [Intern] read raw page data without ecc |
1062 | * @mtd: mtd info structure | 1054 | * @mtd: mtd info structure |
1063 | * @chip: nand chip info structure | 1055 | * @chip: nand chip info structure |
1064 | * @buf: buffer to store read data | 1056 | * @buf: buffer to store read data |
1065 | * @page: page number to read | 1057 | * @page: page number to read |
1066 | * | 1058 | * |
1067 | * We need a special oob layout and handling even when OOB isn't used. | 1059 | * We need a special oob layout and handling even when OOB isn't used. |
1068 | */ | 1060 | */ |
@@ -1102,10 +1094,10 @@ static int nand_read_page_raw_syndrome(struct mtd_info *mtd, | |||
1102 | 1094 | ||
1103 | /** | 1095 | /** |
1104 | * nand_read_page_swecc - [REPLACABLE] software ecc based page read function | 1096 | * nand_read_page_swecc - [REPLACABLE] software ecc based page read function |
1105 | * @mtd: mtd info structure | 1097 | * @mtd: mtd info structure |
1106 | * @chip: nand chip info structure | 1098 | * @chip: nand chip info structure |
1107 | * @buf: buffer to store read data | 1099 | * @buf: buffer to store read data |
1108 | * @page: page number to read | 1100 | * @page: page number to read |
1109 | */ | 1101 | */ |
1110 | static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, | 1102 | static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, |
1111 | uint8_t *buf, int page) | 1103 | uint8_t *buf, int page) |
@@ -1143,11 +1135,11 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, | |||
1143 | 1135 | ||
1144 | /** | 1136 | /** |
1145 | * nand_read_subpage - [REPLACABLE] software ecc based sub-page read function | 1137 | * nand_read_subpage - [REPLACABLE] software ecc based sub-page read function |
1146 | * @mtd: mtd info structure | 1138 | * @mtd: mtd info structure |
1147 | * @chip: nand chip info structure | 1139 | * @chip: nand chip info structure |
1148 | * @data_offs: offset of requested data within the page | 1140 | * @data_offs: offset of requested data within the page |
1149 | * @readlen: data length | 1141 | * @readlen: data length |
1150 | * @bufpoi: buffer to store read data | 1142 | * @bufpoi: buffer to store read data |
1151 | */ | 1143 | */ |
1152 | static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, | 1144 | static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, |
1153 | uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi) | 1145 | uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi) |
@@ -1160,12 +1152,12 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, | |||
1160 | int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1; | 1152 | int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1; |
1161 | int index = 0; | 1153 | int index = 0; |
1162 | 1154 | ||
1163 | /* Column address wihin the page aligned to ECC size (256bytes). */ | 1155 | /* Column address wihin the page aligned to ECC size (256bytes) */ |
1164 | start_step = data_offs / chip->ecc.size; | 1156 | start_step = data_offs / chip->ecc.size; |
1165 | end_step = (data_offs + readlen - 1) / chip->ecc.size; | 1157 | end_step = (data_offs + readlen - 1) / chip->ecc.size; |
1166 | num_steps = end_step - start_step + 1; | 1158 | num_steps = end_step - start_step + 1; |
1167 | 1159 | ||
1168 | /* Data size aligned to ECC ecc.size*/ | 1160 | /* Data size aligned to ECC ecc.size */ |
1169 | datafrag_len = num_steps * chip->ecc.size; | 1161 | datafrag_len = num_steps * chip->ecc.size; |
1170 | eccfrag_len = num_steps * chip->ecc.bytes; | 1162 | eccfrag_len = num_steps * chip->ecc.bytes; |
1171 | 1163 | ||
@@ -1177,13 +1169,14 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, | |||
1177 | p = bufpoi + data_col_addr; | 1169 | p = bufpoi + data_col_addr; |
1178 | chip->read_buf(mtd, p, datafrag_len); | 1170 | chip->read_buf(mtd, p, datafrag_len); |
1179 | 1171 | ||
1180 | /* Calculate ECC */ | 1172 | /* Calculate ECC */ |
1181 | for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) | 1173 | for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) |
1182 | chip->ecc.calculate(mtd, p, &chip->buffers->ecccalc[i]); | 1174 | chip->ecc.calculate(mtd, p, &chip->buffers->ecccalc[i]); |
1183 | 1175 | ||
1184 | /* The performance is faster if to position offsets | 1176 | /* |
1185 | according to ecc.pos. Let make sure here that | 1177 | * The performance is faster if we position offsets according to |
1186 | there are no gaps in ecc positions */ | 1178 | * ecc.pos. Let's make sure that there are no gaps in ecc positions. |
1179 | */ | ||
1187 | for (i = 0; i < eccfrag_len - 1; i++) { | 1180 | for (i = 0; i < eccfrag_len - 1; i++) { |
1188 | if (eccpos[i + start_step * chip->ecc.bytes] + 1 != | 1181 | if (eccpos[i + start_step * chip->ecc.bytes] + 1 != |
1189 | eccpos[i + start_step * chip->ecc.bytes + 1]) { | 1182 | eccpos[i + start_step * chip->ecc.bytes + 1]) { |
@@ -1195,8 +1188,10 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, | |||
1195 | chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1); | 1188 | chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1); |
1196 | chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); | 1189 | chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); |
1197 | } else { | 1190 | } else { |
1198 | /* send the command to read the particular ecc bytes */ | 1191 | /* |
1199 | /* take care about buswidth alignment in read_buf */ | 1192 | * Send the command to read the particular ecc bytes take care |
1193 | * about buswidth alignment in read_buf. | ||
1194 | */ | ||
1200 | index = start_step * chip->ecc.bytes; | 1195 | index = start_step * chip->ecc.bytes; |
1201 | 1196 | ||
1202 | aligned_pos = eccpos[index] & ~(busw - 1); | 1197 | aligned_pos = eccpos[index] & ~(busw - 1); |
@@ -1230,12 +1225,13 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, | |||
1230 | 1225 | ||
1231 | /** | 1226 | /** |
1232 | * nand_read_page_hwecc - [REPLACABLE] hardware ecc based page read function | 1227 | * nand_read_page_hwecc - [REPLACABLE] hardware ecc based page read function |
1233 | * @mtd: mtd info structure | 1228 | * @mtd: mtd info structure |
1234 | * @chip: nand chip info structure | 1229 | * @chip: nand chip info structure |
1235 | * @buf: buffer to store read data | 1230 | * @buf: buffer to store read data |
1236 | * @page: page number to read | 1231 | * @page: page number to read |
1237 | * | 1232 | * |
1238 | * Not for syndrome calculating ecc controllers which need a special oob layout | 1233 | * Not for syndrome calculating ecc controllers which need a special oob |
1234 | * layout. | ||
1239 | */ | 1235 | */ |
1240 | static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, | 1236 | static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, |
1241 | uint8_t *buf, int page) | 1237 | uint8_t *buf, int page) |
@@ -1275,17 +1271,16 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, | |||
1275 | 1271 | ||
1276 | /** | 1272 | /** |
1277 | * nand_read_page_hwecc_oob_first - [REPLACABLE] hw ecc, read oob first | 1273 | * nand_read_page_hwecc_oob_first - [REPLACABLE] hw ecc, read oob first |
1278 | * @mtd: mtd info structure | 1274 | * @mtd: mtd info structure |
1279 | * @chip: nand chip info structure | 1275 | * @chip: nand chip info structure |
1280 | * @buf: buffer to store read data | 1276 | * @buf: buffer to store read data |
1281 | * @page: page number to read | 1277 | * @page: page number to read |
1282 | * | 1278 | * |
1283 | * Hardware ECC for large page chips, require OOB to be read first. | 1279 | * Hardware ECC for large page chips, require OOB to be read first. For this |
1284 | * For this ECC mode, the write_page method is re-used from ECC_HW. | 1280 | * ECC mode, the write_page method is re-used from ECC_HW. These methods |
1285 | * These methods read/write ECC from the OOB area, unlike the | 1281 | * read/write ECC from the OOB area, unlike the ECC_HW_SYNDROME support with |
1286 | * ECC_HW_SYNDROME support with multiple ECC steps, follows the | 1282 | * multiple ECC steps, follows the "infix ECC" scheme and reads/writes ECC from |
1287 | * "infix ECC" scheme and reads/writes ECC from the data area, by | 1283 | * the data area, by overwriting the NAND manufacturer bad block markings. |
1288 | * overwriting the NAND manufacturer bad block markings. | ||
1289 | */ | 1284 | */ |
1290 | static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, | 1285 | static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, |
1291 | struct nand_chip *chip, uint8_t *buf, int page) | 1286 | struct nand_chip *chip, uint8_t *buf, int page) |
@@ -1324,13 +1319,13 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, | |||
1324 | 1319 | ||
1325 | /** | 1320 | /** |
1326 | * nand_read_page_syndrome - [REPLACABLE] hardware ecc syndrom based page read | 1321 | * nand_read_page_syndrome - [REPLACABLE] hardware ecc syndrom based page read |
1327 | * @mtd: mtd info structure | 1322 | * @mtd: mtd info structure |
1328 | * @chip: nand chip info structure | 1323 | * @chip: nand chip info structure |
1329 | * @buf: buffer to store read data | 1324 | * @buf: buffer to store read data |
1330 | * @page: page number to read | 1325 | * @page: page number to read |
1331 | * | 1326 | * |
1332 | * The hw generator calculates the error syndrome automatically. Therefor | 1327 | * The hw generator calculates the error syndrome automatically. Therefore we |
1333 | * we need a special oob layout and handling. | 1328 | * need a special oob layout and handling. |
1334 | */ | 1329 | */ |
1335 | static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, | 1330 | static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, |
1336 | uint8_t *buf, int page) | 1331 | uint8_t *buf, int page) |
@@ -1379,10 +1374,10 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, | |||
1379 | 1374 | ||
1380 | /** | 1375 | /** |
1381 | * nand_transfer_oob - [Internal] Transfer oob to client buffer | 1376 | * nand_transfer_oob - [Internal] Transfer oob to client buffer |
1382 | * @chip: nand chip structure | 1377 | * @chip: nand chip structure |
1383 | * @oob: oob destination address | 1378 | * @oob: oob destination address |
1384 | * @ops: oob ops structure | 1379 | * @ops: oob ops structure |
1385 | * @len: size of oob to transfer | 1380 | * @len: size of oob to transfer |
1386 | */ | 1381 | */ |
1387 | static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, | 1382 | static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, |
1388 | struct mtd_oob_ops *ops, size_t len) | 1383 | struct mtd_oob_ops *ops, size_t len) |
@@ -1400,7 +1395,7 @@ static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, | |||
1400 | size_t bytes = 0; | 1395 | size_t bytes = 0; |
1401 | 1396 | ||
1402 | for (; free->length && len; free++, len -= bytes) { | 1397 | for (; free->length && len; free++, len -= bytes) { |
1403 | /* Read request not from offset 0 ? */ | 1398 | /* Read request not from offset 0? */ |
1404 | if (unlikely(roffs)) { | 1399 | if (unlikely(roffs)) { |
1405 | if (roffs >= free->length) { | 1400 | if (roffs >= free->length) { |
1406 | roffs -= free->length; | 1401 | roffs -= free->length; |
@@ -1427,10 +1422,9 @@ static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, | |||
1427 | 1422 | ||
1428 | /** | 1423 | /** |
1429 | * nand_do_read_ops - [Internal] Read data with ECC | 1424 | * nand_do_read_ops - [Internal] Read data with ECC |
1430 | * | 1425 | * @mtd: MTD device structure |
1431 | * @mtd: MTD device structure | 1426 | * @from: offset to read from |
1432 | * @from: offset to read from | 1427 | * @ops: oob ops structure |
1433 | * @ops: oob ops structure | ||
1434 | * | 1428 | * |
1435 | * Internal function. Called with chip held. | 1429 | * Internal function. Called with chip held. |
1436 | */ | 1430 | */ |
@@ -1467,7 +1461,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
1467 | bytes = min(mtd->writesize - col, readlen); | 1461 | bytes = min(mtd->writesize - col, readlen); |
1468 | aligned = (bytes == mtd->writesize); | 1462 | aligned = (bytes == mtd->writesize); |
1469 | 1463 | ||
1470 | /* Is the current page in the buffer ? */ | 1464 | /* Is the current page in the buffer? */ |
1471 | if (realpage != chip->pagebuf || oob) { | 1465 | if (realpage != chip->pagebuf || oob) { |
1472 | bufpoi = aligned ? buf : chip->buffers->databuf; | 1466 | bufpoi = aligned ? buf : chip->buffers->databuf; |
1473 | 1467 | ||
@@ -1533,7 +1527,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
1533 | if (!readlen) | 1527 | if (!readlen) |
1534 | break; | 1528 | break; |
1535 | 1529 | ||
1536 | /* For subsequent reads align to page boundary. */ | 1530 | /* For subsequent reads align to page boundary */ |
1537 | col = 0; | 1531 | col = 0; |
1538 | /* Increment page address */ | 1532 | /* Increment page address */ |
1539 | realpage++; | 1533 | realpage++; |
@@ -1546,8 +1540,9 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
1546 | chip->select_chip(mtd, chipnr); | 1540 | chip->select_chip(mtd, chipnr); |
1547 | } | 1541 | } |
1548 | 1542 | ||
1549 | /* Check, if the chip supports auto page increment | 1543 | /* |
1550 | * or if we have hit a block boundary. | 1544 | * Check, if the chip supports auto page increment or if we |
1545 | * have hit a block boundary. | ||
1551 | */ | 1546 | */ |
1552 | if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck)) | 1547 | if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck)) |
1553 | sndcmd = 1; | 1548 | sndcmd = 1; |
@@ -1568,13 +1563,13 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, | |||
1568 | 1563 | ||
1569 | /** | 1564 | /** |
1570 | * nand_read - [MTD Interface] MTD compatibility function for nand_do_read_ecc | 1565 | * nand_read - [MTD Interface] MTD compatibility function for nand_do_read_ecc |
1571 | * @mtd: MTD device structure | 1566 | * @mtd: MTD device structure |
1572 | * @from: offset to read from | 1567 | * @from: offset to read from |
1573 | * @len: number of bytes to read | 1568 | * @len: number of bytes to read |
1574 | * @retlen: pointer to variable to store the number of read bytes | 1569 | * @retlen: pointer to variable to store the number of read bytes |
1575 | * @buf: the databuffer to put data | 1570 | * @buf: the databuffer to put data |
1576 | * | 1571 | * |
1577 | * Get hold of the chip and call nand_do_read | 1572 | * Get hold of the chip and call nand_do_read. |
1578 | */ | 1573 | */ |
1579 | static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, | 1574 | static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, |
1580 | size_t *retlen, uint8_t *buf) | 1575 | size_t *retlen, uint8_t *buf) |
@@ -1605,10 +1600,10 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, | |||
1605 | 1600 | ||
1606 | /** | 1601 | /** |
1607 | * nand_read_oob_std - [REPLACABLE] the most common OOB data read function | 1602 | * nand_read_oob_std - [REPLACABLE] the most common OOB data read function |
1608 | * @mtd: mtd info structure | 1603 | * @mtd: mtd info structure |
1609 | * @chip: nand chip info structure | 1604 | * @chip: nand chip info structure |
1610 | * @page: page number to read | 1605 | * @page: page number to read |
1611 | * @sndcmd: flag whether to issue read command or not | 1606 | * @sndcmd: flag whether to issue read command or not |
1612 | */ | 1607 | */ |
1613 | static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, | 1608 | static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, |
1614 | int page, int sndcmd) | 1609 | int page, int sndcmd) |
@@ -1624,10 +1619,10 @@ static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, | |||
1624 | /** | 1619 | /** |
1625 | * nand_read_oob_syndrome - [REPLACABLE] OOB data read function for HW ECC | 1620 | * nand_read_oob_syndrome - [REPLACABLE] OOB data read function for HW ECC |
1626 | * with syndromes | 1621 | * with syndromes |
1627 | * @mtd: mtd info structure | 1622 | * @mtd: mtd info structure |
1628 | * @chip: nand chip info structure | 1623 | * @chip: nand chip info structure |
1629 | * @page: page number to read | 1624 | * @page: page number to read |
1630 | * @sndcmd: flag whether to issue read command or not | 1625 | * @sndcmd: flag whether to issue read command or not |
1631 | */ | 1626 | */ |
1632 | static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip, | 1627 | static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip, |
1633 | int page, int sndcmd) | 1628 | int page, int sndcmd) |
@@ -1662,9 +1657,9 @@ static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip, | |||
1662 | 1657 | ||
1663 | /** | 1658 | /** |
1664 | * nand_write_oob_std - [REPLACABLE] the most common OOB data write function | 1659 | * nand_write_oob_std - [REPLACABLE] the most common OOB data write function |
1665 | * @mtd: mtd info structure | 1660 | * @mtd: mtd info structure |
1666 | * @chip: nand chip info structure | 1661 | * @chip: nand chip info structure |
1667 | * @page: page number to write | 1662 | * @page: page number to write |
1668 | */ | 1663 | */ |
1669 | static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, | 1664 | static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, |
1670 | int page) | 1665 | int page) |
@@ -1685,10 +1680,10 @@ static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, | |||
1685 | 1680 | ||
1686 | /** | 1681 | /** |
1687 | * nand_write_oob_syndrome - [REPLACABLE] OOB data write function for HW ECC | 1682 | * nand_write_oob_syndrome - [REPLACABLE] OOB data write function for HW ECC |
1688 | * with syndrome - only for large page flash ! | 1683 | * with syndrome - only for large page flash |
1689 | * @mtd: mtd info structure | 1684 | * @mtd: mtd info structure |
1690 | * @chip: nand chip info structure | 1685 | * @chip: nand chip info structure |
1691 | * @page: page number to write | 1686 | * @page: page number to write |
1692 | */ | 1687 | */ |
1693 | static int nand_write_oob_syndrome(struct mtd_info *mtd, | 1688 | static int nand_write_oob_syndrome(struct mtd_info *mtd, |
1694 | struct nand_chip *chip, int page) | 1689 | struct nand_chip *chip, int page) |
@@ -1744,11 +1739,11 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd, | |||
1744 | 1739 | ||
1745 | /** | 1740 | /** |
1746 | * nand_do_read_oob - [Intern] NAND read out-of-band | 1741 | * nand_do_read_oob - [Intern] NAND read out-of-band |
1747 | * @mtd: MTD device structure | 1742 | * @mtd: MTD device structure |
1748 | * @from: offset to read from | 1743 | * @from: offset to read from |
1749 | * @ops: oob operations description structure | 1744 | * @ops: oob operations description structure |
1750 | * | 1745 | * |
1751 | * NAND read out-of-band data from the spare area | 1746 | * NAND read out-of-band data from the spare area. |
1752 | */ | 1747 | */ |
1753 | static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, | 1748 | static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, |
1754 | struct mtd_oob_ops *ops) | 1749 | struct mtd_oob_ops *ops) |
@@ -1824,8 +1819,9 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, | |||
1824 | chip->select_chip(mtd, chipnr); | 1819 | chip->select_chip(mtd, chipnr); |
1825 | } | 1820 | } |
1826 | 1821 | ||
1827 | /* Check, if the chip supports auto page increment | 1822 | /* |
1828 | * or if we have hit a block boundary. | 1823 | * Check, if the chip supports auto page increment or if we |
1824 | * have hit a block boundary. | ||
1829 | */ | 1825 | */ |
1830 | if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck)) | 1826 | if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck)) |
1831 | sndcmd = 1; | 1827 | sndcmd = 1; |
@@ -1837,11 +1833,11 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, | |||
1837 | 1833 | ||
1838 | /** | 1834 | /** |
1839 | * nand_read_oob - [MTD Interface] NAND read data and/or out-of-band | 1835 | * nand_read_oob - [MTD Interface] NAND read data and/or out-of-band |
1840 | * @mtd: MTD device structure | 1836 | * @mtd: MTD device structure |
1841 | * @from: offset to read from | 1837 | * @from: offset to read from |
1842 | * @ops: oob operation description structure | 1838 | * @ops: oob operation description structure |
1843 | * | 1839 | * |
1844 | * NAND read data and/or out-of-band data | 1840 | * NAND read data and/or out-of-band data. |
1845 | */ | 1841 | */ |
1846 | static int nand_read_oob(struct mtd_info *mtd, loff_t from, | 1842 | static int nand_read_oob(struct mtd_info *mtd, loff_t from, |
1847 | struct mtd_oob_ops *ops) | 1843 | struct mtd_oob_ops *ops) |
@@ -1883,11 +1879,12 @@ out: | |||
1883 | 1879 | ||
1884 | /** | 1880 | /** |
1885 | * nand_write_page_raw - [Intern] raw page write function | 1881 | * nand_write_page_raw - [Intern] raw page write function |
1886 | * @mtd: mtd info structure | 1882 | * @mtd: mtd info structure |
1887 | * @chip: nand chip info structure | 1883 | * @chip: nand chip info structure |
1888 | * @buf: data buffer | 1884 | * @buf: data buffer |
1889 | * | 1885 | * |
1890 | * Not for syndrome calculating ecc controllers, which use a special oob layout | 1886 | * Not for syndrome calculating ecc controllers, which use a special oob |
1887 | * layout. | ||
1891 | */ | 1888 | */ |
1892 | static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, | 1889 | static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, |
1893 | const uint8_t *buf) | 1890 | const uint8_t *buf) |
@@ -1898,9 +1895,9 @@ static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, | |||
1898 | 1895 | ||
1899 | /** | 1896 | /** |
1900 | * nand_write_page_raw_syndrome - [Intern] raw page write function | 1897 | * nand_write_page_raw_syndrome - [Intern] raw page write function |
1901 | * @mtd: mtd info structure | 1898 | * @mtd: mtd info structure |
1902 | * @chip: nand chip info structure | 1899 | * @chip: nand chip info structure |
1903 | * @buf: data buffer | 1900 | * @buf: data buffer |
1904 | * | 1901 | * |
1905 | * We need a special oob layout and handling even when ECC isn't checked. | 1902 | * We need a special oob layout and handling even when ECC isn't checked. |
1906 | */ | 1903 | */ |
@@ -1937,9 +1934,9 @@ static void nand_write_page_raw_syndrome(struct mtd_info *mtd, | |||
1937 | } | 1934 | } |
1938 | /** | 1935 | /** |
1939 | * nand_write_page_swecc - [REPLACABLE] software ecc based page write function | 1936 | * nand_write_page_swecc - [REPLACABLE] software ecc based page write function |
1940 | * @mtd: mtd info structure | 1937 | * @mtd: mtd info structure |
1941 | * @chip: nand chip info structure | 1938 | * @chip: nand chip info structure |
1942 | * @buf: data buffer | 1939 | * @buf: data buffer |
1943 | */ | 1940 | */ |
1944 | static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, | 1941 | static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, |
1945 | const uint8_t *buf) | 1942 | const uint8_t *buf) |
@@ -1963,9 +1960,9 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, | |||
1963 | 1960 | ||
1964 | /** | 1961 | /** |
1965 | * nand_write_page_hwecc - [REPLACABLE] hardware ecc based page write function | 1962 | * nand_write_page_hwecc - [REPLACABLE] hardware ecc based page write function |
1966 | * @mtd: mtd info structure | 1963 | * @mtd: mtd info structure |
1967 | * @chip: nand chip info structure | 1964 | * @chip: nand chip info structure |
1968 | * @buf: data buffer | 1965 | * @buf: data buffer |
1969 | */ | 1966 | */ |
1970 | static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, | 1967 | static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, |
1971 | const uint8_t *buf) | 1968 | const uint8_t *buf) |
@@ -1991,12 +1988,12 @@ static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, | |||
1991 | 1988 | ||
1992 | /** | 1989 | /** |
1993 | * nand_write_page_syndrome - [REPLACABLE] hardware ecc syndrom based page write | 1990 | * nand_write_page_syndrome - [REPLACABLE] hardware ecc syndrom based page write |
1994 | * @mtd: mtd info structure | 1991 | * @mtd: mtd info structure |
1995 | * @chip: nand chip info structure | 1992 | * @chip: nand chip info structure |
1996 | * @buf: data buffer | 1993 | * @buf: data buffer |
1997 | * | 1994 | * |
1998 | * The hw generator calculates the error syndrome automatically. Therefor | 1995 | * The hw generator calculates the error syndrome automatically. Therefore we |
1999 | * we need a special oob layout and handling. | 1996 | * need a special oob layout and handling. |
2000 | */ | 1997 | */ |
2001 | static void nand_write_page_syndrome(struct mtd_info *mtd, | 1998 | static void nand_write_page_syndrome(struct mtd_info *mtd, |
2002 | struct nand_chip *chip, const uint8_t *buf) | 1999 | struct nand_chip *chip, const uint8_t *buf) |
@@ -2035,12 +2032,12 @@ static void nand_write_page_syndrome(struct mtd_info *mtd, | |||
2035 | 2032 | ||
2036 | /** | 2033 | /** |
2037 | * nand_write_page - [REPLACEABLE] write one page | 2034 | * nand_write_page - [REPLACEABLE] write one page |
2038 | * @mtd: MTD device structure | 2035 | * @mtd: MTD device structure |
2039 | * @chip: NAND chip descriptor | 2036 | * @chip: NAND chip descriptor |
2040 | * @buf: the data to write | 2037 | * @buf: the data to write |
2041 | * @page: page number to write | 2038 | * @page: page number to write |
2042 | * @cached: cached programming | 2039 | * @cached: cached programming |
2043 | * @raw: use _raw version of write_page | 2040 | * @raw: use _raw version of write_page |
2044 | */ | 2041 | */ |
2045 | static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, | 2042 | static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, |
2046 | const uint8_t *buf, int page, int cached, int raw) | 2043 | const uint8_t *buf, int page, int cached, int raw) |
@@ -2056,7 +2053,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, | |||
2056 | 2053 | ||
2057 | /* | 2054 | /* |
2058 | * Cached progamming disabled for now, Not sure if its worth the | 2055 | * Cached progamming disabled for now, Not sure if its worth the |
2059 | * trouble. The speed gain is not very impressive. (2.3->2.6Mib/s) | 2056 | * trouble. The speed gain is not very impressive. (2.3->2.6Mib/s). |
2060 | */ | 2057 | */ |
2061 | cached = 0; | 2058 | cached = 0; |
2062 | 2059 | ||
@@ -2066,7 +2063,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, | |||
2066 | status = chip->waitfunc(mtd, chip); | 2063 | status = chip->waitfunc(mtd, chip); |
2067 | /* | 2064 | /* |
2068 | * See if operation failed and additional status checks are | 2065 | * See if operation failed and additional status checks are |
2069 | * available | 2066 | * available. |
2070 | */ | 2067 | */ |
2071 | if ((status & NAND_STATUS_FAIL) && (chip->errstat)) | 2068 | if ((status & NAND_STATUS_FAIL) && (chip->errstat)) |
2072 | status = chip->errstat(mtd, chip, FL_WRITING, status, | 2069 | status = chip->errstat(mtd, chip, FL_WRITING, status, |
@@ -2091,10 +2088,10 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, | |||
2091 | 2088 | ||
2092 | /** | 2089 | /** |
2093 | * nand_fill_oob - [Internal] Transfer client buffer to oob | 2090 | * nand_fill_oob - [Internal] Transfer client buffer to oob |
2094 | * @chip: nand chip structure | 2091 | * @chip: nand chip structure |
2095 | * @oob: oob data buffer | 2092 | * @oob: oob data buffer |
2096 | * @len: oob data write length | 2093 | * @len: oob data write length |
2097 | * @ops: oob ops structure | 2094 | * @ops: oob ops structure |
2098 | */ | 2095 | */ |
2099 | static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len, | 2096 | static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len, |
2100 | struct mtd_oob_ops *ops) | 2097 | struct mtd_oob_ops *ops) |
@@ -2112,7 +2109,7 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len, | |||
2112 | size_t bytes = 0; | 2109 | size_t bytes = 0; |
2113 | 2110 | ||
2114 | for (; free->length && len; free++, len -= bytes) { | 2111 | for (; free->length && len; free++, len -= bytes) { |
2115 | /* Write request not from offset 0 ? */ | 2112 | /* Write request not from offset 0? */ |
2116 | if (unlikely(woffs)) { | 2113 | if (unlikely(woffs)) { |
2117 | if (woffs >= free->length) { | 2114 | if (woffs >= free->length) { |
2118 | woffs -= free->length; | 2115 | woffs -= free->length; |
@@ -2141,11 +2138,11 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len, | |||
2141 | 2138 | ||
2142 | /** | 2139 | /** |
2143 | * nand_do_write_ops - [Internal] NAND write with ECC | 2140 | * nand_do_write_ops - [Internal] NAND write with ECC |
2144 | * @mtd: MTD device structure | 2141 | * @mtd: MTD device structure |
2145 | * @to: offset to write to | 2142 | * @to: offset to write to |
2146 | * @ops: oob operations description structure | 2143 | * @ops: oob operations description structure |
2147 | * | 2144 | * |
2148 | * NAND write with ECC | 2145 | * NAND write with ECC. |
2149 | */ | 2146 | */ |
2150 | static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | 2147 | static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, |
2151 | struct mtd_oob_ops *ops) | 2148 | struct mtd_oob_ops *ops) |
@@ -2166,7 +2163,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | |||
2166 | if (!writelen) | 2163 | if (!writelen) |
2167 | return 0; | 2164 | return 0; |
2168 | 2165 | ||
2169 | /* reject writes, which are not page aligned */ | 2166 | /* Reject writes, which are not page aligned */ |
2170 | if (NOTALIGNED(to) || NOTALIGNED(ops->len)) { | 2167 | if (NOTALIGNED(to) || NOTALIGNED(ops->len)) { |
2171 | printk(KERN_NOTICE "%s: Attempt to write not " | 2168 | printk(KERN_NOTICE "%s: Attempt to write not " |
2172 | "page aligned data\n", __func__); | 2169 | "page aligned data\n", __func__); |
@@ -2208,7 +2205,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | |||
2208 | int cached = writelen > bytes && page != blockmask; | 2205 | int cached = writelen > bytes && page != blockmask; |
2209 | uint8_t *wbuf = buf; | 2206 | uint8_t *wbuf = buf; |
2210 | 2207 | ||
2211 | /* Partial page write ? */ | 2208 | /* Partial page write? */ |
2212 | if (unlikely(column || writelen < (mtd->writesize - 1))) { | 2209 | if (unlikely(column || writelen < (mtd->writesize - 1))) { |
2213 | cached = 0; | 2210 | cached = 0; |
2214 | bytes = min_t(int, bytes - column, (int) writelen); | 2211 | bytes = min_t(int, bytes - column, (int) writelen); |
@@ -2254,11 +2251,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | |||
2254 | 2251 | ||
2255 | /** | 2252 | /** |
2256 | * panic_nand_write - [MTD Interface] NAND write with ECC | 2253 | * panic_nand_write - [MTD Interface] NAND write with ECC |
2257 | * @mtd: MTD device structure | 2254 | * @mtd: MTD device structure |
2258 | * @to: offset to write to | 2255 | * @to: offset to write to |
2259 | * @len: number of bytes to write | 2256 | * @len: number of bytes to write |
2260 | * @retlen: pointer to variable to store the number of written bytes | 2257 | * @retlen: pointer to variable to store the number of written bytes |
2261 | * @buf: the data to write | 2258 | * @buf: the data to write |
2262 | * | 2259 | * |
2263 | * NAND write with ECC. Used when performing writes in interrupt context, this | 2260 | * NAND write with ECC. Used when performing writes in interrupt context, this |
2264 | * may for example be called by mtdoops when writing an oops while in panic. | 2261 | * may for example be called by mtdoops when writing an oops while in panic. |
@@ -2275,10 +2272,10 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
2275 | if (!len) | 2272 | if (!len) |
2276 | return 0; | 2273 | return 0; |
2277 | 2274 | ||
2278 | /* Wait for the device to get ready. */ | 2275 | /* Wait for the device to get ready */ |
2279 | panic_nand_wait(mtd, chip, 400); | 2276 | panic_nand_wait(mtd, chip, 400); |
2280 | 2277 | ||
2281 | /* Grab the device. */ | 2278 | /* Grab the device */ |
2282 | panic_nand_get_device(chip, mtd, FL_WRITING); | 2279 | panic_nand_get_device(chip, mtd, FL_WRITING); |
2283 | 2280 | ||
2284 | chip->ops.len = len; | 2281 | chip->ops.len = len; |
@@ -2293,13 +2290,13 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
2293 | 2290 | ||
2294 | /** | 2291 | /** |
2295 | * nand_write - [MTD Interface] NAND write with ECC | 2292 | * nand_write - [MTD Interface] NAND write with ECC |
2296 | * @mtd: MTD device structure | 2293 | * @mtd: MTD device structure |
2297 | * @to: offset to write to | 2294 | * @to: offset to write to |
2298 | * @len: number of bytes to write | 2295 | * @len: number of bytes to write |
2299 | * @retlen: pointer to variable to store the number of written bytes | 2296 | * @retlen: pointer to variable to store the number of written bytes |
2300 | * @buf: the data to write | 2297 | * @buf: the data to write |
2301 | * | 2298 | * |
2302 | * NAND write with ECC | 2299 | * NAND write with ECC. |
2303 | */ | 2300 | */ |
2304 | static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, | 2301 | static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, |
2305 | size_t *retlen, const uint8_t *buf) | 2302 | size_t *retlen, const uint8_t *buf) |
@@ -2330,11 +2327,11 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
2330 | 2327 | ||
2331 | /** | 2328 | /** |
2332 | * nand_do_write_oob - [MTD Interface] NAND write out-of-band | 2329 | * nand_do_write_oob - [MTD Interface] NAND write out-of-band |
2333 | * @mtd: MTD device structure | 2330 | * @mtd: MTD device structure |
2334 | * @to: offset to write to | 2331 | * @to: offset to write to |
2335 | * @ops: oob operation description structure | 2332 | * @ops: oob operation description structure |
2336 | * | 2333 | * |
2337 | * NAND write out-of-band | 2334 | * NAND write out-of-band. |
2338 | */ | 2335 | */ |
2339 | static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, | 2336 | static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, |
2340 | struct mtd_oob_ops *ops) | 2337 | struct mtd_oob_ops *ops) |
@@ -2410,9 +2407,9 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, | |||
2410 | 2407 | ||
2411 | /** | 2408 | /** |
2412 | * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band | 2409 | * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band |
2413 | * @mtd: MTD device structure | 2410 | * @mtd: MTD device structure |
2414 | * @to: offset to write to | 2411 | * @to: offset to write to |
2415 | * @ops: oob operation description structure | 2412 | * @ops: oob operation description structure |
2416 | */ | 2413 | */ |
2417 | static int nand_write_oob(struct mtd_info *mtd, loff_t to, | 2414 | static int nand_write_oob(struct mtd_info *mtd, loff_t to, |
2418 | struct mtd_oob_ops *ops) | 2415 | struct mtd_oob_ops *ops) |
@@ -2453,10 +2450,10 @@ out: | |||
2453 | 2450 | ||
2454 | /** | 2451 | /** |
2455 | * single_erease_cmd - [GENERIC] NAND standard block erase command function | 2452 | * single_erease_cmd - [GENERIC] NAND standard block erase command function |
2456 | * @mtd: MTD device structure | 2453 | * @mtd: MTD device structure |
2457 | * @page: the page address of the block which will be erased | 2454 | * @page: the page address of the block which will be erased |
2458 | * | 2455 | * |
2459 | * Standard erase command for NAND chips | 2456 | * Standard erase command for NAND chips. |
2460 | */ | 2457 | */ |
2461 | static void single_erase_cmd(struct mtd_info *mtd, int page) | 2458 | static void single_erase_cmd(struct mtd_info *mtd, int page) |
2462 | { | 2459 | { |
@@ -2468,11 +2465,10 @@ static void single_erase_cmd(struct mtd_info *mtd, int page) | |||
2468 | 2465 | ||
2469 | /** | 2466 | /** |
2470 | * multi_erease_cmd - [GENERIC] AND specific block erase command function | 2467 | * multi_erease_cmd - [GENERIC] AND specific block erase command function |
2471 | * @mtd: MTD device structure | 2468 | * @mtd: MTD device structure |
2472 | * @page: the page address of the block which will be erased | 2469 | * @page: the page address of the block which will be erased |
2473 | * | 2470 | * |
2474 | * AND multi block erase command function | 2471 | * AND multi block erase command function. Erase 4 consecutive blocks. |
2475 | * Erase 4 consecutive blocks | ||
2476 | */ | 2472 | */ |
2477 | static void multi_erase_cmd(struct mtd_info *mtd, int page) | 2473 | static void multi_erase_cmd(struct mtd_info *mtd, int page) |
2478 | { | 2474 | { |
@@ -2487,10 +2483,10 @@ static void multi_erase_cmd(struct mtd_info *mtd, int page) | |||
2487 | 2483 | ||
2488 | /** | 2484 | /** |
2489 | * nand_erase - [MTD Interface] erase block(s) | 2485 | * nand_erase - [MTD Interface] erase block(s) |
2490 | * @mtd: MTD device structure | 2486 | * @mtd: MTD device structure |
2491 | * @instr: erase instruction | 2487 | * @instr: erase instruction |
2492 | * | 2488 | * |
2493 | * Erase one ore more blocks | 2489 | * Erase one ore more blocks. |
2494 | */ | 2490 | */ |
2495 | static int nand_erase(struct mtd_info *mtd, struct erase_info *instr) | 2491 | static int nand_erase(struct mtd_info *mtd, struct erase_info *instr) |
2496 | { | 2492 | { |
@@ -2500,11 +2496,11 @@ static int nand_erase(struct mtd_info *mtd, struct erase_info *instr) | |||
2500 | #define BBT_PAGE_MASK 0xffffff3f | 2496 | #define BBT_PAGE_MASK 0xffffff3f |
2501 | /** | 2497 | /** |
2502 | * nand_erase_nand - [Internal] erase block(s) | 2498 | * nand_erase_nand - [Internal] erase block(s) |
2503 | * @mtd: MTD device structure | 2499 | * @mtd: MTD device structure |
2504 | * @instr: erase instruction | 2500 | * @instr: erase instruction |
2505 | * @allowbbt: allow erasing the bbt area | 2501 | * @allowbbt: allow erasing the bbt area |
2506 | * | 2502 | * |
2507 | * Erase one ore more blocks | 2503 | * Erase one ore more blocks. |
2508 | */ | 2504 | */ |
2509 | int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | 2505 | int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, |
2510 | int allowbbt) | 2506 | int allowbbt) |
@@ -2549,7 +2545,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | |||
2549 | * If BBT requires refresh, set the BBT page mask to see if the BBT | 2545 | * If BBT requires refresh, set the BBT page mask to see if the BBT |
2550 | * should be rewritten. Otherwise the mask is set to 0xffffffff which | 2546 | * should be rewritten. Otherwise the mask is set to 0xffffffff which |
2551 | * can not be matched. This is also done when the bbt is actually | 2547 | * can not be matched. This is also done when the bbt is actually |
2552 | * erased to avoid recusrsive updates | 2548 | * erased to avoid recusrsive updates. |
2553 | */ | 2549 | */ |
2554 | if (chip->options & BBT_AUTO_REFRESH && !allowbbt) | 2550 | if (chip->options & BBT_AUTO_REFRESH && !allowbbt) |
2555 | bbt_masked_page = chip->bbt_td->pages[chipnr] & BBT_PAGE_MASK; | 2551 | bbt_masked_page = chip->bbt_td->pages[chipnr] & BBT_PAGE_MASK; |
@@ -2560,9 +2556,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | |||
2560 | instr->state = MTD_ERASING; | 2556 | instr->state = MTD_ERASING; |
2561 | 2557 | ||
2562 | while (len) { | 2558 | while (len) { |
2563 | /* | 2559 | /* Heck if we have a bad block, we do not erase bad blocks! */ |
2564 | * heck if we have a bad block, we do not erase bad blocks ! | ||
2565 | */ | ||
2566 | if (nand_block_checkbad(mtd, ((loff_t) page) << | 2560 | if (nand_block_checkbad(mtd, ((loff_t) page) << |
2567 | chip->page_shift, 0, allowbbt)) { | 2561 | chip->page_shift, 0, allowbbt)) { |
2568 | printk(KERN_WARNING "%s: attempt to erase a bad block " | 2562 | printk(KERN_WARNING "%s: attempt to erase a bad block " |
@@ -2573,7 +2567,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | |||
2573 | 2567 | ||
2574 | /* | 2568 | /* |
2575 | * Invalidate the page cache, if we erase the block which | 2569 | * Invalidate the page cache, if we erase the block which |
2576 | * contains the current cached page | 2570 | * contains the current cached page. |
2577 | */ | 2571 | */ |
2578 | if (page <= chip->pagebuf && chip->pagebuf < | 2572 | if (page <= chip->pagebuf && chip->pagebuf < |
2579 | (page + pages_per_block)) | 2573 | (page + pages_per_block)) |
@@ -2603,7 +2597,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | |||
2603 | 2597 | ||
2604 | /* | 2598 | /* |
2605 | * If BBT requires refresh, set the BBT rewrite flag to the | 2599 | * If BBT requires refresh, set the BBT rewrite flag to the |
2606 | * page being erased | 2600 | * page being erased. |
2607 | */ | 2601 | */ |
2608 | if (bbt_masked_page != 0xffffffff && | 2602 | if (bbt_masked_page != 0xffffffff && |
2609 | (page & BBT_PAGE_MASK) == bbt_masked_page) | 2603 | (page & BBT_PAGE_MASK) == bbt_masked_page) |
@@ -2622,7 +2616,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, | |||
2622 | 2616 | ||
2623 | /* | 2617 | /* |
2624 | * If BBT requires refresh and BBT-PERCHIP, set the BBT | 2618 | * If BBT requires refresh and BBT-PERCHIP, set the BBT |
2625 | * page mask to see if this BBT should be rewritten | 2619 | * page mask to see if this BBT should be rewritten. |
2626 | */ | 2620 | */ |
2627 | if (bbt_masked_page != 0xffffffff && | 2621 | if (bbt_masked_page != 0xffffffff && |
2628 | (chip->bbt_td->options & NAND_BBT_PERCHIP)) | 2622 | (chip->bbt_td->options & NAND_BBT_PERCHIP)) |
@@ -2645,7 +2639,7 @@ erase_exit: | |||
2645 | 2639 | ||
2646 | /* | 2640 | /* |
2647 | * If BBT requires refresh and erase was successful, rewrite any | 2641 | * If BBT requires refresh and erase was successful, rewrite any |
2648 | * selected bad block tables | 2642 | * selected bad block tables. |
2649 | */ | 2643 | */ |
2650 | if (bbt_masked_page == 0xffffffff || ret) | 2644 | if (bbt_masked_page == 0xffffffff || ret) |
2651 | return ret; | 2645 | return ret; |
@@ -2653,7 +2647,7 @@ erase_exit: | |||
2653 | for (chipnr = 0; chipnr < chip->numchips; chipnr++) { | 2647 | for (chipnr = 0; chipnr < chip->numchips; chipnr++) { |
2654 | if (!rewrite_bbt[chipnr]) | 2648 | if (!rewrite_bbt[chipnr]) |
2655 | continue; | 2649 | continue; |
2656 | /* update the BBT for chip */ | 2650 | /* Update the BBT for chip */ |
2657 | DEBUG(MTD_DEBUG_LEVEL0, "%s: nand_update_bbt " | 2651 | DEBUG(MTD_DEBUG_LEVEL0, "%s: nand_update_bbt " |
2658 | "(%d:0x%0llx 0x%0x)\n", __func__, chipnr, | 2652 | "(%d:0x%0llx 0x%0x)\n", __func__, chipnr, |
2659 | rewrite_bbt[chipnr], chip->bbt_td->pages[chipnr]); | 2653 | rewrite_bbt[chipnr], chip->bbt_td->pages[chipnr]); |
@@ -2666,9 +2660,9 @@ erase_exit: | |||
2666 | 2660 | ||
2667 | /** | 2661 | /** |
2668 | * nand_sync - [MTD Interface] sync | 2662 | * nand_sync - [MTD Interface] sync |
2669 | * @mtd: MTD device structure | 2663 | * @mtd: MTD device structure |
2670 | * | 2664 | * |
2671 | * Sync is actually a wait for chip ready function | 2665 | * Sync is actually a wait for chip ready function. |
2672 | */ | 2666 | */ |
2673 | static void nand_sync(struct mtd_info *mtd) | 2667 | static void nand_sync(struct mtd_info *mtd) |
2674 | { | 2668 | { |
@@ -2684,8 +2678,8 @@ static void nand_sync(struct mtd_info *mtd) | |||
2684 | 2678 | ||
2685 | /** | 2679 | /** |
2686 | * nand_block_isbad - [MTD Interface] Check if block at offset is bad | 2680 | * nand_block_isbad - [MTD Interface] Check if block at offset is bad |
2687 | * @mtd: MTD device structure | 2681 | * @mtd: MTD device structure |
2688 | * @offs: offset relative to mtd start | 2682 | * @offs: offset relative to mtd start |
2689 | */ | 2683 | */ |
2690 | static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) | 2684 | static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) |
2691 | { | 2685 | { |
@@ -2698,8 +2692,8 @@ static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) | |||
2698 | 2692 | ||
2699 | /** | 2693 | /** |
2700 | * nand_block_markbad - [MTD Interface] Mark block at the given offset as bad | 2694 | * nand_block_markbad - [MTD Interface] Mark block at the given offset as bad |
2701 | * @mtd: MTD device structure | 2695 | * @mtd: MTD device structure |
2702 | * @ofs: offset relative to mtd start | 2696 | * @ofs: offset relative to mtd start |
2703 | */ | 2697 | */ |
2704 | static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) | 2698 | static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) |
2705 | { | 2699 | { |
@@ -2708,7 +2702,7 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) | |||
2708 | 2702 | ||
2709 | ret = nand_block_isbad(mtd, ofs); | 2703 | ret = nand_block_isbad(mtd, ofs); |
2710 | if (ret) { | 2704 | if (ret) { |
2711 | /* If it was bad already, return success and do nothing. */ | 2705 | /* If it was bad already, return success and do nothing */ |
2712 | if (ret > 0) | 2706 | if (ret > 0) |
2713 | return 0; | 2707 | return 0; |
2714 | return ret; | 2708 | return ret; |
@@ -2719,7 +2713,7 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) | |||
2719 | 2713 | ||
2720 | /** | 2714 | /** |
2721 | * nand_suspend - [MTD Interface] Suspend the NAND flash | 2715 | * nand_suspend - [MTD Interface] Suspend the NAND flash |
2722 | * @mtd: MTD device structure | 2716 | * @mtd: MTD device structure |
2723 | */ | 2717 | */ |
2724 | static int nand_suspend(struct mtd_info *mtd) | 2718 | static int nand_suspend(struct mtd_info *mtd) |
2725 | { | 2719 | { |
@@ -2730,7 +2724,7 @@ static int nand_suspend(struct mtd_info *mtd) | |||
2730 | 2724 | ||
2731 | /** | 2725 | /** |
2732 | * nand_resume - [MTD Interface] Resume the NAND flash | 2726 | * nand_resume - [MTD Interface] Resume the NAND flash |
2733 | * @mtd: MTD device structure | 2727 | * @mtd: MTD device structure |
2734 | */ | 2728 | */ |
2735 | static void nand_resume(struct mtd_info *mtd) | 2729 | static void nand_resume(struct mtd_info *mtd) |
2736 | { | 2730 | { |
@@ -2743,9 +2737,7 @@ static void nand_resume(struct mtd_info *mtd) | |||
2743 | "in suspended state\n", __func__); | 2737 | "in suspended state\n", __func__); |
2744 | } | 2738 | } |
2745 | 2739 | ||
2746 | /* | 2740 | /* Set default functions */ |
2747 | * Set default functions | ||
2748 | */ | ||
2749 | static void nand_set_defaults(struct nand_chip *chip, int busw) | 2741 | static void nand_set_defaults(struct nand_chip *chip, int busw) |
2750 | { | 2742 | { |
2751 | /* check for proper chip_delay setup, set 20us if not */ | 2743 | /* check for proper chip_delay setup, set 20us if not */ |
@@ -2787,23 +2779,21 @@ static void nand_set_defaults(struct nand_chip *chip, int busw) | |||
2787 | 2779 | ||
2788 | } | 2780 | } |
2789 | 2781 | ||
2790 | /* | 2782 | /* Sanitize ONFI strings so we can safely print them */ |
2791 | * sanitize ONFI strings so we can safely print them | ||
2792 | */ | ||
2793 | static void sanitize_string(uint8_t *s, size_t len) | 2783 | static void sanitize_string(uint8_t *s, size_t len) |
2794 | { | 2784 | { |
2795 | ssize_t i; | 2785 | ssize_t i; |
2796 | 2786 | ||
2797 | /* null terminate */ | 2787 | /* Null terminate */ |
2798 | s[len - 1] = 0; | 2788 | s[len - 1] = 0; |
2799 | 2789 | ||
2800 | /* remove non printable chars */ | 2790 | /* Remove non printable chars */ |
2801 | for (i = 0; i < len - 1; i++) { | 2791 | for (i = 0; i < len - 1; i++) { |
2802 | if (s[i] < ' ' || s[i] > 127) | 2792 | if (s[i] < ' ' || s[i] > 127) |
2803 | s[i] = '?'; | 2793 | s[i] = '?'; |
2804 | } | 2794 | } |
2805 | 2795 | ||
2806 | /* remove trailing spaces */ | 2796 | /* Remove trailing spaces */ |
2807 | strim(s); | 2797 | strim(s); |
2808 | } | 2798 | } |
2809 | 2799 | ||
@@ -2820,7 +2810,7 @@ static u16 onfi_crc16(u16 crc, u8 const *p, size_t len) | |||
2820 | } | 2810 | } |
2821 | 2811 | ||
2822 | /* | 2812 | /* |
2823 | * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise | 2813 | * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. |
2824 | */ | 2814 | */ |
2825 | static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | 2815 | static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, |
2826 | int busw) | 2816 | int busw) |
@@ -2829,7 +2819,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |||
2829 | int i; | 2819 | int i; |
2830 | int val; | 2820 | int val; |
2831 | 2821 | ||
2832 | /* try ONFI for unknow chip or LP */ | 2822 | /* Try ONFI for unknow chip or LP */ |
2833 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x20, -1); | 2823 | chip->cmdfunc(mtd, NAND_CMD_READID, 0x20, -1); |
2834 | if (chip->read_byte(mtd) != 'O' || chip->read_byte(mtd) != 'N' || | 2824 | if (chip->read_byte(mtd) != 'O' || chip->read_byte(mtd) != 'N' || |
2835 | chip->read_byte(mtd) != 'F' || chip->read_byte(mtd) != 'I') | 2825 | chip->read_byte(mtd) != 'F' || chip->read_byte(mtd) != 'I') |
@@ -2849,7 +2839,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |||
2849 | if (i == 3) | 2839 | if (i == 3) |
2850 | return 0; | 2840 | return 0; |
2851 | 2841 | ||
2852 | /* check version */ | 2842 | /* Check version */ |
2853 | val = le16_to_cpu(p->revision); | 2843 | val = le16_to_cpu(p->revision); |
2854 | if (val & (1 << 5)) | 2844 | if (val & (1 << 5)) |
2855 | chip->onfi_version = 23; | 2845 | chip->onfi_version = 23; |
@@ -2890,7 +2880,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, | |||
2890 | } | 2880 | } |
2891 | 2881 | ||
2892 | /* | 2882 | /* |
2893 | * Get the flash and manufacturer id and lookup if the type is supported | 2883 | * Get the flash and manufacturer id and lookup if the type is supported. |
2894 | */ | 2884 | */ |
2895 | static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | 2885 | static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, |
2896 | struct nand_chip *chip, | 2886 | struct nand_chip *chip, |
@@ -2907,7 +2897,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | |||
2907 | 2897 | ||
2908 | /* | 2898 | /* |
2909 | * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) | 2899 | * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) |
2910 | * after power-up | 2900 | * after power-up. |
2911 | */ | 2901 | */ |
2912 | chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); | 2902 | chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); |
2913 | 2903 | ||
@@ -2918,7 +2908,8 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | |||
2918 | *maf_id = chip->read_byte(mtd); | 2908 | *maf_id = chip->read_byte(mtd); |
2919 | *dev_id = chip->read_byte(mtd); | 2909 | *dev_id = chip->read_byte(mtd); |
2920 | 2910 | ||
2921 | /* Try again to make sure, as some systems the bus-hold or other | 2911 | /* |
2912 | * Try again to make sure, as some systems the bus-hold or other | ||
2922 | * interface concerns can cause random data which looks like a | 2913 | * interface concerns can cause random data which looks like a |
2923 | * possibly credible NAND flash to appear. If the two results do | 2914 | * possibly credible NAND flash to appear. If the two results do |
2924 | * not match, ignore the device completely. | 2915 | * not match, ignore the device completely. |
@@ -2967,7 +2958,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | |||
2967 | chip->chipsize = (uint64_t)type->chipsize << 20; | 2958 | chip->chipsize = (uint64_t)type->chipsize << 20; |
2968 | 2959 | ||
2969 | if (!type->pagesize && chip->init_size) { | 2960 | if (!type->pagesize && chip->init_size) { |
2970 | /* set the pagesize, oobsize, erasesize by the driver*/ | 2961 | /* Set the pagesize, oobsize, erasesize by the driver */ |
2971 | busw = chip->init_size(mtd, chip, id_data); | 2962 | busw = chip->init_size(mtd, chip, id_data); |
2972 | } else if (!type->pagesize) { | 2963 | } else if (!type->pagesize) { |
2973 | int extid; | 2964 | int extid; |
@@ -3027,7 +3018,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | |||
3027 | } | 3018 | } |
3028 | } else { | 3019 | } else { |
3029 | /* | 3020 | /* |
3030 | * Old devices have chip data hardcoded in the device id table | 3021 | * Old devices have chip data hardcoded in the device id table. |
3031 | */ | 3022 | */ |
3032 | mtd->erasesize = type->erasesize; | 3023 | mtd->erasesize = type->erasesize; |
3033 | mtd->writesize = type->pagesize; | 3024 | mtd->writesize = type->pagesize; |
@@ -3037,7 +3028,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | |||
3037 | /* | 3028 | /* |
3038 | * Check for Spansion/AMD ID + repeating 5th, 6th byte since | 3029 | * Check for Spansion/AMD ID + repeating 5th, 6th byte since |
3039 | * some Spansion chips have erasesize that conflicts with size | 3030 | * some Spansion chips have erasesize that conflicts with size |
3040 | * listed in nand_ids table | 3031 | * listed in nand_ids table. |
3041 | * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39) | 3032 | * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39) |
3042 | */ | 3033 | */ |
3043 | if (*maf_id == NAND_MFR_AMD && id_data[4] != 0x00 && | 3034 | if (*maf_id == NAND_MFR_AMD && id_data[4] != 0x00 && |
@@ -3051,15 +3042,16 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, | |||
3051 | chip->options &= ~NAND_CHIPOPTIONS_MSK; | 3042 | chip->options &= ~NAND_CHIPOPTIONS_MSK; |
3052 | chip->options |= type->options & NAND_CHIPOPTIONS_MSK; | 3043 | chip->options |= type->options & NAND_CHIPOPTIONS_MSK; |
3053 | 3044 | ||
3054 | /* Check if chip is a not a samsung device. Do not clear the | 3045 | /* |
3055 | * options for chips which are not having an extended id. | 3046 | * Check if chip is not a Samsung device. Do not clear the |
3047 | * options for chips which do not have an extended id. | ||
3056 | */ | 3048 | */ |
3057 | if (*maf_id != NAND_MFR_SAMSUNG && !type->pagesize) | 3049 | if (*maf_id != NAND_MFR_SAMSUNG && !type->pagesize) |
3058 | chip->options &= ~NAND_SAMSUNG_LP_OPTIONS; | 3050 | chip->options &= ~NAND_SAMSUNG_LP_OPTIONS; |
3059 | ident_done: | 3051 | ident_done: |
3060 | 3052 | ||
3061 | /* | 3053 | /* |
3062 | * Set chip as a default. Board drivers can override it, if necessary | 3054 | * Set chip as a default. Board drivers can override it, if necessary. |
3063 | */ | 3055 | */ |
3064 | chip->options |= NAND_NO_AUTOINCR; | 3056 | chip->options |= NAND_NO_AUTOINCR; |
3065 | 3057 | ||
@@ -3071,7 +3063,7 @@ ident_done: | |||
3071 | 3063 | ||
3072 | /* | 3064 | /* |
3073 | * Check, if buswidth is correct. Hardware drivers should set | 3065 | * Check, if buswidth is correct. Hardware drivers should set |
3074 | * chip correct ! | 3066 | * chip correct! |
3075 | */ | 3067 | */ |
3076 | if (busw != (chip->options & NAND_BUSWIDTH_16)) { | 3068 | if (busw != (chip->options & NAND_BUSWIDTH_16)) { |
3077 | printk(KERN_INFO "NAND device: Manufacturer ID:" | 3069 | printk(KERN_INFO "NAND device: Manufacturer ID:" |
@@ -3085,7 +3077,7 @@ ident_done: | |||
3085 | 3077 | ||
3086 | /* Calculate the address shift from the page size */ | 3078 | /* Calculate the address shift from the page size */ |
3087 | chip->page_shift = ffs(mtd->writesize) - 1; | 3079 | chip->page_shift = ffs(mtd->writesize) - 1; |
3088 | /* Convert chipsize to number of pages per chip -1. */ | 3080 | /* Convert chipsize to number of pages per chip -1 */ |
3089 | chip->pagemask = (chip->chipsize >> chip->page_shift) - 1; | 3081 | chip->pagemask = (chip->chipsize >> chip->page_shift) - 1; |
3090 | 3082 | ||
3091 | chip->bbt_erase_shift = chip->phys_erase_shift = | 3083 | chip->bbt_erase_shift = chip->phys_erase_shift = |
@@ -3131,7 +3123,7 @@ ident_done: | |||
3131 | else | 3123 | else |
3132 | chip->erase_cmd = single_erase_cmd; | 3124 | chip->erase_cmd = single_erase_cmd; |
3133 | 3125 | ||
3134 | /* Do not replace user supplied command function ! */ | 3126 | /* Do not replace user supplied command function! */ |
3135 | if (mtd->writesize > 512 && chip->cmdfunc == nand_command) | 3127 | if (mtd->writesize > 512 && chip->cmdfunc == nand_command) |
3136 | chip->cmdfunc = nand_command_lp; | 3128 | chip->cmdfunc = nand_command_lp; |
3137 | 3129 | ||
@@ -3145,12 +3137,12 @@ ident_done: | |||
3145 | 3137 | ||
3146 | /** | 3138 | /** |
3147 | * nand_scan_ident - [NAND Interface] Scan for the NAND device | 3139 | * nand_scan_ident - [NAND Interface] Scan for the NAND device |
3148 | * @mtd: MTD device structure | 3140 | * @mtd: MTD device structure |
3149 | * @maxchips: Number of chips to scan for | 3141 | * @maxchips: number of chips to scan for |
3150 | * @table: Alternative NAND ID table | 3142 | * @table: alternative NAND ID table |
3151 | * | 3143 | * |
3152 | * This is the first phase of the normal nand_scan() function. It | 3144 | * This is the first phase of the normal nand_scan() function. It reads the |
3153 | * reads the flash ID and sets up MTD fields accordingly. | 3145 | * flash ID and sets up MTD fields accordingly. |
3154 | * | 3146 | * |
3155 | * The mtd->owner field must be set to the module of the caller. | 3147 | * The mtd->owner field must be set to the module of the caller. |
3156 | */ | 3148 | */ |
@@ -3203,11 +3195,11 @@ EXPORT_SYMBOL(nand_scan_ident); | |||
3203 | 3195 | ||
3204 | /** | 3196 | /** |
3205 | * nand_scan_tail - [NAND Interface] Scan for the NAND device | 3197 | * nand_scan_tail - [NAND Interface] Scan for the NAND device |
3206 | * @mtd: MTD device structure | 3198 | * @mtd: MTD device structure |
3207 | * | 3199 | * |
3208 | * This is the second phase of the normal nand_scan() function. It | 3200 | * This is the second phase of the normal nand_scan() function. It fills out |
3209 | * fills out all the uninitialized function pointers with the defaults | 3201 | * all the uninitialized function pointers with the defaults and scans for a |
3210 | * and scans for a bad block table if appropriate. | 3202 | * bad block table if appropriate. |
3211 | */ | 3203 | */ |
3212 | int nand_scan_tail(struct mtd_info *mtd) | 3204 | int nand_scan_tail(struct mtd_info *mtd) |
3213 | { | 3205 | { |
@@ -3223,7 +3215,7 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3223 | chip->oob_poi = chip->buffers->databuf + mtd->writesize; | 3215 | chip->oob_poi = chip->buffers->databuf + mtd->writesize; |
3224 | 3216 | ||
3225 | /* | 3217 | /* |
3226 | * If no default placement scheme is given, select an appropriate one | 3218 | * If no default placement scheme is given, select an appropriate one. |
3227 | */ | 3219 | */ |
3228 | if (!chip->ecc.layout && (chip->ecc.mode != NAND_ECC_SOFT_BCH)) { | 3220 | if (!chip->ecc.layout && (chip->ecc.mode != NAND_ECC_SOFT_BCH)) { |
3229 | switch (mtd->oobsize) { | 3221 | switch (mtd->oobsize) { |
@@ -3250,7 +3242,7 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3250 | chip->write_page = nand_write_page; | 3242 | chip->write_page = nand_write_page; |
3251 | 3243 | ||
3252 | /* | 3244 | /* |
3253 | * check ECC mode, default to software if 3byte/512byte hardware ECC is | 3245 | * Check ECC mode, default to software if 3byte/512byte hardware ECC is |
3254 | * selected and we have 256 byte pagesize fallback to software ECC | 3246 | * selected and we have 256 byte pagesize fallback to software ECC |
3255 | */ | 3247 | */ |
3256 | 3248 | ||
@@ -3267,7 +3259,7 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3267 | chip->ecc.read_page = nand_read_page_hwecc_oob_first; | 3259 | chip->ecc.read_page = nand_read_page_hwecc_oob_first; |
3268 | 3260 | ||
3269 | case NAND_ECC_HW: | 3261 | case NAND_ECC_HW: |
3270 | /* Use standard hwecc read page function ? */ | 3262 | /* Use standard hwecc read page function? */ |
3271 | if (!chip->ecc.read_page) | 3263 | if (!chip->ecc.read_page) |
3272 | chip->ecc.read_page = nand_read_page_hwecc; | 3264 | chip->ecc.read_page = nand_read_page_hwecc; |
3273 | if (!chip->ecc.write_page) | 3265 | if (!chip->ecc.write_page) |
@@ -3292,7 +3284,7 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3292 | "Hardware ECC not possible\n"); | 3284 | "Hardware ECC not possible\n"); |
3293 | BUG(); | 3285 | BUG(); |
3294 | } | 3286 | } |
3295 | /* Use standard syndrome read/write page function ? */ | 3287 | /* Use standard syndrome read/write page function? */ |
3296 | if (!chip->ecc.read_page) | 3288 | if (!chip->ecc.read_page) |
3297 | chip->ecc.read_page = nand_read_page_syndrome; | 3289 | chip->ecc.read_page = nand_read_page_syndrome; |
3298 | if (!chip->ecc.write_page) | 3290 | if (!chip->ecc.write_page) |
@@ -3345,8 +3337,8 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3345 | /* | 3337 | /* |
3346 | * Board driver should supply ecc.size and ecc.bytes values to | 3338 | * Board driver should supply ecc.size and ecc.bytes values to |
3347 | * select how many bits are correctable; see nand_bch_init() | 3339 | * select how many bits are correctable; see nand_bch_init() |
3348 | * for details. | 3340 | * for details. Otherwise, default to 4 bits for large page |
3349 | * Otherwise, default to 4 bits for large page devices | 3341 | * devices. |
3350 | */ | 3342 | */ |
3351 | if (!chip->ecc.size && (mtd->oobsize >= 64)) { | 3343 | if (!chip->ecc.size && (mtd->oobsize >= 64)) { |
3352 | chip->ecc.size = 512; | 3344 | chip->ecc.size = 512; |
@@ -3383,7 +3375,7 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3383 | 3375 | ||
3384 | /* | 3376 | /* |
3385 | * The number of bytes available for a client to place data into | 3377 | * The number of bytes available for a client to place data into |
3386 | * the out of band area | 3378 | * the out of band area. |
3387 | */ | 3379 | */ |
3388 | chip->ecc.layout->oobavail = 0; | 3380 | chip->ecc.layout->oobavail = 0; |
3389 | for (i = 0; chip->ecc.layout->oobfree[i].length | 3381 | for (i = 0; chip->ecc.layout->oobfree[i].length |
@@ -3394,7 +3386,7 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3394 | 3386 | ||
3395 | /* | 3387 | /* |
3396 | * Set the number of read / write steps for one page depending on ECC | 3388 | * Set the number of read / write steps for one page depending on ECC |
3397 | * mode | 3389 | * mode. |
3398 | */ | 3390 | */ |
3399 | chip->ecc.steps = mtd->writesize / chip->ecc.size; | 3391 | chip->ecc.steps = mtd->writesize / chip->ecc.size; |
3400 | if (chip->ecc.steps * chip->ecc.size != mtd->writesize) { | 3392 | if (chip->ecc.steps * chip->ecc.size != mtd->writesize) { |
@@ -3403,10 +3395,7 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3403 | } | 3395 | } |
3404 | chip->ecc.total = chip->ecc.steps * chip->ecc.bytes; | 3396 | chip->ecc.total = chip->ecc.steps * chip->ecc.bytes; |
3405 | 3397 | ||
3406 | /* | 3398 | /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */ |
3407 | * Allow subpage writes up to ecc.steps. Not possible for MLC | ||
3408 | * FLASH. | ||
3409 | */ | ||
3410 | if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && | 3399 | if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && |
3411 | !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) { | 3400 | !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) { |
3412 | switch (chip->ecc.steps) { | 3401 | switch (chip->ecc.steps) { |
@@ -3464,9 +3453,11 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
3464 | } | 3453 | } |
3465 | EXPORT_SYMBOL(nand_scan_tail); | 3454 | EXPORT_SYMBOL(nand_scan_tail); |
3466 | 3455 | ||
3467 | /* is_module_text_address() isn't exported, and it's mostly a pointless | 3456 | /* |
3457 | * is_module_text_address() isn't exported, and it's mostly a pointless | ||
3468 | * test if this is a module _anyway_ -- they'd have to try _really_ hard | 3458 | * test if this is a module _anyway_ -- they'd have to try _really_ hard |
3469 | * to call us from in-kernel code if the core NAND support is modular. */ | 3459 | * to call us from in-kernel code if the core NAND support is modular. |
3460 | */ | ||
3470 | #ifdef MODULE | 3461 | #ifdef MODULE |
3471 | #define caller_is_module() (1) | 3462 | #define caller_is_module() (1) |
3472 | #else | 3463 | #else |
@@ -3476,15 +3467,13 @@ EXPORT_SYMBOL(nand_scan_tail); | |||
3476 | 3467 | ||
3477 | /** | 3468 | /** |
3478 | * nand_scan - [NAND Interface] Scan for the NAND device | 3469 | * nand_scan - [NAND Interface] Scan for the NAND device |
3479 | * @mtd: MTD device structure | 3470 | * @mtd: MTD device structure |
3480 | * @maxchips: Number of chips to scan for | 3471 | * @maxchips: number of chips to scan for |
3481 | * | ||
3482 | * This fills out all the uninitialized function pointers | ||
3483 | * with the defaults. | ||
3484 | * The flash ID is read and the mtd/chip structures are | ||
3485 | * filled with the appropriate values. | ||
3486 | * The mtd->owner field must be set to the module of the caller | ||
3487 | * | 3472 | * |
3473 | * This fills out all the uninitialized function pointers with the defaults. | ||
3474 | * The flash ID is read and the mtd/chip structures are filled with the | ||
3475 | * appropriate values. The mtd->owner field must be set to the module of the | ||
3476 | * caller. | ||
3488 | */ | 3477 | */ |
3489 | int nand_scan(struct mtd_info *mtd, int maxchips) | 3478 | int nand_scan(struct mtd_info *mtd, int maxchips) |
3490 | { | 3479 | { |
@@ -3506,8 +3495,8 @@ EXPORT_SYMBOL(nand_scan); | |||
3506 | 3495 | ||
3507 | /** | 3496 | /** |
3508 | * nand_release - [NAND Interface] Free resources held by the NAND device | 3497 | * nand_release - [NAND Interface] Free resources held by the NAND device |
3509 | * @mtd: MTD device structure | 3498 | * @mtd: MTD device structure |
3510 | */ | 3499 | */ |
3511 | void nand_release(struct mtd_info *mtd) | 3500 | void nand_release(struct mtd_info *mtd) |
3512 | { | 3501 | { |
3513 | struct nand_chip *chip = mtd->priv; | 3502 | struct nand_chip *chip = mtd->priv; |
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index 9af703def4aa..ba401662835e 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c | |||
@@ -80,17 +80,15 @@ static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td) | |||
80 | 80 | ||
81 | /** | 81 | /** |
82 | * check_pattern - [GENERIC] check if a pattern is in the buffer | 82 | * check_pattern - [GENERIC] check if a pattern is in the buffer |
83 | * @buf: the buffer to search | 83 | * @buf: the buffer to search |
84 | * @len: the length of buffer to search | 84 | * @len: the length of buffer to search |
85 | * @paglen: the pagelength | 85 | * @paglen: the pagelength |
86 | * @td: search pattern descriptor | 86 | * @td: search pattern descriptor |
87 | * | 87 | * |
88 | * Check for a pattern at the given place. Used to search bad block | 88 | * Check for a pattern at the given place. Used to search bad block tables and |
89 | * tables and good / bad block identifiers. | 89 | * good / bad block identifiers. If the SCAN_EMPTY option is set then check, if |
90 | * If the SCAN_EMPTY option is set then check, if all bytes except the | 90 | * all bytes except the pattern area contain 0xff. |
91 | * pattern area contain 0xff | 91 | */ |
92 | * | ||
93 | */ | ||
94 | static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) | 92 | static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) |
95 | { | 93 | { |
96 | int i, end = 0; | 94 | int i, end = 0; |
@@ -127,14 +125,13 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc | |||
127 | 125 | ||
128 | /** | 126 | /** |
129 | * check_short_pattern - [GENERIC] check if a pattern is in the buffer | 127 | * check_short_pattern - [GENERIC] check if a pattern is in the buffer |
130 | * @buf: the buffer to search | 128 | * @buf: the buffer to search |
131 | * @td: search pattern descriptor | 129 | * @td: search pattern descriptor |
132 | * | ||
133 | * Check for a pattern at the given place. Used to search bad block | ||
134 | * tables and good / bad block identifiers. Same as check_pattern, but | ||
135 | * no optional empty check | ||
136 | * | 130 | * |
137 | */ | 131 | * Check for a pattern at the given place. Used to search bad block tables and |
132 | * good / bad block identifiers. Same as check_pattern, but no optional empty | ||
133 | * check. | ||
134 | */ | ||
138 | static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) | 135 | static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) |
139 | { | 136 | { |
140 | int i; | 137 | int i; |
@@ -150,7 +147,7 @@ static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) | |||
150 | 147 | ||
151 | /** | 148 | /** |
152 | * add_marker_len - compute the length of the marker in data area | 149 | * add_marker_len - compute the length of the marker in data area |
153 | * @td: BBT descriptor used for computation | 150 | * @td: BBT descriptor used for computation |
154 | * | 151 | * |
155 | * The length will be 0 if the markeris located in OOB area. | 152 | * The length will be 0 if the markeris located in OOB area. |
156 | */ | 153 | */ |
@@ -169,15 +166,14 @@ static u32 add_marker_len(struct nand_bbt_descr *td) | |||
169 | 166 | ||
170 | /** | 167 | /** |
171 | * read_bbt - [GENERIC] Read the bad block table starting from page | 168 | * read_bbt - [GENERIC] Read the bad block table starting from page |
172 | * @mtd: MTD device structure | 169 | * @mtd: MTD device structure |
173 | * @buf: temporary buffer | 170 | * @buf: temporary buffer |
174 | * @page: the starting page | 171 | * @page: the starting page |
175 | * @num: the number of bbt descriptors to read | 172 | * @num: the number of bbt descriptors to read |
176 | * @td: the bbt describtion table | 173 | * @td: the bbt describtion table |
177 | * @offs: offset in the memory table | 174 | * @offs: offset in the memory table |
178 | * | 175 | * |
179 | * Read the bad block table starting from page. | 176 | * Read the bad block table starting from page. |
180 | * | ||
181 | */ | 177 | */ |
182 | static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, | 178 | static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, |
183 | struct nand_bbt_descr *td, int offs) | 179 | struct nand_bbt_descr *td, int offs) |
@@ -229,11 +225,13 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, | |||
229 | mtd->ecc_stats.bbtblocks++; | 225 | mtd->ecc_stats.bbtblocks++; |
230 | continue; | 226 | continue; |
231 | } | 227 | } |
232 | /* Leave it for now, if its matured we can move this | 228 | /* |
233 | * message to MTD_DEBUG_LEVEL0 */ | 229 | * Leave it for now, if it's matured we can |
230 | * move this message to MTD_DEBUG_LEVEL0. | ||
231 | */ | ||
234 | printk(KERN_DEBUG "nand_read_bbt: Bad block at 0x%012llx\n", | 232 | printk(KERN_DEBUG "nand_read_bbt: Bad block at 0x%012llx\n", |
235 | (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift); | 233 | (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift); |
236 | /* Factory marked bad or worn out ? */ | 234 | /* Factory marked bad or worn out? */ |
237 | if (tmp == 0) | 235 | if (tmp == 0) |
238 | this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06); | 236 | this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06); |
239 | else | 237 | else |
@@ -249,15 +247,15 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, | |||
249 | 247 | ||
250 | /** | 248 | /** |
251 | * read_abs_bbt - [GENERIC] Read the bad block table starting at a given page | 249 | * read_abs_bbt - [GENERIC] Read the bad block table starting at a given page |
252 | * @mtd: MTD device structure | 250 | * @mtd: MTD device structure |
253 | * @buf: temporary buffer | 251 | * @buf: temporary buffer |
254 | * @td: descriptor for the bad block table | 252 | * @td: descriptor for the bad block table |
255 | * @chip: read the table for a specific chip, -1 read all chips. | 253 | * @chip: read the table for a specific chip, -1 read all chips; aplies only if |
256 | * Applies only if NAND_BBT_PERCHIP option is set | 254 | * NAND_BBT_PERCHIP option is set |
257 | * | 255 | * |
258 | * Read the bad block table for all chips starting at a given page | 256 | * Read the bad block table for all chips starting at a given page. We assume |
259 | * We assume that the bbt bits are in consecutive order. | 257 | * that the bbt bits are in consecutive order. |
260 | */ | 258 | */ |
261 | static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip) | 259 | static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip) |
262 | { | 260 | { |
263 | struct nand_chip *this = mtd->priv; | 261 | struct nand_chip *this = mtd->priv; |
@@ -283,9 +281,7 @@ static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc | |||
283 | return 0; | 281 | return 0; |
284 | } | 282 | } |
285 | 283 | ||
286 | /* | 284 | /* BBT marker is in the first page, no OOB */ |
287 | * BBT marker is in the first page, no OOB. | ||
288 | */ | ||
289 | static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs, | 285 | static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs, |
290 | struct nand_bbt_descr *td) | 286 | struct nand_bbt_descr *td) |
291 | { | 287 | { |
@@ -299,9 +295,7 @@ static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs, | |||
299 | return mtd->read(mtd, offs, len, &retlen, buf); | 295 | return mtd->read(mtd, offs, len, &retlen, buf); |
300 | } | 296 | } |
301 | 297 | ||
302 | /* | 298 | /* Scan read raw data from flash */ |
303 | * Scan read raw data from flash | ||
304 | */ | ||
305 | static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs, | 299 | static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs, |
306 | size_t len) | 300 | size_t len) |
307 | { | 301 | { |
@@ -344,9 +338,7 @@ static int scan_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t offs, | |||
344 | return scan_read_raw_oob(mtd, buf, offs, len); | 338 | return scan_read_raw_oob(mtd, buf, offs, len); |
345 | } | 339 | } |
346 | 340 | ||
347 | /* | 341 | /* Scan write data with oob to flash */ |
348 | * Scan write data with oob to flash | ||
349 | */ | ||
350 | static int scan_write_bbt(struct mtd_info *mtd, loff_t offs, size_t len, | 342 | static int scan_write_bbt(struct mtd_info *mtd, loff_t offs, size_t len, |
351 | uint8_t *buf, uint8_t *oob) | 343 | uint8_t *buf, uint8_t *oob) |
352 | { | 344 | { |
@@ -373,15 +365,14 @@ static u32 bbt_get_ver_offs(struct mtd_info *mtd, struct nand_bbt_descr *td) | |||
373 | 365 | ||
374 | /** | 366 | /** |
375 | * read_abs_bbts - [GENERIC] Read the bad block table(s) for all chips starting at a given page | 367 | * read_abs_bbts - [GENERIC] Read the bad block table(s) for all chips starting at a given page |
376 | * @mtd: MTD device structure | 368 | * @mtd: MTD device structure |
377 | * @buf: temporary buffer | 369 | * @buf: temporary buffer |
378 | * @td: descriptor for the bad block table | 370 | * @td: descriptor for the bad block table |
379 | * @md: descriptor for the bad block table mirror | 371 | * @md: descriptor for the bad block table mirror |
380 | * | ||
381 | * Read the bad block table(s) for all chips starting at a given page | ||
382 | * We assume that the bbt bits are in consecutive order. | ||
383 | * | 372 | * |
384 | */ | 373 | * Read the bad block table(s) for all chips starting at a given page. We |
374 | * assume that the bbt bits are in consecutive order. | ||
375 | */ | ||
385 | static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, | 376 | static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, |
386 | struct nand_bbt_descr *td, struct nand_bbt_descr *md) | 377 | struct nand_bbt_descr *td, struct nand_bbt_descr *md) |
387 | { | 378 | { |
@@ -407,9 +398,7 @@ static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, | |||
407 | return 1; | 398 | return 1; |
408 | } | 399 | } |
409 | 400 | ||
410 | /* | 401 | /* Scan a given block full */ |
411 | * Scan a given block full | ||
412 | */ | ||
413 | static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd, | 402 | static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd, |
414 | loff_t offs, uint8_t *buf, size_t readlen, | 403 | loff_t offs, uint8_t *buf, size_t readlen, |
415 | int scanlen, int len) | 404 | int scanlen, int len) |
@@ -427,9 +416,7 @@ static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd, | |||
427 | return 0; | 416 | return 0; |
428 | } | 417 | } |
429 | 418 | ||
430 | /* | 419 | /* Scan a given block partially */ |
431 | * Scan a given block partially | ||
432 | */ | ||
433 | static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, | 420 | static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, |
434 | loff_t offs, uint8_t *buf, int len) | 421 | loff_t offs, uint8_t *buf, int len) |
435 | { | 422 | { |
@@ -444,9 +431,8 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, | |||
444 | 431 | ||
445 | for (j = 0; j < len; j++) { | 432 | for (j = 0; j < len; j++) { |
446 | /* | 433 | /* |
447 | * Read the full oob until read_oob is fixed to | 434 | * Read the full oob until read_oob is fixed to handle single |
448 | * handle single byte reads for 16 bit | 435 | * byte reads for 16 bit buswidth. |
449 | * buswidth | ||
450 | */ | 436 | */ |
451 | ret = mtd->read_oob(mtd, offs, &ops); | 437 | ret = mtd->read_oob(mtd, offs, &ops); |
452 | if (ret) | 438 | if (ret) |
@@ -462,14 +448,14 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, | |||
462 | 448 | ||
463 | /** | 449 | /** |
464 | * create_bbt - [GENERIC] Create a bad block table by scanning the device | 450 | * create_bbt - [GENERIC] Create a bad block table by scanning the device |
465 | * @mtd: MTD device structure | 451 | * @mtd: MTD device structure |
466 | * @buf: temporary buffer | 452 | * @buf: temporary buffer |
467 | * @bd: descriptor for the good/bad block search pattern | 453 | * @bd: descriptor for the good/bad block search pattern |
468 | * @chip: create the table for a specific chip, -1 read all chips. | 454 | * @chip: create the table for a specific chip, -1 read all chips; applies only |
469 | * Applies only if NAND_BBT_PERCHIP option is set | 455 | * if NAND_BBT_PERCHIP option is set |
470 | * | 456 | * |
471 | * Create a bad block table by scanning the device | 457 | * Create a bad block table by scanning the device for the given good/bad block |
472 | * for the given good/bad block identify pattern | 458 | * identify pattern. |
473 | */ | 459 | */ |
474 | static int create_bbt(struct mtd_info *mtd, uint8_t *buf, | 460 | static int create_bbt(struct mtd_info *mtd, uint8_t *buf, |
475 | struct nand_bbt_descr *bd, int chip) | 461 | struct nand_bbt_descr *bd, int chip) |
@@ -500,8 +486,10 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
500 | } | 486 | } |
501 | 487 | ||
502 | if (chip == -1) { | 488 | if (chip == -1) { |
503 | /* Note that numblocks is 2 * (real numblocks) here, see i+=2 | 489 | /* |
504 | * below as it makes shifting and masking less painful */ | 490 | * Note that numblocks is 2 * (real numblocks) here, see i+=2 |
491 | * below as it makes shifting and masking less painful | ||
492 | */ | ||
505 | numblocks = mtd->size >> (this->bbt_erase_shift - 1); | 493 | numblocks = mtd->size >> (this->bbt_erase_shift - 1); |
506 | startblock = 0; | 494 | startblock = 0; |
507 | from = 0; | 495 | from = 0; |
@@ -549,20 +537,18 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
549 | 537 | ||
550 | /** | 538 | /** |
551 | * search_bbt - [GENERIC] scan the device for a specific bad block table | 539 | * search_bbt - [GENERIC] scan the device for a specific bad block table |
552 | * @mtd: MTD device structure | 540 | * @mtd: MTD device structure |
553 | * @buf: temporary buffer | 541 | * @buf: temporary buffer |
554 | * @td: descriptor for the bad block table | 542 | * @td: descriptor for the bad block table |
555 | * | 543 | * |
556 | * Read the bad block table by searching for a given ident pattern. | 544 | * Read the bad block table by searching for a given ident pattern. Search is |
557 | * Search is preformed either from the beginning up or from the end of | 545 | * preformed either from the beginning up or from the end of the device |
558 | * the device downwards. The search starts always at the start of a | 546 | * downwards. The search starts always at the start of a block. If the option |
559 | * block. | 547 | * NAND_BBT_PERCHIP is given, each chip is searched for a bbt, which contains |
560 | * If the option NAND_BBT_PERCHIP is given, each chip is searched | 548 | * the bad block information of this chip. This is necessary to provide support |
561 | * for a bbt, which contains the bad block information of this chip. | 549 | * for certain DOC devices. |
562 | * This is necessary to provide support for certain DOC devices. | ||
563 | * | 550 | * |
564 | * The bbt ident pattern resides in the oob area of the first page | 551 | * The bbt ident pattern resides in the oob area of the first page in a block. |
565 | * in a block. | ||
566 | */ | 552 | */ |
567 | static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td) | 553 | static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td) |
568 | { | 554 | { |
@@ -573,7 +559,7 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr | |||
573 | int bbtblocks; | 559 | int bbtblocks; |
574 | int blocktopage = this->bbt_erase_shift - this->page_shift; | 560 | int blocktopage = this->bbt_erase_shift - this->page_shift; |
575 | 561 | ||
576 | /* Search direction top -> down ? */ | 562 | /* Search direction top -> down? */ |
577 | if (td->options & NAND_BBT_LASTBLOCK) { | 563 | if (td->options & NAND_BBT_LASTBLOCK) { |
578 | startblock = (mtd->size >> this->bbt_erase_shift) - 1; | 564 | startblock = (mtd->size >> this->bbt_erase_shift) - 1; |
579 | dir = -1; | 565 | dir = -1; |
@@ -582,7 +568,7 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr | |||
582 | dir = 1; | 568 | dir = 1; |
583 | } | 569 | } |
584 | 570 | ||
585 | /* Do we have a bbt per chip ? */ | 571 | /* Do we have a bbt per chip? */ |
586 | if (td->options & NAND_BBT_PERCHIP) { | 572 | if (td->options & NAND_BBT_PERCHIP) { |
587 | chips = this->numchips; | 573 | chips = this->numchips; |
588 | bbtblocks = this->chipsize >> this->bbt_erase_shift; | 574 | bbtblocks = this->chipsize >> this->bbt_erase_shift; |
@@ -631,13 +617,13 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr | |||
631 | 617 | ||
632 | /** | 618 | /** |
633 | * search_read_bbts - [GENERIC] scan the device for bad block table(s) | 619 | * search_read_bbts - [GENERIC] scan the device for bad block table(s) |
634 | * @mtd: MTD device structure | 620 | * @mtd: MTD device structure |
635 | * @buf: temporary buffer | 621 | * @buf: temporary buffer |
636 | * @td: descriptor for the bad block table | 622 | * @td: descriptor for the bad block table |
637 | * @md: descriptor for the bad block table mirror | 623 | * @md: descriptor for the bad block table mirror |
638 | * | 624 | * |
639 | * Search and read the bad block table(s) | 625 | * Search and read the bad block table(s). |
640 | */ | 626 | */ |
641 | static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md) | 627 | static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md) |
642 | { | 628 | { |
643 | /* Search the primary table */ | 629 | /* Search the primary table */ |
@@ -653,16 +639,14 @@ static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt | |||
653 | 639 | ||
654 | /** | 640 | /** |
655 | * write_bbt - [GENERIC] (Re)write the bad block table | 641 | * write_bbt - [GENERIC] (Re)write the bad block table |
642 | * @mtd: MTD device structure | ||
643 | * @buf: temporary buffer | ||
644 | * @td: descriptor for the bad block table | ||
645 | * @md: descriptor for the bad block table mirror | ||
646 | * @chipsel: selector for a specific chip, -1 for all | ||
656 | * | 647 | * |
657 | * @mtd: MTD device structure | 648 | * (Re)write the bad block table. |
658 | * @buf: temporary buffer | 649 | */ |
659 | * @td: descriptor for the bad block table | ||
660 | * @md: descriptor for the bad block table mirror | ||
661 | * @chipsel: selector for a specific chip, -1 for all | ||
662 | * | ||
663 | * (Re)write the bad block table | ||
664 | * | ||
665 | */ | ||
666 | static int write_bbt(struct mtd_info *mtd, uint8_t *buf, | 650 | static int write_bbt(struct mtd_info *mtd, uint8_t *buf, |
667 | struct nand_bbt_descr *td, struct nand_bbt_descr *md, | 651 | struct nand_bbt_descr *td, struct nand_bbt_descr *md, |
668 | int chipsel) | 652 | int chipsel) |
@@ -685,10 +669,10 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
685 | 669 | ||
686 | if (!rcode) | 670 | if (!rcode) |
687 | rcode = 0xff; | 671 | rcode = 0xff; |
688 | /* Write bad block table per chip rather than per device ? */ | 672 | /* Write bad block table per chip rather than per device? */ |
689 | if (td->options & NAND_BBT_PERCHIP) { | 673 | if (td->options & NAND_BBT_PERCHIP) { |
690 | numblocks = (int)(this->chipsize >> this->bbt_erase_shift); | 674 | numblocks = (int)(this->chipsize >> this->bbt_erase_shift); |
691 | /* Full device write or specific chip ? */ | 675 | /* Full device write or specific chip? */ |
692 | if (chipsel == -1) { | 676 | if (chipsel == -1) { |
693 | nrchips = this->numchips; | 677 | nrchips = this->numchips; |
694 | } else { | 678 | } else { |
@@ -702,8 +686,8 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
702 | 686 | ||
703 | /* Loop through the chips */ | 687 | /* Loop through the chips */ |
704 | for (; chip < nrchips; chip++) { | 688 | for (; chip < nrchips; chip++) { |
705 | 689 | /* | |
706 | /* There was already a version of the table, reuse the page | 690 | * There was already a version of the table, reuse the page |
707 | * This applies for absolute placement too, as we have the | 691 | * This applies for absolute placement too, as we have the |
708 | * page nr. in td->pages. | 692 | * page nr. in td->pages. |
709 | */ | 693 | */ |
@@ -712,8 +696,10 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
712 | goto write; | 696 | goto write; |
713 | } | 697 | } |
714 | 698 | ||
715 | /* Automatic placement of the bad block table */ | 699 | /* |
716 | /* Search direction top -> down ? */ | 700 | * Automatic placement of the bad block table. Search direction |
701 | * top -> down? | ||
702 | */ | ||
717 | if (td->options & NAND_BBT_LASTBLOCK) { | 703 | if (td->options & NAND_BBT_LASTBLOCK) { |
718 | startblock = numblocks * (chip + 1) - 1; | 704 | startblock = numblocks * (chip + 1) - 1; |
719 | dir = -1; | 705 | dir = -1; |
@@ -764,7 +750,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
764 | 750 | ||
765 | to = ((loff_t) page) << this->page_shift; | 751 | to = ((loff_t) page) << this->page_shift; |
766 | 752 | ||
767 | /* Must we save the block contents ? */ | 753 | /* Must we save the block contents? */ |
768 | if (td->options & NAND_BBT_SAVECONTENT) { | 754 | if (td->options & NAND_BBT_SAVECONTENT) { |
769 | /* Make it block aligned */ | 755 | /* Make it block aligned */ |
770 | to &= ~((loff_t) ((1 << this->bbt_erase_shift) - 1)); | 756 | to &= ~((loff_t) ((1 << this->bbt_erase_shift) - 1)); |
@@ -798,13 +784,13 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
798 | } else if (td->options & NAND_BBT_NO_OOB) { | 784 | } else if (td->options & NAND_BBT_NO_OOB) { |
799 | ooboffs = 0; | 785 | ooboffs = 0; |
800 | offs = td->len; | 786 | offs = td->len; |
801 | /* the version byte */ | 787 | /* The version byte */ |
802 | if (td->options & NAND_BBT_VERSION) | 788 | if (td->options & NAND_BBT_VERSION) |
803 | offs++; | 789 | offs++; |
804 | /* Calc length */ | 790 | /* Calc length */ |
805 | len = (size_t) (numblocks >> sft); | 791 | len = (size_t) (numblocks >> sft); |
806 | len += offs; | 792 | len += offs; |
807 | /* Make it page aligned ! */ | 793 | /* Make it page aligned! */ |
808 | len = ALIGN(len, mtd->writesize); | 794 | len = ALIGN(len, mtd->writesize); |
809 | /* Preset the buffer with 0xff */ | 795 | /* Preset the buffer with 0xff */ |
810 | memset(buf, 0xff, len); | 796 | memset(buf, 0xff, len); |
@@ -813,7 +799,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
813 | } else { | 799 | } else { |
814 | /* Calc length */ | 800 | /* Calc length */ |
815 | len = (size_t) (numblocks >> sft); | 801 | len = (size_t) (numblocks >> sft); |
816 | /* Make it page aligned ! */ | 802 | /* Make it page aligned! */ |
817 | len = ALIGN(len, mtd->writesize); | 803 | len = ALIGN(len, mtd->writesize); |
818 | /* Preset the buffer with 0xff */ | 804 | /* Preset the buffer with 0xff */ |
819 | memset(buf, 0xff, len + | 805 | memset(buf, 0xff, len + |
@@ -827,13 +813,13 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
827 | if (td->options & NAND_BBT_VERSION) | 813 | if (td->options & NAND_BBT_VERSION) |
828 | buf[ooboffs + td->veroffs] = td->version[chip]; | 814 | buf[ooboffs + td->veroffs] = td->version[chip]; |
829 | 815 | ||
830 | /* walk through the memory table */ | 816 | /* Walk through the memory table */ |
831 | for (i = 0; i < numblocks;) { | 817 | for (i = 0; i < numblocks;) { |
832 | uint8_t dat; | 818 | uint8_t dat; |
833 | dat = this->bbt[bbtoffs + (i >> 2)]; | 819 | dat = this->bbt[bbtoffs + (i >> 2)]; |
834 | for (j = 0; j < 4; j++, i++) { | 820 | for (j = 0; j < 4; j++, i++) { |
835 | int sftcnt = (i << (3 - sft)) & sftmsk; | 821 | int sftcnt = (i << (3 - sft)) & sftmsk; |
836 | /* Do not store the reserved bbt blocks ! */ | 822 | /* Do not store the reserved bbt blocks! */ |
837 | buf[offs + (i >> sft)] &= | 823 | buf[offs + (i >> sft)] &= |
838 | ~(msk[dat & 0x03] << sftcnt); | 824 | ~(msk[dat & 0x03] << sftcnt); |
839 | dat >>= 2; | 825 | dat >>= 2; |
@@ -870,12 +856,12 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, | |||
870 | 856 | ||
871 | /** | 857 | /** |
872 | * nand_memory_bbt - [GENERIC] create a memory based bad block table | 858 | * nand_memory_bbt - [GENERIC] create a memory based bad block table |
873 | * @mtd: MTD device structure | 859 | * @mtd: MTD device structure |
874 | * @bd: descriptor for the good/bad block search pattern | 860 | * @bd: descriptor for the good/bad block search pattern |
875 | * | 861 | * |
876 | * The function creates a memory based bbt by scanning the device | 862 | * The function creates a memory based bbt by scanning the device for |
877 | * for manufacturer / software marked good / bad blocks | 863 | * manufacturer / software marked good / bad blocks. |
878 | */ | 864 | */ |
879 | static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) | 865 | static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) |
880 | { | 866 | { |
881 | struct nand_chip *this = mtd->priv; | 867 | struct nand_chip *this = mtd->priv; |
@@ -886,16 +872,15 @@ static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *b | |||
886 | 872 | ||
887 | /** | 873 | /** |
888 | * check_create - [GENERIC] create and write bbt(s) if necessary | 874 | * check_create - [GENERIC] create and write bbt(s) if necessary |
889 | * @mtd: MTD device structure | 875 | * @mtd: MTD device structure |
890 | * @buf: temporary buffer | 876 | * @buf: temporary buffer |
891 | * @bd: descriptor for the good/bad block search pattern | 877 | * @bd: descriptor for the good/bad block search pattern |
892 | * | 878 | * |
893 | * The function checks the results of the previous call to read_bbt | 879 | * The function checks the results of the previous call to read_bbt and creates |
894 | * and creates / updates the bbt(s) if necessary | 880 | * / updates the bbt(s) if necessary. Creation is necessary if no bbt was found |
895 | * Creation is necessary if no bbt was found for the chip/device | 881 | * for the chip/device. Update is necessary if one of the tables is missing or |
896 | * Update is necessary if one of the tables is missing or the | 882 | * the version nr. of one table is less than the other. |
897 | * version nr. of one table is less than the other | 883 | */ |
898 | */ | ||
899 | static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd) | 884 | static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd) |
900 | { | 885 | { |
901 | int i, chips, writeops, chipsel, res; | 886 | int i, chips, writeops, chipsel, res; |
@@ -904,7 +889,7 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc | |||
904 | struct nand_bbt_descr *md = this->bbt_md; | 889 | struct nand_bbt_descr *md = this->bbt_md; |
905 | struct nand_bbt_descr *rd, *rd2; | 890 | struct nand_bbt_descr *rd, *rd2; |
906 | 891 | ||
907 | /* Do we have a bbt per chip ? */ | 892 | /* Do we have a bbt per chip? */ |
908 | if (td->options & NAND_BBT_PERCHIP) | 893 | if (td->options & NAND_BBT_PERCHIP) |
909 | chips = this->numchips; | 894 | chips = this->numchips; |
910 | else | 895 | else |
@@ -914,9 +899,9 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc | |||
914 | writeops = 0; | 899 | writeops = 0; |
915 | rd = NULL; | 900 | rd = NULL; |
916 | rd2 = NULL; | 901 | rd2 = NULL; |
917 | /* Per chip or per device ? */ | 902 | /* Per chip or per device? */ |
918 | chipsel = (td->options & NAND_BBT_PERCHIP) ? i : -1; | 903 | chipsel = (td->options & NAND_BBT_PERCHIP) ? i : -1; |
919 | /* Mirrored table available ? */ | 904 | /* Mirrored table available? */ |
920 | if (md) { | 905 | if (md) { |
921 | if (td->pages[i] == -1 && md->pages[i] == -1) { | 906 | if (td->pages[i] == -1 && md->pages[i] == -1) { |
922 | writeops = 0x03; | 907 | writeops = 0x03; |
@@ -965,7 +950,7 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc | |||
965 | goto writecheck; | 950 | goto writecheck; |
966 | } | 951 | } |
967 | create: | 952 | create: |
968 | /* Create the bad block table by scanning the device ? */ | 953 | /* Create the bad block table by scanning the device? */ |
969 | if (!(td->options & NAND_BBT_CREATE)) | 954 | if (!(td->options & NAND_BBT_CREATE)) |
970 | continue; | 955 | continue; |
971 | 956 | ||
@@ -977,21 +962,21 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc | |||
977 | if (md) | 962 | if (md) |
978 | md->version[i] = 1; | 963 | md->version[i] = 1; |
979 | writecheck: | 964 | writecheck: |
980 | /* read back first ? */ | 965 | /* Read back first? */ |
981 | if (rd) | 966 | if (rd) |
982 | read_abs_bbt(mtd, buf, rd, chipsel); | 967 | read_abs_bbt(mtd, buf, rd, chipsel); |
983 | /* If they weren't versioned, read both. */ | 968 | /* If they weren't versioned, read both */ |
984 | if (rd2) | 969 | if (rd2) |
985 | read_abs_bbt(mtd, buf, rd2, chipsel); | 970 | read_abs_bbt(mtd, buf, rd2, chipsel); |
986 | 971 | ||
987 | /* Write the bad block table to the device ? */ | 972 | /* Write the bad block table to the device? */ |
988 | if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) { | 973 | if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) { |
989 | res = write_bbt(mtd, buf, td, md, chipsel); | 974 | res = write_bbt(mtd, buf, td, md, chipsel); |
990 | if (res < 0) | 975 | if (res < 0) |
991 | return res; | 976 | return res; |
992 | } | 977 | } |
993 | 978 | ||
994 | /* Write the mirror bad block table to the device ? */ | 979 | /* Write the mirror bad block table to the device? */ |
995 | if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) { | 980 | if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) { |
996 | res = write_bbt(mtd, buf, md, td, chipsel); | 981 | res = write_bbt(mtd, buf, md, td, chipsel); |
997 | if (res < 0) | 982 | if (res < 0) |
@@ -1003,20 +988,19 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc | |||
1003 | 988 | ||
1004 | /** | 989 | /** |
1005 | * mark_bbt_regions - [GENERIC] mark the bad block table regions | 990 | * mark_bbt_regions - [GENERIC] mark the bad block table regions |
1006 | * @mtd: MTD device structure | 991 | * @mtd: MTD device structure |
1007 | * @td: bad block table descriptor | 992 | * @td: bad block table descriptor |
1008 | * | 993 | * |
1009 | * The bad block table regions are marked as "bad" to prevent | 994 | * The bad block table regions are marked as "bad" to prevent accidental |
1010 | * accidental erasures / writes. The regions are identified by | 995 | * erasures / writes. The regions are identified by the mark 0x02. |
1011 | * the mark 0x02. | 996 | */ |
1012 | */ | ||
1013 | static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td) | 997 | static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td) |
1014 | { | 998 | { |
1015 | struct nand_chip *this = mtd->priv; | 999 | struct nand_chip *this = mtd->priv; |
1016 | int i, j, chips, block, nrblocks, update; | 1000 | int i, j, chips, block, nrblocks, update; |
1017 | uint8_t oldval, newval; | 1001 | uint8_t oldval, newval; |
1018 | 1002 | ||
1019 | /* Do we have a bbt per chip ? */ | 1003 | /* Do we have a bbt per chip? */ |
1020 | if (td->options & NAND_BBT_PERCHIP) { | 1004 | if (td->options & NAND_BBT_PERCHIP) { |
1021 | chips = this->numchips; | 1005 | chips = this->numchips; |
1022 | nrblocks = (int)(this->chipsize >> this->bbt_erase_shift); | 1006 | nrblocks = (int)(this->chipsize >> this->bbt_erase_shift); |
@@ -1053,9 +1037,11 @@ static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td) | |||
1053 | update = 1; | 1037 | update = 1; |
1054 | block += 2; | 1038 | block += 2; |
1055 | } | 1039 | } |
1056 | /* If we want reserved blocks to be recorded to flash, and some | 1040 | /* |
1057 | new ones have been marked, then we need to update the stored | 1041 | * If we want reserved blocks to be recorded to flash, and some |
1058 | bbts. This should only happen once. */ | 1042 | * new ones have been marked, then we need to update the stored |
1043 | * bbts. This should only happen once. | ||
1044 | */ | ||
1059 | if (update && td->reserved_block_code) | 1045 | if (update && td->reserved_block_code) |
1060 | nand_update_bbt(mtd, (loff_t)(block - 2) << (this->bbt_erase_shift - 1)); | 1046 | nand_update_bbt(mtd, (loff_t)(block - 2) << (this->bbt_erase_shift - 1)); |
1061 | } | 1047 | } |
@@ -1063,8 +1049,8 @@ static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td) | |||
1063 | 1049 | ||
1064 | /** | 1050 | /** |
1065 | * verify_bbt_descr - verify the bad block description | 1051 | * verify_bbt_descr - verify the bad block description |
1066 | * @mtd: MTD device structure | 1052 | * @mtd: MTD device structure |
1067 | * @bd: the table to verify | 1053 | * @bd: the table to verify |
1068 | * | 1054 | * |
1069 | * This functions performs a few sanity checks on the bad block description | 1055 | * This functions performs a few sanity checks on the bad block description |
1070 | * table. | 1056 | * table. |
@@ -1111,18 +1097,16 @@ static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd) | |||
1111 | 1097 | ||
1112 | /** | 1098 | /** |
1113 | * nand_scan_bbt - [NAND Interface] scan, find, read and maybe create bad block table(s) | 1099 | * nand_scan_bbt - [NAND Interface] scan, find, read and maybe create bad block table(s) |
1114 | * @mtd: MTD device structure | 1100 | * @mtd: MTD device structure |
1115 | * @bd: descriptor for the good/bad block search pattern | 1101 | * @bd: descriptor for the good/bad block search pattern |
1116 | * | 1102 | * |
1117 | * The function checks, if a bad block table(s) is/are already | 1103 | * The function checks, if a bad block table(s) is/are already available. If |
1118 | * available. If not it scans the device for manufacturer | 1104 | * not it scans the device for manufacturer marked good / bad blocks and writes |
1119 | * marked good / bad blocks and writes the bad block table(s) to | 1105 | * the bad block table(s) to the selected place. |
1120 | * the selected place. | ||
1121 | * | 1106 | * |
1122 | * The bad block table memory is allocated here. It must be freed | 1107 | * The bad block table memory is allocated here. It must be freed by calling |
1123 | * by calling the nand_free_bbt function. | 1108 | * the nand_free_bbt function. |
1124 | * | 1109 | */ |
1125 | */ | ||
1126 | int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) | 1110 | int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) |
1127 | { | 1111 | { |
1128 | struct nand_chip *this = mtd->priv; | 1112 | struct nand_chip *this = mtd->priv; |
@@ -1132,15 +1116,19 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) | |||
1132 | struct nand_bbt_descr *md = this->bbt_md; | 1116 | struct nand_bbt_descr *md = this->bbt_md; |
1133 | 1117 | ||
1134 | len = mtd->size >> (this->bbt_erase_shift + 2); | 1118 | len = mtd->size >> (this->bbt_erase_shift + 2); |
1135 | /* Allocate memory (2bit per block) and clear the memory bad block table */ | 1119 | /* |
1120 | * Allocate memory (2bit per block) and clear the memory bad block | ||
1121 | * table. | ||
1122 | */ | ||
1136 | this->bbt = kzalloc(len, GFP_KERNEL); | 1123 | this->bbt = kzalloc(len, GFP_KERNEL); |
1137 | if (!this->bbt) { | 1124 | if (!this->bbt) { |
1138 | printk(KERN_ERR "nand_scan_bbt: Out of memory\n"); | 1125 | printk(KERN_ERR "nand_scan_bbt: Out of memory\n"); |
1139 | return -ENOMEM; | 1126 | return -ENOMEM; |
1140 | } | 1127 | } |
1141 | 1128 | ||
1142 | /* If no primary table decriptor is given, scan the device | 1129 | /* |
1143 | * to build a memory based bad block table | 1130 | * If no primary table decriptor is given, scan the device to build a |
1131 | * memory based bad block table. | ||
1144 | */ | 1132 | */ |
1145 | if (!td) { | 1133 | if (!td) { |
1146 | if ((res = nand_memory_bbt(mtd, bd))) { | 1134 | if ((res = nand_memory_bbt(mtd, bd))) { |
@@ -1164,7 +1152,7 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) | |||
1164 | return -ENOMEM; | 1152 | return -ENOMEM; |
1165 | } | 1153 | } |
1166 | 1154 | ||
1167 | /* Is the bbt at a given page ? */ | 1155 | /* Is the bbt at a given page? */ |
1168 | if (td->options & NAND_BBT_ABSPAGE) { | 1156 | if (td->options & NAND_BBT_ABSPAGE) { |
1169 | res = read_abs_bbts(mtd, buf, td, md); | 1157 | res = read_abs_bbts(mtd, buf, td, md); |
1170 | } else { | 1158 | } else { |
@@ -1186,11 +1174,11 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) | |||
1186 | 1174 | ||
1187 | /** | 1175 | /** |
1188 | * nand_update_bbt - [NAND Interface] update bad block table(s) | 1176 | * nand_update_bbt - [NAND Interface] update bad block table(s) |
1189 | * @mtd: MTD device structure | 1177 | * @mtd: MTD device structure |
1190 | * @offs: the offset of the newly marked block | 1178 | * @offs: the offset of the newly marked block |
1191 | * | 1179 | * |
1192 | * The function updates the bad block table(s) | 1180 | * The function updates the bad block table(s). |
1193 | */ | 1181 | */ |
1194 | int nand_update_bbt(struct mtd_info *mtd, loff_t offs) | 1182 | int nand_update_bbt(struct mtd_info *mtd, loff_t offs) |
1195 | { | 1183 | { |
1196 | struct nand_chip *this = mtd->priv; | 1184 | struct nand_chip *this = mtd->priv; |
@@ -1214,7 +1202,7 @@ int nand_update_bbt(struct mtd_info *mtd, loff_t offs) | |||
1214 | 1202 | ||
1215 | writeops = md != NULL ? 0x03 : 0x01; | 1203 | writeops = md != NULL ? 0x03 : 0x01; |
1216 | 1204 | ||
1217 | /* Do we have a bbt per chip ? */ | 1205 | /* Do we have a bbt per chip? */ |
1218 | if (td->options & NAND_BBT_PERCHIP) { | 1206 | if (td->options & NAND_BBT_PERCHIP) { |
1219 | chip = (int)(offs >> this->chip_shift); | 1207 | chip = (int)(offs >> this->chip_shift); |
1220 | chipsel = chip; | 1208 | chipsel = chip; |
@@ -1227,13 +1215,13 @@ int nand_update_bbt(struct mtd_info *mtd, loff_t offs) | |||
1227 | if (md) | 1215 | if (md) |
1228 | md->version[chip]++; | 1216 | md->version[chip]++; |
1229 | 1217 | ||
1230 | /* Write the bad block table to the device ? */ | 1218 | /* Write the bad block table to the device? */ |
1231 | if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) { | 1219 | if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) { |
1232 | res = write_bbt(mtd, buf, td, md, chipsel); | 1220 | res = write_bbt(mtd, buf, td, md, chipsel); |
1233 | if (res < 0) | 1221 | if (res < 0) |
1234 | goto out; | 1222 | goto out; |
1235 | } | 1223 | } |
1236 | /* Write the mirror bad block table to the device ? */ | 1224 | /* Write the mirror bad block table to the device? */ |
1237 | if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) { | 1225 | if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) { |
1238 | res = write_bbt(mtd, buf, md, td, chipsel); | 1226 | res = write_bbt(mtd, buf, md, td, chipsel); |
1239 | } | 1227 | } |
@@ -1243,8 +1231,10 @@ int nand_update_bbt(struct mtd_info *mtd, loff_t offs) | |||
1243 | return res; | 1231 | return res; |
1244 | } | 1232 | } |
1245 | 1233 | ||
1246 | /* Define some generic bad / good block scan pattern which are used | 1234 | /* |
1247 | * while scanning a device for factory marked good / bad blocks. */ | 1235 | * Define some generic bad / good block scan pattern which are used |
1236 | * while scanning a device for factory marked good / bad blocks. | ||
1237 | */ | ||
1248 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; | 1238 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; |
1249 | 1239 | ||
1250 | static uint8_t scan_agand_pattern[] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 }; | 1240 | static uint8_t scan_agand_pattern[] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 }; |
@@ -1256,8 +1246,7 @@ static struct nand_bbt_descr agand_flashbased = { | |||
1256 | .pattern = scan_agand_pattern | 1246 | .pattern = scan_agand_pattern |
1257 | }; | 1247 | }; |
1258 | 1248 | ||
1259 | /* Generic flash bbt decriptors | 1249 | /* Generic flash bbt decriptors */ |
1260 | */ | ||
1261 | static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' }; | 1250 | static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' }; |
1262 | static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' }; | 1251 | static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' }; |
1263 | 1252 | ||
@@ -1303,13 +1292,12 @@ static struct nand_bbt_descr bbt_mirror_no_bbt_descr = { | |||
1303 | 1292 | ||
1304 | /** | 1293 | /** |
1305 | * nand_create_default_bbt_descr - [Internal] Creates a BBT descriptor structure | 1294 | * nand_create_default_bbt_descr - [Internal] Creates a BBT descriptor structure |
1306 | * @this: NAND chip to create descriptor for | 1295 | * @this: NAND chip to create descriptor for |
1307 | * | 1296 | * |
1308 | * This function allocates and initializes a nand_bbt_descr for BBM detection | 1297 | * This function allocates and initializes a nand_bbt_descr for BBM detection |
1309 | * based on the properties of "this". The new descriptor is stored in | 1298 | * based on the properties of "this". The new descriptor is stored in |
1310 | * this->badblock_pattern. Thus, this->badblock_pattern should be NULL when | 1299 | * this->badblock_pattern. Thus, this->badblock_pattern should be NULL when |
1311 | * passed to this function. | 1300 | * passed to this function. |
1312 | * | ||
1313 | */ | 1301 | */ |
1314 | static int nand_create_default_bbt_descr(struct nand_chip *this) | 1302 | static int nand_create_default_bbt_descr(struct nand_chip *this) |
1315 | { | 1303 | { |
@@ -1334,22 +1322,20 @@ static int nand_create_default_bbt_descr(struct nand_chip *this) | |||
1334 | 1322 | ||
1335 | /** | 1323 | /** |
1336 | * nand_default_bbt - [NAND Interface] Select a default bad block table for the device | 1324 | * nand_default_bbt - [NAND Interface] Select a default bad block table for the device |
1337 | * @mtd: MTD device structure | 1325 | * @mtd: MTD device structure |
1338 | * | ||
1339 | * This function selects the default bad block table | ||
1340 | * support for the device and calls the nand_scan_bbt function | ||
1341 | * | 1326 | * |
1342 | */ | 1327 | * This function selects the default bad block table support for the device and |
1328 | * calls the nand_scan_bbt function. | ||
1329 | */ | ||
1343 | int nand_default_bbt(struct mtd_info *mtd) | 1330 | int nand_default_bbt(struct mtd_info *mtd) |
1344 | { | 1331 | { |
1345 | struct nand_chip *this = mtd->priv; | 1332 | struct nand_chip *this = mtd->priv; |
1346 | 1333 | ||
1347 | /* Default for AG-AND. We must use a flash based | 1334 | /* |
1348 | * bad block table as the devices have factory marked | 1335 | * Default for AG-AND. We must use a flash based bad block table as the |
1349 | * _good_ blocks. Erasing those blocks leads to loss | 1336 | * devices have factory marked _good_ blocks. Erasing those blocks |
1350 | * of the good / bad information, so we _must_ store | 1337 | * leads to loss of the good / bad information, so we _must_ store this |
1351 | * this information in a good / bad table during | 1338 | * information in a good / bad table during startup. |
1352 | * startup | ||
1353 | */ | 1339 | */ |
1354 | if (this->options & NAND_IS_AND) { | 1340 | if (this->options & NAND_IS_AND) { |
1355 | /* Use the default pattern descriptors */ | 1341 | /* Use the default pattern descriptors */ |
@@ -1361,7 +1347,7 @@ int nand_default_bbt(struct mtd_info *mtd) | |||
1361 | return nand_scan_bbt(mtd, &agand_flashbased); | 1347 | return nand_scan_bbt(mtd, &agand_flashbased); |
1362 | } | 1348 | } |
1363 | 1349 | ||
1364 | /* Is a flash based bad block table requested ? */ | 1350 | /* Is a flash based bad block table requested? */ |
1365 | if (this->bbt_options & NAND_BBT_USE_FLASH) { | 1351 | if (this->bbt_options & NAND_BBT_USE_FLASH) { |
1366 | /* Use the default pattern descriptors */ | 1352 | /* Use the default pattern descriptors */ |
1367 | if (!this->bbt_td) { | 1353 | if (!this->bbt_td) { |
@@ -1386,11 +1372,10 @@ int nand_default_bbt(struct mtd_info *mtd) | |||
1386 | 1372 | ||
1387 | /** | 1373 | /** |
1388 | * nand_isbad_bbt - [NAND Interface] Check if a block is bad | 1374 | * nand_isbad_bbt - [NAND Interface] Check if a block is bad |
1389 | * @mtd: MTD device structure | 1375 | * @mtd: MTD device structure |
1390 | * @offs: offset in the device | 1376 | * @offs: offset in the device |
1391 | * @allowbbt: allow access to bad block table region | 1377 | * @allowbbt: allow access to bad block table region |
1392 | * | 1378 | */ |
1393 | */ | ||
1394 | int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) | 1379 | int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) |
1395 | { | 1380 | { |
1396 | struct nand_chip *this = mtd->priv; | 1381 | struct nand_chip *this = mtd->priv; |