aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/nand_bbt.c
diff options
context:
space:
mode:
authorBrian Norris <norris@broadcom.com>2011-05-25 17:59:01 -0400
committerArtem Bityutskiy <artem.bityutskiy@intel.com>2011-09-11 08:02:04 -0400
commit8b6e50c9eba8bf44b2dfd931d359706a461d2cfd (patch)
tree23f9deda954030fc7d7ab6ffe9c06abb6a1f89de /drivers/mtd/nand/nand_bbt.c
parent18f8eb1b23619736872740f8c4697b6534a0524b (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/nand_bbt.c')
-rw-r--r--drivers/mtd/nand/nand_bbt.c365
1 files changed, 175 insertions, 190 deletions
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*/
94static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) 92static 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 */
138static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) 135static 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 */
182static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, 178static 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 */
261static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip) 259static 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 */
289static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs, 285static 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 */
305static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs, 299static 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 */
350static int scan_write_bbt(struct mtd_info *mtd, loff_t offs, size_t len, 342static 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 */
385static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, 376static 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 */
413static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd, 402static 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 */
433static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, 420static 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 */
474static int create_bbt(struct mtd_info *mtd, uint8_t *buf, 460static 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 */
567static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td) 553static 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 */
641static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md) 627static 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*/
666static int write_bbt(struct mtd_info *mtd, uint8_t *buf, 650static 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 */
879static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) 865static 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*/
899static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd) 884static 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*/
1013static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td) 997static 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*/
1126int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) 1110int 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 */
1194int nand_update_bbt(struct mtd_info *mtd, loff_t offs) 1182int 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 */
1248static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 1238static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
1249 1239
1250static uint8_t scan_agand_pattern[] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 }; 1240static 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*/
1261static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' }; 1250static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' };
1262static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' }; 1251static 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 */
1314static int nand_create_default_bbt_descr(struct nand_chip *this) 1302static 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 */
1343int nand_default_bbt(struct mtd_info *mtd) 1330int 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*/
1394int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) 1379int 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;