diff options
Diffstat (limited to 'drivers/mtd/nand/nand_base.c')
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 694 |
1 files changed, 337 insertions, 357 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 95e96fa1fceb..fdaf32083ada 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -92,24 +92,24 @@ static struct nand_oobinfo nand_oob_8 = { | |||
92 | .useecc = MTD_NANDECC_AUTOPLACE, | 92 | .useecc = MTD_NANDECC_AUTOPLACE, |
93 | .eccbytes = 3, | 93 | .eccbytes = 3, |
94 | .eccpos = {0, 1, 2}, | 94 | .eccpos = {0, 1, 2}, |
95 | .oobfree = { {3, 2}, {6, 2} } | 95 | .oobfree = {{3, 2}, {6, 2}} |
96 | }; | 96 | }; |
97 | 97 | ||
98 | static struct nand_oobinfo nand_oob_16 = { | 98 | static struct nand_oobinfo nand_oob_16 = { |
99 | .useecc = MTD_NANDECC_AUTOPLACE, | 99 | .useecc = MTD_NANDECC_AUTOPLACE, |
100 | .eccbytes = 6, | 100 | .eccbytes = 6, |
101 | .eccpos = {0, 1, 2, 3, 6, 7}, | 101 | .eccpos = {0, 1, 2, 3, 6, 7}, |
102 | .oobfree = { {8, 8} } | 102 | .oobfree = {{8, 8}} |
103 | }; | 103 | }; |
104 | 104 | ||
105 | static struct nand_oobinfo nand_oob_64 = { | 105 | static struct nand_oobinfo nand_oob_64 = { |
106 | .useecc = MTD_NANDECC_AUTOPLACE, | 106 | .useecc = MTD_NANDECC_AUTOPLACE, |
107 | .eccbytes = 24, | 107 | .eccbytes = 24, |
108 | .eccpos = { | 108 | .eccpos = { |
109 | 40, 41, 42, 43, 44, 45, 46, 47, | 109 | 40, 41, 42, 43, 44, 45, 46, 47, |
110 | 48, 49, 50, 51, 52, 53, 54, 55, | 110 | 48, 49, 50, 51, 52, 53, 54, 55, |
111 | 56, 57, 58, 59, 60, 61, 62, 63}, | 111 | 56, 57, 58, 59, 60, 61, 62, 63}, |
112 | .oobfree = { {2, 38} } | 112 | .oobfree = {{2, 38}} |
113 | }; | 113 | }; |
114 | 114 | ||
115 | /* This is used for padding purposes in nand_write_oob */ | 115 | /* This is used for padding purposes in nand_write_oob */ |
@@ -131,32 +131,32 @@ static void nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len); | |||
131 | static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len); | 131 | static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len); |
132 | static int nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len); | 132 | static int nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len); |
133 | 133 | ||
134 | static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf); | 134 | static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); |
135 | static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | 135 | static int nand_read_ecc(struct mtd_info *mtd, loff_t from, size_t len, |
136 | size_t * retlen, u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel); | 136 | size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel); |
137 | static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf); | 137 | static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); |
138 | static int nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf); | 138 | static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); |
139 | static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | 139 | static int nand_write_ecc(struct mtd_info *mtd, loff_t to, size_t len, |
140 | size_t * retlen, const u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel); | 140 | size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel); |
141 | static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char *buf); | 141 | static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); |
142 | static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, | 142 | static int nand_writev(struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen); |
143 | unsigned long count, loff_t to, size_t * retlen); | 143 | static int nand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs, |
144 | static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, | 144 | unsigned long count, loff_t to, size_t *retlen, u_char *eccbuf, |
145 | unsigned long count, loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel); | 145 | struct nand_oobinfo *oobsel); |
146 | static int nand_erase (struct mtd_info *mtd, struct erase_info *instr); | 146 | static int nand_erase(struct mtd_info *mtd, struct erase_info *instr); |
147 | static void nand_sync (struct mtd_info *mtd); | 147 | static void nand_sync(struct mtd_info *mtd); |
148 | 148 | ||
149 | /* Some internal functions */ | 149 | /* Some internal functions */ |
150 | static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, u_char *oob_buf, | 150 | static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int page, u_char * oob_buf, |
151 | struct nand_oobinfo *oobsel, int mode); | 151 | struct nand_oobinfo *oobsel, int mode); |
152 | #ifdef CONFIG_MTD_NAND_VERIFY_WRITE | 152 | #ifdef CONFIG_MTD_NAND_VERIFY_WRITE |
153 | static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, | 153 | static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, |
154 | u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode); | 154 | u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode); |
155 | #else | 155 | #else |
156 | #define nand_verify_pages(...) (0) | 156 | #define nand_verify_pages(...) (0) |
157 | #endif | 157 | #endif |
158 | 158 | ||
159 | static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state); | 159 | static int nand_get_device(struct nand_chip *this, struct mtd_info *mtd, int new_state); |
160 | 160 | ||
161 | /** | 161 | /** |
162 | * nand_release_device - [GENERIC] release chip | 162 | * nand_release_device - [GENERIC] release chip |
@@ -164,7 +164,7 @@ static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int ne | |||
164 | * | 164 | * |
165 | * Deselect, release chip lock and wake up anyone waiting on the device | 165 | * Deselect, release chip lock and wake up anyone waiting on the device |
166 | */ | 166 | */ |
167 | static void nand_release_device (struct mtd_info *mtd) | 167 | static void nand_release_device(struct mtd_info *mtd) |
168 | { | 168 | { |
169 | struct nand_chip *this = mtd->priv; | 169 | struct nand_chip *this = mtd->priv; |
170 | 170 | ||
@@ -276,7 +276,7 @@ static void nand_write_word(struct mtd_info *mtd, u16 word) | |||
276 | static void nand_select_chip(struct mtd_info *mtd, int chip) | 276 | static void nand_select_chip(struct mtd_info *mtd, int chip) |
277 | { | 277 | { |
278 | struct nand_chip *this = mtd->priv; | 278 | struct nand_chip *this = mtd->priv; |
279 | switch(chip) { | 279 | switch (chip) { |
280 | case -1: | 280 | case -1: |
281 | this->hwcontrol(mtd, NAND_CTL_CLRNCE); | 281 | this->hwcontrol(mtd, NAND_CTL_CLRNCE); |
282 | break; | 282 | break; |
@@ -302,7 +302,7 @@ static void nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) | |||
302 | int i; | 302 | int i; |
303 | struct nand_chip *this = mtd->priv; | 303 | struct nand_chip *this = mtd->priv; |
304 | 304 | ||
305 | for (i=0; i<len; i++) | 305 | for (i = 0; i < len; i++) |
306 | writeb(buf[i], this->IO_ADDR_W); | 306 | writeb(buf[i], this->IO_ADDR_W); |
307 | } | 307 | } |
308 | 308 | ||
@@ -319,7 +319,7 @@ static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) | |||
319 | int i; | 319 | int i; |
320 | struct nand_chip *this = mtd->priv; | 320 | struct nand_chip *this = mtd->priv; |
321 | 321 | ||
322 | for (i=0; i<len; i++) | 322 | for (i = 0; i < len; i++) |
323 | buf[i] = readb(this->IO_ADDR_R); | 323 | buf[i] = readb(this->IO_ADDR_R); |
324 | } | 324 | } |
325 | 325 | ||
@@ -336,7 +336,7 @@ static int nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len) | |||
336 | int i; | 336 | int i; |
337 | struct nand_chip *this = mtd->priv; | 337 | struct nand_chip *this = mtd->priv; |
338 | 338 | ||
339 | for (i=0; i<len; i++) | 339 | for (i = 0; i < len; i++) |
340 | if (buf[i] != readb(this->IO_ADDR_R)) | 340 | if (buf[i] != readb(this->IO_ADDR_R)) |
341 | return -EFAULT; | 341 | return -EFAULT; |
342 | 342 | ||
@@ -358,7 +358,7 @@ static void nand_write_buf16(struct mtd_info *mtd, const u_char *buf, int len) | |||
358 | u16 *p = (u16 *) buf; | 358 | u16 *p = (u16 *) buf; |
359 | len >>= 1; | 359 | len >>= 1; |
360 | 360 | ||
361 | for (i=0; i<len; i++) | 361 | for (i = 0; i < len; i++) |
362 | writew(p[i], this->IO_ADDR_W); | 362 | writew(p[i], this->IO_ADDR_W); |
363 | 363 | ||
364 | } | 364 | } |
@@ -378,7 +378,7 @@ static void nand_read_buf16(struct mtd_info *mtd, u_char *buf, int len) | |||
378 | u16 *p = (u16 *) buf; | 378 | u16 *p = (u16 *) buf; |
379 | len >>= 1; | 379 | len >>= 1; |
380 | 380 | ||
381 | for (i=0; i<len; i++) | 381 | for (i = 0; i < len; i++) |
382 | p[i] = readw(this->IO_ADDR_R); | 382 | p[i] = readw(this->IO_ADDR_R); |
383 | } | 383 | } |
384 | 384 | ||
@@ -397,7 +397,7 @@ static int nand_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len) | |||
397 | u16 *p = (u16 *) buf; | 397 | u16 *p = (u16 *) buf; |
398 | len >>= 1; | 398 | len >>= 1; |
399 | 399 | ||
400 | for (i=0; i<len; i++) | 400 | for (i = 0; i < len; i++) |
401 | if (p[i] != readw(this->IO_ADDR_R)) | 401 | if (p[i] != readw(this->IO_ADDR_R)) |
402 | return -EFAULT; | 402 | return -EFAULT; |
403 | 403 | ||
@@ -423,22 +423,22 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) | |||
423 | chipnr = (int)(ofs >> this->chip_shift); | 423 | chipnr = (int)(ofs >> this->chip_shift); |
424 | 424 | ||
425 | /* Grab the lock and see if the device is available */ | 425 | /* Grab the lock and see if the device is available */ |
426 | nand_get_device (this, mtd, FL_READING); | 426 | nand_get_device(this, mtd, FL_READING); |
427 | 427 | ||
428 | /* Select the NAND device */ | 428 | /* Select the NAND device */ |
429 | this->select_chip(mtd, chipnr); | 429 | this->select_chip(mtd, chipnr); |
430 | } else | 430 | } else |
431 | page = (int) ofs; | 431 | page = (int)ofs; |
432 | 432 | ||
433 | if (this->options & NAND_BUSWIDTH_16) { | 433 | if (this->options & NAND_BUSWIDTH_16) { |
434 | this->cmdfunc (mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, page & this->pagemask); | 434 | this->cmdfunc(mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, page & this->pagemask); |
435 | bad = cpu_to_le16(this->read_word(mtd)); | 435 | bad = cpu_to_le16(this->read_word(mtd)); |
436 | if (this->badblockpos & 0x1) | 436 | if (this->badblockpos & 0x1) |
437 | bad >>= 8; | 437 | bad >>= 8; |
438 | if ((bad & 0xFF) != 0xff) | 438 | if ((bad & 0xFF) != 0xff) |
439 | res = 1; | 439 | res = 1; |
440 | } else { | 440 | } else { |
441 | this->cmdfunc (mtd, NAND_CMD_READOOB, this->badblockpos, page & this->pagemask); | 441 | this->cmdfunc(mtd, NAND_CMD_READOOB, this->badblockpos, page & this->pagemask); |
442 | if (this->read_byte(mtd) != 0xff) | 442 | if (this->read_byte(mtd) != 0xff) |
443 | res = 1; | 443 | res = 1; |
444 | } | 444 | } |
@@ -462,22 +462,22 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) | |||
462 | static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) | 462 | static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) |
463 | { | 463 | { |
464 | struct nand_chip *this = mtd->priv; | 464 | struct nand_chip *this = mtd->priv; |
465 | u_char buf[2] = {0, 0}; | 465 | u_char buf[2] = { 0, 0 }; |
466 | size_t retlen; | 466 | size_t retlen; |
467 | int block; | 467 | int block; |
468 | 468 | ||
469 | /* Get block number */ | 469 | /* Get block number */ |
470 | block = ((int) ofs) >> this->bbt_erase_shift; | 470 | block = ((int)ofs) >> this->bbt_erase_shift; |
471 | if (this->bbt) | 471 | if (this->bbt) |
472 | this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); | 472 | this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); |
473 | 473 | ||
474 | /* Do we have a flash based bad block table ? */ | 474 | /* Do we have a flash based bad block table ? */ |
475 | if (this->options & NAND_USE_FLASH_BBT) | 475 | if (this->options & NAND_USE_FLASH_BBT) |
476 | return nand_update_bbt (mtd, ofs); | 476 | return nand_update_bbt(mtd, ofs); |
477 | 477 | ||
478 | /* We write two bytes, so we dont have to mess with 16 bit access */ | 478 | /* We write two bytes, so we dont have to mess with 16 bit access */ |
479 | ofs += mtd->oobsize + (this->badblockpos & ~0x01); | 479 | ofs += mtd->oobsize + (this->badblockpos & ~0x01); |
480 | return nand_write_oob (mtd, ofs , 2, &retlen, buf); | 480 | return nand_write_oob(mtd, ofs, 2, &retlen, buf); |
481 | } | 481 | } |
482 | 482 | ||
483 | /** | 483 | /** |
@@ -487,11 +487,11 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) | |||
487 | * | 487 | * |
488 | * The function expects, that the device is already selected | 488 | * The function expects, that the device is already selected |
489 | */ | 489 | */ |
490 | static int nand_check_wp (struct mtd_info *mtd) | 490 | static int nand_check_wp(struct mtd_info *mtd) |
491 | { | 491 | { |
492 | struct nand_chip *this = mtd->priv; | 492 | struct nand_chip *this = mtd->priv; |
493 | /* Check the WP bit */ | 493 | /* Check the WP bit */ |
494 | this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); | 494 | this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); |
495 | return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1; | 495 | return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1; |
496 | } | 496 | } |
497 | 497 | ||
@@ -505,7 +505,7 @@ static int nand_check_wp (struct mtd_info *mtd) | |||
505 | * Check, if the block is bad. Either by reading the bad block table or | 505 | * Check, if the block is bad. Either by reading the bad block table or |
506 | * calling of the scan function. | 506 | * calling of the scan function. |
507 | */ | 507 | */ |
508 | static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt) | 508 | static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt) |
509 | { | 509 | { |
510 | struct nand_chip *this = mtd->priv; | 510 | struct nand_chip *this = mtd->priv; |
511 | 511 | ||
@@ -513,7 +513,7 @@ static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, i | |||
513 | return this->block_bad(mtd, ofs, getchip); | 513 | return this->block_bad(mtd, ofs, getchip); |
514 | 514 | ||
515 | /* Return info from the table */ | 515 | /* Return info from the table */ |
516 | return nand_isbad_bbt (mtd, ofs, allowbbt); | 516 | return nand_isbad_bbt(mtd, ofs, allowbbt); |
517 | } | 517 | } |
518 | 518 | ||
519 | DEFINE_LED_TRIGGER(nand_led_trigger); | 519 | DEFINE_LED_TRIGGER(nand_led_trigger); |
@@ -525,7 +525,7 @@ DEFINE_LED_TRIGGER(nand_led_trigger); | |||
525 | static void nand_wait_ready(struct mtd_info *mtd) | 525 | static void nand_wait_ready(struct mtd_info *mtd) |
526 | { | 526 | { |
527 | struct nand_chip *this = mtd->priv; | 527 | struct nand_chip *this = mtd->priv; |
528 | unsigned long timeo = jiffies + 2; | 528 | unsigned long timeo = jiffies + 2; |
529 | 529 | ||
530 | led_trigger_event(nand_led_trigger, LED_FULL); | 530 | led_trigger_event(nand_led_trigger, LED_FULL); |
531 | /* wait until command is processed or timeout occures */ | 531 | /* wait until command is processed or timeout occures */ |
@@ -547,7 +547,7 @@ static void nand_wait_ready(struct mtd_info *mtd) | |||
547 | * Send command to NAND device. This function is used for small page | 547 | * Send command to NAND device. This function is used for small page |
548 | * devices (256/512 Bytes per page) | 548 | * devices (256/512 Bytes per page) |
549 | */ | 549 | */ |
550 | static void nand_command (struct mtd_info *mtd, unsigned command, int column, int page_addr) | 550 | static void nand_command(struct mtd_info *mtd, unsigned command, int column, int page_addr) |
551 | { | 551 | { |
552 | register struct nand_chip *this = mtd->priv; | 552 | register struct nand_chip *this = mtd->priv; |
553 | 553 | ||
@@ -588,11 +588,11 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in | |||
588 | this->write_byte(mtd, column); | 588 | this->write_byte(mtd, column); |
589 | } | 589 | } |
590 | if (page_addr != -1) { | 590 | if (page_addr != -1) { |
591 | this->write_byte(mtd, (unsigned char) (page_addr & 0xff)); | 591 | this->write_byte(mtd, (unsigned char)(page_addr & 0xff)); |
592 | this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff)); | 592 | this->write_byte(mtd, (unsigned char)((page_addr >> 8) & 0xff)); |
593 | /* One more address cycle for devices > 32MiB */ | 593 | /* One more address cycle for devices > 32MiB */ |
594 | if (this->chipsize > (32 << 20)) | 594 | if (this->chipsize > (32 << 20)) |
595 | this->write_byte(mtd, (unsigned char) ((page_addr >> 16) & 0x0f)); | 595 | this->write_byte(mtd, (unsigned char)((page_addr >> 16) & 0x0f)); |
596 | } | 596 | } |
597 | /* Latch in address */ | 597 | /* Latch in address */ |
598 | this->hwcontrol(mtd, NAND_CTL_CLRALE); | 598 | this->hwcontrol(mtd, NAND_CTL_CLRALE); |
@@ -601,7 +601,7 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in | |||
601 | /* | 601 | /* |
602 | * program and erase have their own busy handlers | 602 | * program and erase have their own busy handlers |
603 | * status and sequential in needs no delay | 603 | * status and sequential in needs no delay |
604 | */ | 604 | */ |
605 | switch (command) { | 605 | switch (command) { |
606 | 606 | ||
607 | case NAND_CMD_PAGEPROG: | 607 | case NAND_CMD_PAGEPROG: |
@@ -618,23 +618,23 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in | |||
618 | this->hwcontrol(mtd, NAND_CTL_SETCLE); | 618 | this->hwcontrol(mtd, NAND_CTL_SETCLE); |
619 | this->write_byte(mtd, NAND_CMD_STATUS); | 619 | this->write_byte(mtd, NAND_CMD_STATUS); |
620 | this->hwcontrol(mtd, NAND_CTL_CLRCLE); | 620 | this->hwcontrol(mtd, NAND_CTL_CLRCLE); |
621 | while ( !(this->read_byte(mtd) & NAND_STATUS_READY)); | 621 | while (!(this->read_byte(mtd) & NAND_STATUS_READY)) ; |
622 | return; | 622 | return; |
623 | 623 | ||
624 | /* This applies to read commands */ | 624 | /* This applies to read commands */ |
625 | default: | 625 | default: |
626 | /* | 626 | /* |
627 | * If we don't have access to the busy pin, we apply the given | 627 | * If we don't have access to the busy pin, we apply the given |
628 | * command delay | 628 | * command delay |
629 | */ | 629 | */ |
630 | if (!this->dev_ready) { | 630 | if (!this->dev_ready) { |
631 | udelay (this->chip_delay); | 631 | udelay(this->chip_delay); |
632 | return; | 632 | return; |
633 | } | 633 | } |
634 | } | 634 | } |
635 | /* Apply this short delay always to ensure that we do wait tWB in | 635 | /* Apply this short delay always to ensure that we do wait tWB in |
636 | * any case on any machine. */ | 636 | * any case on any machine. */ |
637 | ndelay (100); | 637 | ndelay(100); |
638 | 638 | ||
639 | nand_wait_ready(mtd); | 639 | nand_wait_ready(mtd); |
640 | } | 640 | } |
@@ -647,11 +647,11 @@ static void nand_command (struct mtd_info *mtd, unsigned command, int column, in | |||
647 | * @page_addr: the page address for this command, -1 if none | 647 | * @page_addr: the page address for this command, -1 if none |
648 | * | 648 | * |
649 | * Send command to NAND device. This is the version for the new large page devices | 649 | * Send command to NAND device. This is the version for the new large page devices |
650 | * We dont have the seperate regions as we have in the small page devices. | 650 | * We dont have the separate regions as we have in the small page devices. |
651 | * We must emulate NAND_CMD_READOOB to keep the code compatible. | 651 | * We must emulate NAND_CMD_READOOB to keep the code compatible. |
652 | * | 652 | * |
653 | */ | 653 | */ |
654 | static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, int page_addr) | 654 | static void nand_command_lp(struct mtd_info *mtd, unsigned command, int column, int page_addr) |
655 | { | 655 | { |
656 | register struct nand_chip *this = mtd->priv; | 656 | register struct nand_chip *this = mtd->priv; |
657 | 657 | ||
@@ -661,7 +661,6 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
661 | command = NAND_CMD_READ0; | 661 | command = NAND_CMD_READ0; |
662 | } | 662 | } |
663 | 663 | ||
664 | |||
665 | /* Begin command latch cycle */ | 664 | /* Begin command latch cycle */ |
666 | this->hwcontrol(mtd, NAND_CTL_SETCLE); | 665 | this->hwcontrol(mtd, NAND_CTL_SETCLE); |
667 | /* Write out the command to the device. */ | 666 | /* Write out the command to the device. */ |
@@ -681,11 +680,11 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
681 | this->write_byte(mtd, column >> 8); | 680 | this->write_byte(mtd, column >> 8); |
682 | } | 681 | } |
683 | if (page_addr != -1) { | 682 | if (page_addr != -1) { |
684 | this->write_byte(mtd, (unsigned char) (page_addr & 0xff)); | 683 | this->write_byte(mtd, (unsigned char)(page_addr & 0xff)); |
685 | this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff)); | 684 | this->write_byte(mtd, (unsigned char)((page_addr >> 8) & 0xff)); |
686 | /* One more address cycle for devices > 128MiB */ | 685 | /* One more address cycle for devices > 128MiB */ |
687 | if (this->chipsize > (128 << 20)) | 686 | if (this->chipsize > (128 << 20)) |
688 | this->write_byte(mtd, (unsigned char) ((page_addr >> 16) & 0xff)); | 687 | this->write_byte(mtd, (unsigned char)((page_addr >> 16) & 0xff)); |
689 | } | 688 | } |
690 | /* Latch in address */ | 689 | /* Latch in address */ |
691 | this->hwcontrol(mtd, NAND_CTL_CLRALE); | 690 | this->hwcontrol(mtd, NAND_CTL_CLRALE); |
@@ -706,9 +705,9 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
706 | case NAND_CMD_DEPLETE1: | 705 | case NAND_CMD_DEPLETE1: |
707 | return; | 706 | return; |
708 | 707 | ||
709 | /* | 708 | /* |
710 | * read error status commands require only a short delay | 709 | * read error status commands require only a short delay |
711 | */ | 710 | */ |
712 | case NAND_CMD_STATUS_ERROR: | 711 | case NAND_CMD_STATUS_ERROR: |
713 | case NAND_CMD_STATUS_ERROR0: | 712 | case NAND_CMD_STATUS_ERROR0: |
714 | case NAND_CMD_STATUS_ERROR1: | 713 | case NAND_CMD_STATUS_ERROR1: |
@@ -724,7 +723,7 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
724 | this->hwcontrol(mtd, NAND_CTL_SETCLE); | 723 | this->hwcontrol(mtd, NAND_CTL_SETCLE); |
725 | this->write_byte(mtd, NAND_CMD_STATUS); | 724 | this->write_byte(mtd, NAND_CMD_STATUS); |
726 | this->hwcontrol(mtd, NAND_CTL_CLRCLE); | 725 | this->hwcontrol(mtd, NAND_CTL_CLRCLE); |
727 | while ( !(this->read_byte(mtd) & NAND_STATUS_READY)); | 726 | while (!(this->read_byte(mtd) & NAND_STATUS_READY)) ; |
728 | return; | 727 | return; |
729 | 728 | ||
730 | case NAND_CMD_READ0: | 729 | case NAND_CMD_READ0: |
@@ -736,21 +735,21 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
736 | this->hwcontrol(mtd, NAND_CTL_CLRCLE); | 735 | this->hwcontrol(mtd, NAND_CTL_CLRCLE); |
737 | /* Fall through into ready check */ | 736 | /* Fall through into ready check */ |
738 | 737 | ||
739 | /* This applies to read commands */ | 738 | /* This applies to read commands */ |
740 | default: | 739 | default: |
741 | /* | 740 | /* |
742 | * If we don't have access to the busy pin, we apply the given | 741 | * If we don't have access to the busy pin, we apply the given |
743 | * command delay | 742 | * command delay |
744 | */ | 743 | */ |
745 | if (!this->dev_ready) { | 744 | if (!this->dev_ready) { |
746 | udelay (this->chip_delay); | 745 | udelay(this->chip_delay); |
747 | return; | 746 | return; |
748 | } | 747 | } |
749 | } | 748 | } |
750 | 749 | ||
751 | /* Apply this short delay always to ensure that we do wait tWB in | 750 | /* Apply this short delay always to ensure that we do wait tWB in |
752 | * any case on any machine. */ | 751 | * any case on any machine. */ |
753 | ndelay (100); | 752 | ndelay(100); |
754 | 753 | ||
755 | nand_wait_ready(mtd); | 754 | nand_wait_ready(mtd); |
756 | } | 755 | } |
@@ -763,16 +762,16 @@ static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, | |||
763 | * | 762 | * |
764 | * Get the device and lock it for exclusive access | 763 | * Get the device and lock it for exclusive access |
765 | */ | 764 | */ |
766 | static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state) | 765 | static int nand_get_device(struct nand_chip *this, struct mtd_info *mtd, int new_state) |
767 | { | 766 | { |
768 | struct nand_chip *active; | 767 | struct nand_chip *active; |
769 | spinlock_t *lock; | 768 | spinlock_t *lock; |
770 | wait_queue_head_t *wq; | 769 | wait_queue_head_t *wq; |
771 | DECLARE_WAITQUEUE (wait, current); | 770 | DECLARE_WAITQUEUE(wait, current); |
772 | 771 | ||
773 | lock = (this->controller) ? &this->controller->lock : &this->chip_lock; | 772 | lock = (this->controller) ? &this->controller->lock : &this->chip_lock; |
774 | wq = (this->controller) ? &this->controller->wq : &this->wq; | 773 | wq = (this->controller) ? &this->controller->wq : &this->wq; |
775 | retry: | 774 | retry: |
776 | active = this; | 775 | active = this; |
777 | spin_lock(lock); | 776 | spin_lock(lock); |
778 | 777 | ||
@@ -814,24 +813,24 @@ retry: | |||
814 | static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) | 813 | static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) |
815 | { | 814 | { |
816 | 815 | ||
817 | unsigned long timeo = jiffies; | 816 | unsigned long timeo = jiffies; |
818 | int status; | 817 | int status; |
819 | 818 | ||
820 | if (state == FL_ERASING) | 819 | if (state == FL_ERASING) |
821 | timeo += (HZ * 400) / 1000; | 820 | timeo += (HZ * 400) / 1000; |
822 | else | 821 | else |
823 | timeo += (HZ * 20) / 1000; | 822 | timeo += (HZ * 20) / 1000; |
824 | 823 | ||
825 | led_trigger_event(nand_led_trigger, LED_FULL); | 824 | led_trigger_event(nand_led_trigger, LED_FULL); |
826 | 825 | ||
827 | /* Apply this short delay always to ensure that we do wait tWB in | 826 | /* Apply this short delay always to ensure that we do wait tWB in |
828 | * any case on any machine. */ | 827 | * any case on any machine. */ |
829 | ndelay (100); | 828 | ndelay(100); |
830 | 829 | ||
831 | if ((state == FL_ERASING) && (this->options & NAND_IS_AND)) | 830 | if ((state == FL_ERASING) && (this->options & NAND_IS_AND)) |
832 | this->cmdfunc (mtd, NAND_CMD_STATUS_MULTI, -1, -1); | 831 | this->cmdfunc(mtd, NAND_CMD_STATUS_MULTI, -1, -1); |
833 | else | 832 | else |
834 | this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); | 833 | this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); |
835 | 834 | ||
836 | while (time_before(jiffies, timeo)) { | 835 | while (time_before(jiffies, timeo)) { |
837 | /* Check, if we were interrupted */ | 836 | /* Check, if we were interrupted */ |
@@ -849,7 +848,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) | |||
849 | } | 848 | } |
850 | led_trigger_event(nand_led_trigger, LED_OFF); | 849 | led_trigger_event(nand_led_trigger, LED_OFF); |
851 | 850 | ||
852 | status = (int) this->read_byte(mtd); | 851 | status = (int)this->read_byte(mtd); |
853 | return status; | 852 | return status; |
854 | } | 853 | } |
855 | 854 | ||
@@ -868,31 +867,31 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) | |||
868 | * | 867 | * |
869 | * Cached programming is not supported yet. | 868 | * Cached programming is not supported yet. |
870 | */ | 869 | */ |
871 | static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, | 870 | static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int page, |
872 | u_char *oob_buf, struct nand_oobinfo *oobsel, int cached) | 871 | u_char *oob_buf, struct nand_oobinfo *oobsel, int cached) |
873 | { | 872 | { |
874 | int i, status; | 873 | int i, status; |
875 | u_char ecc_code[32]; | 874 | u_char ecc_code[32]; |
876 | int eccmode = oobsel->useecc ? this->eccmode : NAND_ECC_NONE; | 875 | int eccmode = oobsel->useecc ? this->eccmode : NAND_ECC_NONE; |
877 | int *oob_config = oobsel->eccpos; | 876 | int *oob_config = oobsel->eccpos; |
878 | int datidx = 0, eccidx = 0, eccsteps = this->eccsteps; | 877 | int datidx = 0, eccidx = 0, eccsteps = this->eccsteps; |
879 | int eccbytes = 0; | 878 | int eccbytes = 0; |
880 | 879 | ||
881 | /* FIXME: Enable cached programming */ | 880 | /* FIXME: Enable cached programming */ |
882 | cached = 0; | 881 | cached = 0; |
883 | 882 | ||
884 | /* Send command to begin auto page programming */ | 883 | /* Send command to begin auto page programming */ |
885 | this->cmdfunc (mtd, NAND_CMD_SEQIN, 0x00, page); | 884 | this->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); |
886 | 885 | ||
887 | /* Write out complete page of data, take care of eccmode */ | 886 | /* Write out complete page of data, take care of eccmode */ |
888 | switch (eccmode) { | 887 | switch (eccmode) { |
889 | /* No ecc, write all */ | 888 | /* No ecc, write all */ |
890 | case NAND_ECC_NONE: | 889 | case NAND_ECC_NONE: |
891 | printk (KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n"); | 890 | printk(KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n"); |
892 | this->write_buf(mtd, this->data_poi, mtd->oobblock); | 891 | this->write_buf(mtd, this->data_poi, mtd->oobblock); |
893 | break; | 892 | break; |
894 | 893 | ||
895 | /* Software ecc 3/256, write all */ | 894 | /* Software ecc 3/256, write all */ |
896 | case NAND_ECC_SOFT: | 895 | case NAND_ECC_SOFT: |
897 | for (; eccsteps; eccsteps--) { | 896 | for (; eccsteps; eccsteps--) { |
898 | this->calculate_ecc(mtd, &this->data_poi[datidx], ecc_code); | 897 | this->calculate_ecc(mtd, &this->data_poi[datidx], ecc_code); |
@@ -928,11 +927,11 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa | |||
928 | this->write_buf(mtd, oob_buf, mtd->oobsize); | 927 | this->write_buf(mtd, oob_buf, mtd->oobsize); |
929 | 928 | ||
930 | /* Send command to actually program the data */ | 929 | /* Send command to actually program the data */ |
931 | this->cmdfunc (mtd, cached ? NAND_CMD_CACHEDPROG : NAND_CMD_PAGEPROG, -1, -1); | 930 | this->cmdfunc(mtd, cached ? NAND_CMD_CACHEDPROG : NAND_CMD_PAGEPROG, -1, -1); |
932 | 931 | ||
933 | if (!cached) { | 932 | if (!cached) { |
934 | /* call wait ready function */ | 933 | /* call wait ready function */ |
935 | status = this->waitfunc (mtd, this, FL_WRITING); | 934 | status = this->waitfunc(mtd, this, FL_WRITING); |
936 | 935 | ||
937 | /* See if operation failed and additional status checks are available */ | 936 | /* See if operation failed and additional status checks are available */ |
938 | if ((status & NAND_STATUS_FAIL) && (this->errstat)) { | 937 | if ((status & NAND_STATUS_FAIL) && (this->errstat)) { |
@@ -941,12 +940,12 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa | |||
941 | 940 | ||
942 | /* See if device thinks it succeeded */ | 941 | /* See if device thinks it succeeded */ |
943 | if (status & NAND_STATUS_FAIL) { | 942 | if (status & NAND_STATUS_FAIL) { |
944 | DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write, page 0x%08x, ", __FUNCTION__, page); | 943 | DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write, page 0x%08x, ", __FUNCTION__, page); |
945 | return -EIO; | 944 | return -EIO; |
946 | } | 945 | } |
947 | } else { | 946 | } else { |
948 | /* FIXME: Implement cached programming ! */ | 947 | /* FIXME: Implement cached programming ! */ |
949 | /* wait until cache is ready*/ | 948 | /* wait until cache is ready */ |
950 | // status = this->waitfunc (mtd, this, FL_CACHEDRPG); | 949 | // status = this->waitfunc (mtd, this, FL_CACHEDRPG); |
951 | } | 950 | } |
952 | return 0; | 951 | return 0; |
@@ -972,24 +971,24 @@ static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int pa | |||
972 | * the error later when the ECC page check fails, but we would rather catch | 971 | * the error later when the ECC page check fails, but we would rather catch |
973 | * it early in the page write stage. Better to write no data than invalid data. | 972 | * it early in the page write stage. Better to write no data than invalid data. |
974 | */ | 973 | */ |
975 | static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, | 974 | static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, |
976 | u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode) | 975 | u_char *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode) |
977 | { | 976 | { |
978 | int i, j, datidx = 0, oobofs = 0, res = -EIO; | 977 | int i, j, datidx = 0, oobofs = 0, res = -EIO; |
979 | int eccsteps = this->eccsteps; | 978 | int eccsteps = this->eccsteps; |
980 | int hweccbytes; | 979 | int hweccbytes; |
981 | u_char oobdata[64]; | 980 | u_char oobdata[64]; |
982 | 981 | ||
983 | hweccbytes = (this->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0; | 982 | hweccbytes = (this->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0; |
984 | 983 | ||
985 | /* Send command to read back the first page */ | 984 | /* Send command to read back the first page */ |
986 | this->cmdfunc (mtd, NAND_CMD_READ0, 0, page); | 985 | this->cmdfunc(mtd, NAND_CMD_READ0, 0, page); |
987 | 986 | ||
988 | for(;;) { | 987 | for (;;) { |
989 | for (j = 0; j < eccsteps; j++) { | 988 | for (j = 0; j < eccsteps; j++) { |
990 | /* Loop through and verify the data */ | 989 | /* Loop through and verify the data */ |
991 | if (this->verify_buf(mtd, &this->data_poi[datidx], mtd->eccsize)) { | 990 | if (this->verify_buf(mtd, &this->data_poi[datidx], mtd->eccsize)) { |
992 | DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); | 991 | DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); |
993 | goto out; | 992 | goto out; |
994 | } | 993 | } |
995 | datidx += mtd->eccsize; | 994 | datidx += mtd->eccsize; |
@@ -997,7 +996,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int | |||
997 | if (!hweccbytes) | 996 | if (!hweccbytes) |
998 | continue; | 997 | continue; |
999 | if (this->verify_buf(mtd, &this->oob_buf[oobofs], hweccbytes)) { | 998 | if (this->verify_buf(mtd, &this->oob_buf[oobofs], hweccbytes)) { |
1000 | DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); | 999 | DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); |
1001 | goto out; | 1000 | goto out; |
1002 | } | 1001 | } |
1003 | oobofs += hweccbytes; | 1002 | oobofs += hweccbytes; |
@@ -1008,7 +1007,7 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int | |||
1008 | */ | 1007 | */ |
1009 | if (oobmode) { | 1008 | if (oobmode) { |
1010 | if (this->verify_buf(mtd, &oob_buf[oobofs], mtd->oobsize - hweccbytes * eccsteps)) { | 1009 | if (this->verify_buf(mtd, &oob_buf[oobofs], mtd->oobsize - hweccbytes * eccsteps)) { |
1011 | DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); | 1010 | DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); |
1012 | goto out; | 1011 | goto out; |
1013 | } | 1012 | } |
1014 | } else { | 1013 | } else { |
@@ -1020,10 +1019,9 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int | |||
1020 | 1019 | ||
1021 | for (i = 0; i < ecccnt; i++) { | 1020 | for (i = 0; i < ecccnt; i++) { |
1022 | int idx = oobsel->eccpos[i]; | 1021 | int idx = oobsel->eccpos[i]; |
1023 | if (oobdata[idx] != oob_buf[oobofs + idx] ) { | 1022 | if (oobdata[idx] != oob_buf[oobofs + idx]) { |
1024 | DEBUG (MTD_DEBUG_LEVEL0, | 1023 | DEBUG(MTD_DEBUG_LEVEL0, "%s: Failed ECC write verify, page 0x%08x, %6i bytes were succesful\n", |
1025 | "%s: Failed ECC write " | 1024 | __FUNCTION__, page, i); |
1026 | "verify, page 0x%08x, " "%6i bytes were succesful\n", __FUNCTION__, page, i); | ||
1027 | goto out; | 1025 | goto out; |
1028 | } | 1026 | } |
1029 | } | 1027 | } |
@@ -1039,9 +1037,9 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int | |||
1039 | * is marked as NOAUTOINCR by the board driver. | 1037 | * is marked as NOAUTOINCR by the board driver. |
1040 | * Do this also before returning, so the chip is | 1038 | * Do this also before returning, so the chip is |
1041 | * ready for the next command. | 1039 | * ready for the next command. |
1042 | */ | 1040 | */ |
1043 | if (!this->dev_ready) | 1041 | if (!this->dev_ready) |
1044 | udelay (this->chip_delay); | 1042 | udelay(this->chip_delay); |
1045 | else | 1043 | else |
1046 | nand_wait_ready(mtd); | 1044 | nand_wait_ready(mtd); |
1047 | 1045 | ||
@@ -1049,17 +1047,16 @@ static int nand_verify_pages (struct mtd_info *mtd, struct nand_chip *this, int | |||
1049 | if (!numpages) | 1047 | if (!numpages) |
1050 | return 0; | 1048 | return 0; |
1051 | 1049 | ||
1052 | |||
1053 | /* Check, if the chip supports auto page increment */ | 1050 | /* Check, if the chip supports auto page increment */ |
1054 | if (!NAND_CANAUTOINCR(this)) | 1051 | if (!NAND_CANAUTOINCR(this)) |
1055 | this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); | 1052 | this->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); |
1056 | } | 1053 | } |
1057 | /* | 1054 | /* |
1058 | * Terminate the read command. We come here in case of an error | 1055 | * Terminate the read command. We come here in case of an error |
1059 | * So we must issue a reset command. | 1056 | * So we must issue a reset command. |
1060 | */ | 1057 | */ |
1061 | out: | 1058 | out: |
1062 | this->cmdfunc (mtd, NAND_CMD_RESET, -1, -1); | 1059 | this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); |
1063 | return res; | 1060 | return res; |
1064 | } | 1061 | } |
1065 | #endif | 1062 | #endif |
@@ -1075,12 +1072,11 @@ out: | |||
1075 | * This function simply calls nand_do_read_ecc with oob buffer and oobsel = NULL | 1072 | * This function simply calls nand_do_read_ecc with oob buffer and oobsel = NULL |
1076 | * and flags = 0xff | 1073 | * and flags = 0xff |
1077 | */ | 1074 | */ |
1078 | static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf) | 1075 | static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) |
1079 | { | 1076 | { |
1080 | return nand_do_read_ecc (mtd, from, len, retlen, buf, NULL, &mtd->oobinfo, 0xff); | 1077 | return nand_do_read_ecc(mtd, from, len, retlen, buf, NULL, &mtd->oobinfo, 0xff); |
1081 | } | 1078 | } |
1082 | 1079 | ||
1083 | |||
1084 | /** | 1080 | /** |
1085 | * nand_read_ecc - [MTD Interface] MTD compability function for nand_do_read_ecc | 1081 | * nand_read_ecc - [MTD Interface] MTD compability function for nand_do_read_ecc |
1086 | * @mtd: MTD device structure | 1082 | * @mtd: MTD device structure |
@@ -1093,8 +1089,8 @@ static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * re | |||
1093 | * | 1089 | * |
1094 | * This function simply calls nand_do_read_ecc with flags = 0xff | 1090 | * This function simply calls nand_do_read_ecc with flags = 0xff |
1095 | */ | 1091 | */ |
1096 | static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | 1092 | static int nand_read_ecc(struct mtd_info *mtd, loff_t from, size_t len, |
1097 | size_t * retlen, u_char * buf, u_char * oob_buf, struct nand_oobinfo *oobsel) | 1093 | size_t *retlen, u_char *buf, u_char *oob_buf, struct nand_oobinfo *oobsel) |
1098 | { | 1094 | { |
1099 | /* use userspace supplied oobinfo, if zero */ | 1095 | /* use userspace supplied oobinfo, if zero */ |
1100 | if (oobsel == NULL) | 1096 | if (oobsel == NULL) |
@@ -1102,7 +1098,6 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1102 | return nand_do_read_ecc(mtd, from, len, retlen, buf, oob_buf, oobsel, 0xff); | 1098 | return nand_do_read_ecc(mtd, from, len, retlen, buf, oob_buf, oobsel, 0xff); |
1103 | } | 1099 | } |
1104 | 1100 | ||
1105 | |||
1106 | /** | 1101 | /** |
1107 | * nand_do_read_ecc - [MTD Interface] Read data with ECC | 1102 | * nand_do_read_ecc - [MTD Interface] Read data with ECC |
1108 | * @mtd: MTD device structure | 1103 | * @mtd: MTD device structure |
@@ -1119,9 +1114,8 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1119 | * | 1114 | * |
1120 | * NAND read with ECC | 1115 | * NAND read with ECC |
1121 | */ | 1116 | */ |
1122 | int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | 1117 | int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len, |
1123 | size_t * retlen, u_char * buf, u_char * oob_buf, | 1118 | size_t *retlen, u_char *buf, u_char *oob_buf, struct nand_oobinfo *oobsel, int flags) |
1124 | struct nand_oobinfo *oobsel, int flags) | ||
1125 | { | 1119 | { |
1126 | 1120 | ||
1127 | int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1; | 1121 | int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1; |
@@ -1130,26 +1124,25 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1130 | u_char *data_poi, *oob_data = oob_buf; | 1124 | u_char *data_poi, *oob_data = oob_buf; |
1131 | u_char ecc_calc[32]; | 1125 | u_char ecc_calc[32]; |
1132 | u_char ecc_code[32]; | 1126 | u_char ecc_code[32]; |
1133 | int eccmode, eccsteps; | 1127 | int eccmode, eccsteps; |
1134 | int *oob_config, datidx; | 1128 | int *oob_config, datidx; |
1135 | int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; | 1129 | int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; |
1136 | int eccbytes; | 1130 | int eccbytes; |
1137 | int compareecc = 1; | 1131 | int compareecc = 1; |
1138 | int oobreadlen; | 1132 | int oobreadlen; |
1139 | 1133 | ||
1140 | 1134 | DEBUG(MTD_DEBUG_LEVEL3, "nand_read_ecc: from = 0x%08x, len = %i\n", (unsigned int)from, (int)len); | |
1141 | DEBUG (MTD_DEBUG_LEVEL3, "nand_read_ecc: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); | ||
1142 | 1135 | ||
1143 | /* Do not allow reads past end of device */ | 1136 | /* Do not allow reads past end of device */ |
1144 | if ((from + len) > mtd->size) { | 1137 | if ((from + len) > mtd->size) { |
1145 | DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: Attempt read beyond end of device\n"); | 1138 | DEBUG(MTD_DEBUG_LEVEL0, "nand_read_ecc: Attempt read beyond end of device\n"); |
1146 | *retlen = 0; | 1139 | *retlen = 0; |
1147 | return -EINVAL; | 1140 | return -EINVAL; |
1148 | } | 1141 | } |
1149 | 1142 | ||
1150 | /* Grab the lock and see if the device is available */ | 1143 | /* Grab the lock and see if the device is available */ |
1151 | if (flags & NAND_GET_DEVICE) | 1144 | if (flags & NAND_GET_DEVICE) |
1152 | nand_get_device (this, mtd, FL_READING); | 1145 | nand_get_device(this, mtd, FL_READING); |
1153 | 1146 | ||
1154 | /* Autoplace of oob data ? Use the default placement scheme */ | 1147 | /* Autoplace of oob data ? Use the default placement scheme */ |
1155 | if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) | 1148 | if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) |
@@ -1163,7 +1156,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1163 | this->select_chip(mtd, chipnr); | 1156 | this->select_chip(mtd, chipnr); |
1164 | 1157 | ||
1165 | /* First we calculate the starting page */ | 1158 | /* First we calculate the starting page */ |
1166 | realpage = (int) (from >> this->page_shift); | 1159 | realpage = (int)(from >> this->page_shift); |
1167 | page = realpage & this->pagemask; | 1160 | page = realpage & this->pagemask; |
1168 | 1161 | ||
1169 | /* Get raw starting column */ | 1162 | /* Get raw starting column */ |
@@ -1201,13 +1194,13 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1201 | if (realpage == this->pagebuf && !oob_buf) { | 1194 | if (realpage == this->pagebuf && !oob_buf) { |
1202 | /* aligned read ? */ | 1195 | /* aligned read ? */ |
1203 | if (aligned) | 1196 | if (aligned) |
1204 | memcpy (data_poi, this->data_buf, end); | 1197 | memcpy(data_poi, this->data_buf, end); |
1205 | goto readdata; | 1198 | goto readdata; |
1206 | } | 1199 | } |
1207 | 1200 | ||
1208 | /* Check, if we must send the read command */ | 1201 | /* Check, if we must send the read command */ |
1209 | if (sndcmd) { | 1202 | if (sndcmd) { |
1210 | this->cmdfunc (mtd, NAND_CMD_READ0, 0x00, page); | 1203 | this->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); |
1211 | sndcmd = 0; | 1204 | sndcmd = 0; |
1212 | } | 1205 | } |
1213 | 1206 | ||
@@ -1219,24 +1212,26 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1219 | eccsteps = this->eccsteps; | 1212 | eccsteps = this->eccsteps; |
1220 | 1213 | ||
1221 | switch (eccmode) { | 1214 | switch (eccmode) { |
1222 | case NAND_ECC_NONE: { /* No ECC, Read in a page */ | 1215 | case NAND_ECC_NONE:{ |
1223 | static unsigned long lastwhinge = 0; | 1216 | /* No ECC, Read in a page */ |
1224 | if ((lastwhinge / HZ) != (jiffies / HZ)) { | 1217 | static unsigned long lastwhinge = 0; |
1225 | printk (KERN_WARNING "Reading data from NAND FLASH without ECC is not recommended\n"); | 1218 | if ((lastwhinge / HZ) != (jiffies / HZ)) { |
1226 | lastwhinge = jiffies; | 1219 | printk(KERN_WARNING |
1220 | "Reading data from NAND FLASH without ECC is not recommended\n"); | ||
1221 | lastwhinge = jiffies; | ||
1222 | } | ||
1223 | this->read_buf(mtd, data_poi, end); | ||
1224 | break; | ||
1227 | } | 1225 | } |
1228 | this->read_buf(mtd, data_poi, end); | ||
1229 | break; | ||
1230 | } | ||
1231 | 1226 | ||
1232 | case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */ | 1227 | case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */ |
1233 | this->read_buf(mtd, data_poi, end); | 1228 | this->read_buf(mtd, data_poi, end); |
1234 | for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=3, datidx += ecc) | 1229 | for (i = 0, datidx = 0; eccsteps; eccsteps--, i += 3, datidx += ecc) |
1235 | this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]); | 1230 | this->calculate_ecc(mtd, &data_poi[datidx], &ecc_calc[i]); |
1236 | break; | 1231 | break; |
1237 | 1232 | ||
1238 | default: | 1233 | default: |
1239 | for (i = 0, datidx = 0; eccsteps; eccsteps--, i+=eccbytes, datidx += ecc) { | 1234 | for (i = 0, datidx = 0; eccsteps; eccsteps--, i += eccbytes, datidx += ecc) { |
1240 | this->enable_hwecc(mtd, NAND_ECC_READ); | 1235 | this->enable_hwecc(mtd, NAND_ECC_READ); |
1241 | this->read_buf(mtd, &data_poi[datidx], ecc); | 1236 | this->read_buf(mtd, &data_poi[datidx], ecc); |
1242 | 1237 | ||
@@ -1252,8 +1247,8 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1252 | * does the error correction on the fly */ | 1247 | * does the error correction on the fly */ |
1253 | ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]); | 1248 | ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]); |
1254 | if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { | 1249 | if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { |
1255 | DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " | 1250 | DEBUG(MTD_DEBUG_LEVEL0, "nand_read_ecc: " |
1256 | "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr); | 1251 | "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr); |
1257 | ecc_failed++; | 1252 | ecc_failed++; |
1258 | } | 1253 | } |
1259 | } else { | 1254 | } else { |
@@ -1274,7 +1269,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1274 | for (j = 0; j < oobsel->eccbytes; j++) | 1269 | for (j = 0; j < oobsel->eccbytes; j++) |
1275 | ecc_code[j] = oob_data[oob_config[j]]; | 1270 | ecc_code[j] = oob_data[oob_config[j]]; |
1276 | 1271 | ||
1277 | /* correct data, if neccecary */ | 1272 | /* correct data, if necessary */ |
1278 | for (i = 0, j = 0, datidx = 0; i < this->eccsteps; i++, datidx += ecc) { | 1273 | for (i = 0, j = 0, datidx = 0; i < this->eccsteps; i++, datidx += ecc) { |
1279 | ecc_status = this->correct_data(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]); | 1274 | ecc_status = this->correct_data(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]); |
1280 | 1275 | ||
@@ -1291,16 +1286,16 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1291 | } | 1286 | } |
1292 | 1287 | ||
1293 | if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { | 1288 | if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { |
1294 | DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page); | 1289 | DEBUG(MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page); |
1295 | ecc_failed++; | 1290 | ecc_failed++; |
1296 | } | 1291 | } |
1297 | } | 1292 | } |
1298 | 1293 | ||
1299 | readoob: | 1294 | readoob: |
1300 | /* check, if we have a fs supplied oob-buffer */ | 1295 | /* check, if we have a fs supplied oob-buffer */ |
1301 | if (oob_buf) { | 1296 | if (oob_buf) { |
1302 | /* without autoplace. Legacy mode used by YAFFS1 */ | 1297 | /* without autoplace. Legacy mode used by YAFFS1 */ |
1303 | switch(oobsel->useecc) { | 1298 | switch (oobsel->useecc) { |
1304 | case MTD_NANDECC_AUTOPLACE: | 1299 | case MTD_NANDECC_AUTOPLACE: |
1305 | case MTD_NANDECC_AUTOPL_USR: | 1300 | case MTD_NANDECC_AUTOPL_USR: |
1306 | /* Walk through the autoplace chunks */ | 1301 | /* Walk through the autoplace chunks */ |
@@ -1313,7 +1308,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1313 | break; | 1308 | break; |
1314 | case MTD_NANDECC_PLACE: | 1309 | case MTD_NANDECC_PLACE: |
1315 | /* YAFFS1 legacy mode */ | 1310 | /* YAFFS1 legacy mode */ |
1316 | oob_data += this->eccsteps * sizeof (int); | 1311 | oob_data += this->eccsteps * sizeof(int); |
1317 | default: | 1312 | default: |
1318 | oob_data += mtd->oobsize; | 1313 | oob_data += mtd->oobsize; |
1319 | } | 1314 | } |
@@ -1331,9 +1326,9 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1331 | * Do this before the AUTOINCR check, so no problems | 1326 | * Do this before the AUTOINCR check, so no problems |
1332 | * arise if a chip which does auto increment | 1327 | * arise if a chip which does auto increment |
1333 | * is marked as NOAUTOINCR by the board driver. | 1328 | * is marked as NOAUTOINCR by the board driver. |
1334 | */ | 1329 | */ |
1335 | if (!this->dev_ready) | 1330 | if (!this->dev_ready) |
1336 | udelay (this->chip_delay); | 1331 | udelay(this->chip_delay); |
1337 | else | 1332 | else |
1338 | nand_wait_ready(mtd); | 1333 | nand_wait_ready(mtd); |
1339 | 1334 | ||
@@ -1354,7 +1349,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1354 | } | 1349 | } |
1355 | /* Check, if the chip supports auto page increment | 1350 | /* Check, if the chip supports auto page increment |
1356 | * or if we have hit a block boundary. | 1351 | * or if we have hit a block boundary. |
1357 | */ | 1352 | */ |
1358 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) | 1353 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) |
1359 | sndcmd = 1; | 1354 | sndcmd = 1; |
1360 | } | 1355 | } |
@@ -1382,13 +1377,13 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, | |||
1382 | * | 1377 | * |
1383 | * NAND read out-of-band data from the spare area | 1378 | * NAND read out-of-band data from the spare area |
1384 | */ | 1379 | */ |
1385 | static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf) | 1380 | static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) |
1386 | { | 1381 | { |
1387 | int i, col, page, chipnr; | 1382 | int i, col, page, chipnr; |
1388 | struct nand_chip *this = mtd->priv; | 1383 | struct nand_chip *this = mtd->priv; |
1389 | int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; | 1384 | int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; |
1390 | 1385 | ||
1391 | DEBUG (MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); | 1386 | DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08x, len = %i\n", (unsigned int)from, (int)len); |
1392 | 1387 | ||
1393 | /* Shift to get page */ | 1388 | /* Shift to get page */ |
1394 | page = (int)(from >> this->page_shift); | 1389 | page = (int)(from >> this->page_shift); |
@@ -1402,19 +1397,19 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t | |||
1402 | 1397 | ||
1403 | /* Do not allow reads past end of device */ | 1398 | /* Do not allow reads past end of device */ |
1404 | if ((from + len) > mtd->size) { | 1399 | if ((from + len) > mtd->size) { |
1405 | DEBUG (MTD_DEBUG_LEVEL0, "nand_read_oob: Attempt read beyond end of device\n"); | 1400 | DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: Attempt read beyond end of device\n"); |
1406 | *retlen = 0; | 1401 | *retlen = 0; |
1407 | return -EINVAL; | 1402 | return -EINVAL; |
1408 | } | 1403 | } |
1409 | 1404 | ||
1410 | /* Grab the lock and see if the device is available */ | 1405 | /* Grab the lock and see if the device is available */ |
1411 | nand_get_device (this, mtd , FL_READING); | 1406 | nand_get_device(this, mtd, FL_READING); |
1412 | 1407 | ||
1413 | /* Select the NAND device */ | 1408 | /* Select the NAND device */ |
1414 | this->select_chip(mtd, chipnr); | 1409 | this->select_chip(mtd, chipnr); |
1415 | 1410 | ||
1416 | /* Send the read command */ | 1411 | /* Send the read command */ |
1417 | this->cmdfunc (mtd, NAND_CMD_READOOB, col, page & this->pagemask); | 1412 | this->cmdfunc(mtd, NAND_CMD_READOOB, col, page & this->pagemask); |
1418 | /* | 1413 | /* |
1419 | * Read the data, if we read more than one page | 1414 | * Read the data, if we read more than one page |
1420 | * oob data, let the device transfer the data ! | 1415 | * oob data, let the device transfer the data ! |
@@ -1444,16 +1439,16 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t | |||
1444 | * is marked as NOAUTOINCR by the board driver. | 1439 | * is marked as NOAUTOINCR by the board driver. |
1445 | */ | 1440 | */ |
1446 | if (!this->dev_ready) | 1441 | if (!this->dev_ready) |
1447 | udelay (this->chip_delay); | 1442 | udelay(this->chip_delay); |
1448 | else | 1443 | else |
1449 | nand_wait_ready(mtd); | 1444 | nand_wait_ready(mtd); |
1450 | 1445 | ||
1451 | /* Check, if the chip supports auto page increment | 1446 | /* Check, if the chip supports auto page increment |
1452 | * or if we have hit a block boundary. | 1447 | * or if we have hit a block boundary. |
1453 | */ | 1448 | */ |
1454 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) { | 1449 | if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) { |
1455 | /* For subsequent page reads set offset to 0 */ | 1450 | /* For subsequent page reads set offset to 0 */ |
1456 | this->cmdfunc (mtd, NAND_CMD_READOOB, 0x0, page & this->pagemask); | 1451 | this->cmdfunc(mtd, NAND_CMD_READOOB, 0x0, page & this->pagemask); |
1457 | } | 1452 | } |
1458 | } | 1453 | } |
1459 | } | 1454 | } |
@@ -1476,43 +1471,43 @@ static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t | |||
1476 | * | 1471 | * |
1477 | * Read raw data including oob into buffer | 1472 | * Read raw data including oob into buffer |
1478 | */ | 1473 | */ |
1479 | int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, size_t ooblen) | 1474 | int nand_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, size_t ooblen) |
1480 | { | 1475 | { |
1481 | struct nand_chip *this = mtd->priv; | 1476 | struct nand_chip *this = mtd->priv; |
1482 | int page = (int) (from >> this->page_shift); | 1477 | int page = (int)(from >> this->page_shift); |
1483 | int chip = (int) (from >> this->chip_shift); | 1478 | int chip = (int)(from >> this->chip_shift); |
1484 | int sndcmd = 1; | 1479 | int sndcmd = 1; |
1485 | int cnt = 0; | 1480 | int cnt = 0; |
1486 | int pagesize = mtd->oobblock + mtd->oobsize; | 1481 | int pagesize = mtd->oobblock + mtd->oobsize; |
1487 | int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; | 1482 | int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; |
1488 | 1483 | ||
1489 | /* Do not allow reads past end of device */ | 1484 | /* Do not allow reads past end of device */ |
1490 | if ((from + len) > mtd->size) { | 1485 | if ((from + len) > mtd->size) { |
1491 | DEBUG (MTD_DEBUG_LEVEL0, "nand_read_raw: Attempt read beyond end of device\n"); | 1486 | DEBUG(MTD_DEBUG_LEVEL0, "nand_read_raw: Attempt read beyond end of device\n"); |
1492 | return -EINVAL; | 1487 | return -EINVAL; |
1493 | } | 1488 | } |
1494 | 1489 | ||
1495 | /* Grab the lock and see if the device is available */ | 1490 | /* Grab the lock and see if the device is available */ |
1496 | nand_get_device (this, mtd , FL_READING); | 1491 | nand_get_device(this, mtd, FL_READING); |
1497 | 1492 | ||
1498 | this->select_chip (mtd, chip); | 1493 | this->select_chip(mtd, chip); |
1499 | 1494 | ||
1500 | /* Add requested oob length */ | 1495 | /* Add requested oob length */ |
1501 | len += ooblen; | 1496 | len += ooblen; |
1502 | 1497 | ||
1503 | while (len) { | 1498 | while (len) { |
1504 | if (sndcmd) | 1499 | if (sndcmd) |
1505 | this->cmdfunc (mtd, NAND_CMD_READ0, 0, page & this->pagemask); | 1500 | this->cmdfunc(mtd, NAND_CMD_READ0, 0, page & this->pagemask); |
1506 | sndcmd = 0; | 1501 | sndcmd = 0; |
1507 | 1502 | ||
1508 | this->read_buf (mtd, &buf[cnt], pagesize); | 1503 | this->read_buf(mtd, &buf[cnt], pagesize); |
1509 | 1504 | ||
1510 | len -= pagesize; | 1505 | len -= pagesize; |
1511 | cnt += pagesize; | 1506 | cnt += pagesize; |
1512 | page++; | 1507 | page++; |
1513 | 1508 | ||
1514 | if (!this->dev_ready) | 1509 | if (!this->dev_ready) |
1515 | udelay (this->chip_delay); | 1510 | udelay(this->chip_delay); |
1516 | else | 1511 | else |
1517 | nand_wait_ready(mtd); | 1512 | nand_wait_ready(mtd); |
1518 | 1513 | ||
@@ -1526,7 +1521,6 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, | |||
1526 | return 0; | 1521 | return 0; |
1527 | } | 1522 | } |
1528 | 1523 | ||
1529 | |||
1530 | /** | 1524 | /** |
1531 | * nand_prepare_oobbuf - [GENERIC] Prepare the out of band buffer | 1525 | * nand_prepare_oobbuf - [GENERIC] Prepare the out of band buffer |
1532 | * @mtd: MTD device structure | 1526 | * @mtd: MTD device structure |
@@ -1550,8 +1544,8 @@ int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, | |||
1550 | * forces the 0xff fill before using the buffer again. | 1544 | * forces the 0xff fill before using the buffer again. |
1551 | * | 1545 | * |
1552 | */ | 1546 | */ |
1553 | static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct nand_oobinfo *oobsel, | 1547 | static u_char *nand_prepare_oobbuf(struct mtd_info *mtd, u_char *fsbuf, struct nand_oobinfo *oobsel, |
1554 | int autoplace, int numpages) | 1548 | int autoplace, int numpages) |
1555 | { | 1549 | { |
1556 | struct nand_chip *this = mtd->priv; | 1550 | struct nand_chip *this = mtd->priv; |
1557 | int i, len, ofs; | 1551 | int i, len, ofs; |
@@ -1562,8 +1556,7 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct | |||
1562 | 1556 | ||
1563 | /* Check, if the buffer must be filled with ff again */ | 1557 | /* Check, if the buffer must be filled with ff again */ |
1564 | if (this->oobdirty) { | 1558 | if (this->oobdirty) { |
1565 | memset (this->oob_buf, 0xff, | 1559 | memset(this->oob_buf, 0xff, mtd->oobsize << (this->phys_erase_shift - this->page_shift)); |
1566 | mtd->oobsize << (this->phys_erase_shift - this->page_shift)); | ||
1567 | this->oobdirty = 0; | 1560 | this->oobdirty = 0; |
1568 | } | 1561 | } |
1569 | 1562 | ||
@@ -1578,7 +1571,7 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct | |||
1578 | for (i = 0, len = 0; len < mtd->oobavail; i++) { | 1571 | for (i = 0, len = 0; len < mtd->oobavail; i++) { |
1579 | int to = ofs + oobsel->oobfree[i][0]; | 1572 | int to = ofs + oobsel->oobfree[i][0]; |
1580 | int num = oobsel->oobfree[i][1]; | 1573 | int num = oobsel->oobfree[i][1]; |
1581 | memcpy (&this->oob_buf[to], fsbuf, num); | 1574 | memcpy(&this->oob_buf[to], fsbuf, num); |
1582 | len += num; | 1575 | len += num; |
1583 | fsbuf += num; | 1576 | fsbuf += num; |
1584 | } | 1577 | } |
@@ -1600,9 +1593,9 @@ static u_char * nand_prepare_oobbuf (struct mtd_info *mtd, u_char *fsbuf, struct | |||
1600 | * This function simply calls nand_write_ecc with oob buffer and oobsel = NULL | 1593 | * This function simply calls nand_write_ecc with oob buffer and oobsel = NULL |
1601 | * | 1594 | * |
1602 | */ | 1595 | */ |
1603 | static int nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf) | 1596 | static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) |
1604 | { | 1597 | { |
1605 | return (nand_write_ecc (mtd, to, len, retlen, buf, NULL, NULL)); | 1598 | return (nand_write_ecc(mtd, to, len, retlen, buf, NULL, NULL)); |
1606 | } | 1599 | } |
1607 | 1600 | ||
1608 | /** | 1601 | /** |
@@ -1617,34 +1610,35 @@ static int nand_write (struct mtd_info *mtd, loff_t to, size_t len, size_t * ret | |||
1617 | * | 1610 | * |
1618 | * NAND write with ECC | 1611 | * NAND write with ECC |
1619 | */ | 1612 | */ |
1620 | static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | 1613 | static int nand_write_ecc(struct mtd_info *mtd, loff_t to, size_t len, |
1621 | size_t * retlen, const u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel) | 1614 | size_t *retlen, const u_char *buf, u_char *eccbuf, |
1615 | struct nand_oobinfo *oobsel) | ||
1622 | { | 1616 | { |
1623 | int startpage, page, ret = -EIO, oob = 0, written = 0, chipnr; | 1617 | int startpage, page, ret = -EIO, oob = 0, written = 0, chipnr; |
1624 | int autoplace = 0, numpages, totalpages; | 1618 | int autoplace = 0, numpages, totalpages; |
1625 | struct nand_chip *this = mtd->priv; | 1619 | struct nand_chip *this = mtd->priv; |
1626 | u_char *oobbuf, *bufstart; | 1620 | u_char *oobbuf, *bufstart; |
1627 | int ppblock = (1 << (this->phys_erase_shift - this->page_shift)); | 1621 | int ppblock = (1 << (this->phys_erase_shift - this->page_shift)); |
1628 | 1622 | ||
1629 | DEBUG (MTD_DEBUG_LEVEL3, "nand_write_ecc: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); | 1623 | DEBUG(MTD_DEBUG_LEVEL3, "nand_write_ecc: to = 0x%08x, len = %i\n", (unsigned int)to, (int)len); |
1630 | 1624 | ||
1631 | /* Initialize retlen, in case of early exit */ | 1625 | /* Initialize retlen, in case of early exit */ |
1632 | *retlen = 0; | 1626 | *retlen = 0; |
1633 | 1627 | ||
1634 | /* Do not allow write past end of device */ | 1628 | /* Do not allow write past end of device */ |
1635 | if ((to + len) > mtd->size) { | 1629 | if ((to + len) > mtd->size) { |
1636 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: Attempt to write past end of page\n"); | 1630 | DEBUG(MTD_DEBUG_LEVEL0, "nand_write_ecc: Attempt to write past end of page\n"); |
1637 | return -EINVAL; | 1631 | return -EINVAL; |
1638 | } | 1632 | } |
1639 | 1633 | ||
1640 | /* reject writes, which are not page aligned */ | 1634 | /* reject writes, which are not page aligned */ |
1641 | if (NOTALIGNED (to) || NOTALIGNED(len)) { | 1635 | if (NOTALIGNED(to) || NOTALIGNED(len)) { |
1642 | printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); | 1636 | printk(KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); |
1643 | return -EINVAL; | 1637 | return -EINVAL; |
1644 | } | 1638 | } |
1645 | 1639 | ||
1646 | /* Grab the lock and see if the device is available */ | 1640 | /* Grab the lock and see if the device is available */ |
1647 | nand_get_device (this, mtd, FL_WRITING); | 1641 | nand_get_device(this, mtd, FL_WRITING); |
1648 | 1642 | ||
1649 | /* Calculate chipnr */ | 1643 | /* Calculate chipnr */ |
1650 | chipnr = (int)(to >> this->chip_shift); | 1644 | chipnr = (int)(to >> this->chip_shift); |
@@ -1669,7 +1663,7 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1669 | 1663 | ||
1670 | /* Setup variables and oob buffer */ | 1664 | /* Setup variables and oob buffer */ |
1671 | totalpages = len >> this->page_shift; | 1665 | totalpages = len >> this->page_shift; |
1672 | page = (int) (to >> this->page_shift); | 1666 | page = (int)(to >> this->page_shift); |
1673 | /* Invalidate the page cache, if we write to the cached page */ | 1667 | /* Invalidate the page cache, if we write to the cached page */ |
1674 | if (page <= this->pagebuf && this->pagebuf < (page + totalpages)) | 1668 | if (page <= this->pagebuf && this->pagebuf < (page + totalpages)) |
1675 | this->pagebuf = -1; | 1669 | this->pagebuf = -1; |
@@ -1678,22 +1672,22 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1678 | page &= this->pagemask; | 1672 | page &= this->pagemask; |
1679 | startpage = page; | 1673 | startpage = page; |
1680 | /* Calc number of pages we can write in one go */ | 1674 | /* Calc number of pages we can write in one go */ |
1681 | numpages = min (ppblock - (startpage & (ppblock - 1)), totalpages); | 1675 | numpages = min(ppblock - (startpage & (ppblock - 1)), totalpages); |
1682 | oobbuf = nand_prepare_oobbuf (mtd, eccbuf, oobsel, autoplace, numpages); | 1676 | oobbuf = nand_prepare_oobbuf(mtd, eccbuf, oobsel, autoplace, numpages); |
1683 | bufstart = (u_char *)buf; | 1677 | bufstart = (u_char *) buf; |
1684 | 1678 | ||
1685 | /* Loop until all data is written */ | 1679 | /* Loop until all data is written */ |
1686 | while (written < len) { | 1680 | while (written < len) { |
1687 | 1681 | ||
1688 | this->data_poi = (u_char*) &buf[written]; | 1682 | this->data_poi = (u_char *) &buf[written]; |
1689 | /* Write one page. If this is the last page to write | 1683 | /* Write one page. If this is the last page to write |
1690 | * or the last page in this block, then use the | 1684 | * or the last page in this block, then use the |
1691 | * real pageprogram command, else select cached programming | 1685 | * real pageprogram command, else select cached programming |
1692 | * if supported by the chip. | 1686 | * if supported by the chip. |
1693 | */ | 1687 | */ |
1694 | ret = nand_write_page (mtd, this, page, &oobbuf[oob], oobsel, (--numpages > 0)); | 1688 | ret = nand_write_page(mtd, this, page, &oobbuf[oob], oobsel, (--numpages > 0)); |
1695 | if (ret) { | 1689 | if (ret) { |
1696 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: write_page failed %d\n", ret); | 1690 | DEBUG(MTD_DEBUG_LEVEL0, "nand_write_ecc: write_page failed %d\n", ret); |
1697 | goto out; | 1691 | goto out; |
1698 | } | 1692 | } |
1699 | /* Next oob page */ | 1693 | /* Next oob page */ |
@@ -1709,15 +1703,14 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1709 | /* Have we hit a block boundary ? Then we have to verify and | 1703 | /* Have we hit a block boundary ? Then we have to verify and |
1710 | * if verify is ok, we have to setup the oob buffer for | 1704 | * if verify is ok, we have to setup the oob buffer for |
1711 | * the next pages. | 1705 | * the next pages. |
1712 | */ | 1706 | */ |
1713 | if (!(page & (ppblock - 1))){ | 1707 | if (!(page & (ppblock - 1))) { |
1714 | int ofs; | 1708 | int ofs; |
1715 | this->data_poi = bufstart; | 1709 | this->data_poi = bufstart; |
1716 | ret = nand_verify_pages (mtd, this, startpage, | 1710 | ret = nand_verify_pages(mtd, this, startpage, page - startpage, |
1717 | page - startpage, | 1711 | oobbuf, oobsel, chipnr, (eccbuf != NULL)); |
1718 | oobbuf, oobsel, chipnr, (eccbuf != NULL)); | ||
1719 | if (ret) { | 1712 | if (ret) { |
1720 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); | 1713 | DEBUG(MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); |
1721 | goto out; | 1714 | goto out; |
1722 | } | 1715 | } |
1723 | *retlen = written; | 1716 | *retlen = written; |
@@ -1726,11 +1719,10 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1726 | if (eccbuf) | 1719 | if (eccbuf) |
1727 | eccbuf += (page - startpage) * ofs; | 1720 | eccbuf += (page - startpage) * ofs; |
1728 | totalpages -= page - startpage; | 1721 | totalpages -= page - startpage; |
1729 | numpages = min (totalpages, ppblock); | 1722 | numpages = min(totalpages, ppblock); |
1730 | page &= this->pagemask; | 1723 | page &= this->pagemask; |
1731 | startpage = page; | 1724 | startpage = page; |
1732 | oobbuf = nand_prepare_oobbuf (mtd, eccbuf, oobsel, | 1725 | oobbuf = nand_prepare_oobbuf(mtd, eccbuf, oobsel, autoplace, numpages); |
1733 | autoplace, numpages); | ||
1734 | oob = 0; | 1726 | oob = 0; |
1735 | /* Check, if we cross a chip boundary */ | 1727 | /* Check, if we cross a chip boundary */ |
1736 | if (!page) { | 1728 | if (!page) { |
@@ -1741,23 +1733,21 @@ static int nand_write_ecc (struct mtd_info *mtd, loff_t to, size_t len, | |||
1741 | } | 1733 | } |
1742 | } | 1734 | } |
1743 | /* Verify the remaining pages */ | 1735 | /* Verify the remaining pages */ |
1744 | cmp: | 1736 | cmp: |
1745 | this->data_poi = bufstart; | 1737 | this->data_poi = bufstart; |
1746 | ret = nand_verify_pages (mtd, this, startpage, totalpages, | 1738 | ret = nand_verify_pages(mtd, this, startpage, totalpages, oobbuf, oobsel, chipnr, (eccbuf != NULL)); |
1747 | oobbuf, oobsel, chipnr, (eccbuf != NULL)); | ||
1748 | if (!ret) | 1739 | if (!ret) |
1749 | *retlen = written; | 1740 | *retlen = written; |
1750 | else | 1741 | else |
1751 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); | 1742 | DEBUG(MTD_DEBUG_LEVEL0, "nand_write_ecc: verify_pages failed %d\n", ret); |
1752 | 1743 | ||
1753 | out: | 1744 | out: |
1754 | /* Deselect and wake up anyone waiting on the device */ | 1745 | /* Deselect and wake up anyone waiting on the device */ |
1755 | nand_release_device(mtd); | 1746 | nand_release_device(mtd); |
1756 | 1747 | ||
1757 | return ret; | 1748 | return ret; |
1758 | } | 1749 | } |
1759 | 1750 | ||
1760 | |||
1761 | /** | 1751 | /** |
1762 | * nand_write_oob - [MTD Interface] NAND write out-of-band | 1752 | * nand_write_oob - [MTD Interface] NAND write out-of-band |
1763 | * @mtd: MTD device structure | 1753 | * @mtd: MTD device structure |
@@ -1768,16 +1758,16 @@ out: | |||
1768 | * | 1758 | * |
1769 | * NAND write out-of-band | 1759 | * NAND write out-of-band |
1770 | */ | 1760 | */ |
1771 | static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf) | 1761 | static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) |
1772 | { | 1762 | { |
1773 | int column, page, status, ret = -EIO, chipnr; | 1763 | int column, page, status, ret = -EIO, chipnr; |
1774 | struct nand_chip *this = mtd->priv; | 1764 | struct nand_chip *this = mtd->priv; |
1775 | 1765 | ||
1776 | DEBUG (MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); | 1766 | DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", (unsigned int)to, (int)len); |
1777 | 1767 | ||
1778 | /* Shift to get page */ | 1768 | /* Shift to get page */ |
1779 | page = (int) (to >> this->page_shift); | 1769 | page = (int)(to >> this->page_shift); |
1780 | chipnr = (int) (to >> this->chip_shift); | 1770 | chipnr = (int)(to >> this->chip_shift); |
1781 | 1771 | ||
1782 | /* Mask to get column */ | 1772 | /* Mask to get column */ |
1783 | column = to & (mtd->oobsize - 1); | 1773 | column = to & (mtd->oobsize - 1); |
@@ -1787,12 +1777,12 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * | |||
1787 | 1777 | ||
1788 | /* Do not allow write past end of page */ | 1778 | /* Do not allow write past end of page */ |
1789 | if ((column + len) > mtd->oobsize) { | 1779 | if ((column + len) > mtd->oobsize) { |
1790 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: Attempt to write past end of page\n"); | 1780 | DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: Attempt to write past end of page\n"); |
1791 | return -EINVAL; | 1781 | return -EINVAL; |
1792 | } | 1782 | } |
1793 | 1783 | ||
1794 | /* Grab the lock and see if the device is available */ | 1784 | /* Grab the lock and see if the device is available */ |
1795 | nand_get_device (this, mtd, FL_WRITING); | 1785 | nand_get_device(this, mtd, FL_WRITING); |
1796 | 1786 | ||
1797 | /* Select the NAND device */ | 1787 | /* Select the NAND device */ |
1798 | this->select_chip(mtd, chipnr); | 1788 | this->select_chip(mtd, chipnr); |
@@ -1814,27 +1804,27 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * | |||
1814 | 1804 | ||
1815 | if (NAND_MUST_PAD(this)) { | 1805 | if (NAND_MUST_PAD(this)) { |
1816 | /* Write out desired data */ | 1806 | /* Write out desired data */ |
1817 | this->cmdfunc (mtd, NAND_CMD_SEQIN, mtd->oobblock, page & this->pagemask); | 1807 | this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->oobblock, page & this->pagemask); |
1818 | /* prepad 0xff for partial programming */ | 1808 | /* prepad 0xff for partial programming */ |
1819 | this->write_buf(mtd, ffchars, column); | 1809 | this->write_buf(mtd, ffchars, column); |
1820 | /* write data */ | 1810 | /* write data */ |
1821 | this->write_buf(mtd, buf, len); | 1811 | this->write_buf(mtd, buf, len); |
1822 | /* postpad 0xff for partial programming */ | 1812 | /* postpad 0xff for partial programming */ |
1823 | this->write_buf(mtd, ffchars, mtd->oobsize - (len+column)); | 1813 | this->write_buf(mtd, ffchars, mtd->oobsize - (len + column)); |
1824 | } else { | 1814 | } else { |
1825 | /* Write out desired data */ | 1815 | /* Write out desired data */ |
1826 | this->cmdfunc (mtd, NAND_CMD_SEQIN, mtd->oobblock + column, page & this->pagemask); | 1816 | this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->oobblock + column, page & this->pagemask); |
1827 | /* write data */ | 1817 | /* write data */ |
1828 | this->write_buf(mtd, buf, len); | 1818 | this->write_buf(mtd, buf, len); |
1829 | } | 1819 | } |
1830 | /* Send command to program the OOB data */ | 1820 | /* Send command to program the OOB data */ |
1831 | this->cmdfunc (mtd, NAND_CMD_PAGEPROG, -1, -1); | 1821 | this->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); |
1832 | 1822 | ||
1833 | status = this->waitfunc (mtd, this, FL_WRITING); | 1823 | status = this->waitfunc(mtd, this, FL_WRITING); |
1834 | 1824 | ||
1835 | /* See if device thinks it succeeded */ | 1825 | /* See if device thinks it succeeded */ |
1836 | if (status & NAND_STATUS_FAIL) { | 1826 | if (status & NAND_STATUS_FAIL) { |
1837 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write, page 0x%08x\n", page); | 1827 | DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write, page 0x%08x\n", page); |
1838 | ret = -EIO; | 1828 | ret = -EIO; |
1839 | goto out; | 1829 | goto out; |
1840 | } | 1830 | } |
@@ -1843,23 +1833,22 @@ static int nand_write_oob (struct mtd_info *mtd, loff_t to, size_t len, size_t * | |||
1843 | 1833 | ||
1844 | #ifdef CONFIG_MTD_NAND_VERIFY_WRITE | 1834 | #ifdef CONFIG_MTD_NAND_VERIFY_WRITE |
1845 | /* Send command to read back the data */ | 1835 | /* Send command to read back the data */ |
1846 | this->cmdfunc (mtd, NAND_CMD_READOOB, column, page & this->pagemask); | 1836 | this->cmdfunc(mtd, NAND_CMD_READOOB, column, page & this->pagemask); |
1847 | 1837 | ||
1848 | if (this->verify_buf(mtd, buf, len)) { | 1838 | if (this->verify_buf(mtd, buf, len)) { |
1849 | DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write verify, page 0x%08x\n", page); | 1839 | DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write verify, page 0x%08x\n", page); |
1850 | ret = -EIO; | 1840 | ret = -EIO; |
1851 | goto out; | 1841 | goto out; |
1852 | } | 1842 | } |
1853 | #endif | 1843 | #endif |
1854 | ret = 0; | 1844 | ret = 0; |
1855 | out: | 1845 | out: |
1856 | /* Deselect and wake up anyone waiting on the device */ | 1846 | /* Deselect and wake up anyone waiting on the device */ |
1857 | nand_release_device(mtd); | 1847 | nand_release_device(mtd); |
1858 | 1848 | ||
1859 | return ret; | 1849 | return ret; |
1860 | } | 1850 | } |
1861 | 1851 | ||
1862 | |||
1863 | /** | 1852 | /** |
1864 | * nand_writev - [MTD Interface] compabilty function for nand_writev_ecc | 1853 | * nand_writev - [MTD Interface] compabilty function for nand_writev_ecc |
1865 | * @mtd: MTD device structure | 1854 | * @mtd: MTD device structure |
@@ -1870,10 +1859,10 @@ out: | |||
1870 | * | 1859 | * |
1871 | * NAND write with kvec. This just calls the ecc function | 1860 | * NAND write with kvec. This just calls the ecc function |
1872 | */ | 1861 | */ |
1873 | static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, | 1862 | static int nand_writev(struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, |
1874 | loff_t to, size_t * retlen) | 1863 | loff_t to, size_t *retlen) |
1875 | { | 1864 | { |
1876 | return (nand_writev_ecc (mtd, vecs, count, to, retlen, NULL, NULL)); | 1865 | return (nand_writev_ecc(mtd, vecs, count, to, retlen, NULL, NULL)); |
1877 | } | 1866 | } |
1878 | 1867 | ||
1879 | /** | 1868 | /** |
@@ -1888,13 +1877,13 @@ static int nand_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned | |||
1888 | * | 1877 | * |
1889 | * NAND write with iovec with ecc | 1878 | * NAND write with iovec with ecc |
1890 | */ | 1879 | */ |
1891 | static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, | 1880 | static int nand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, |
1892 | loff_t to, size_t * retlen, u_char *eccbuf, struct nand_oobinfo *oobsel) | 1881 | loff_t to, size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel) |
1893 | { | 1882 | { |
1894 | int i, page, len, total_len, ret = -EIO, written = 0, chipnr; | 1883 | int i, page, len, total_len, ret = -EIO, written = 0, chipnr; |
1895 | int oob, numpages, autoplace = 0, startpage; | 1884 | int oob, numpages, autoplace = 0, startpage; |
1896 | struct nand_chip *this = mtd->priv; | 1885 | struct nand_chip *this = mtd->priv; |
1897 | int ppblock = (1 << (this->phys_erase_shift - this->page_shift)); | 1886 | int ppblock = (1 << (this->phys_erase_shift - this->page_shift)); |
1898 | u_char *oobbuf, *bufstart; | 1887 | u_char *oobbuf, *bufstart; |
1899 | 1888 | ||
1900 | /* Preset written len for early exit */ | 1889 | /* Preset written len for early exit */ |
@@ -1903,28 +1892,27 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1903 | /* Calculate total length of data */ | 1892 | /* Calculate total length of data */ |
1904 | total_len = 0; | 1893 | total_len = 0; |
1905 | for (i = 0; i < count; i++) | 1894 | for (i = 0; i < count; i++) |
1906 | total_len += (int) vecs[i].iov_len; | 1895 | total_len += (int)vecs[i].iov_len; |
1907 | 1896 | ||
1908 | DEBUG (MTD_DEBUG_LEVEL3, | 1897 | DEBUG(MTD_DEBUG_LEVEL3, "nand_writev: to = 0x%08x, len = %i, count = %ld\n", (unsigned int)to, (unsigned int)total_len, count); |
1909 | "nand_writev: to = 0x%08x, len = %i, count = %ld\n", (unsigned int) to, (unsigned int) total_len, count); | ||
1910 | 1898 | ||
1911 | /* Do not allow write past end of page */ | 1899 | /* Do not allow write past end of page */ |
1912 | if ((to + total_len) > mtd->size) { | 1900 | if ((to + total_len) > mtd->size) { |
1913 | DEBUG (MTD_DEBUG_LEVEL0, "nand_writev: Attempted write past end of device\n"); | 1901 | DEBUG(MTD_DEBUG_LEVEL0, "nand_writev: Attempted write past end of device\n"); |
1914 | return -EINVAL; | 1902 | return -EINVAL; |
1915 | } | 1903 | } |
1916 | 1904 | ||
1917 | /* reject writes, which are not page aligned */ | 1905 | /* reject writes, which are not page aligned */ |
1918 | if (NOTALIGNED (to) || NOTALIGNED(total_len)) { | 1906 | if (NOTALIGNED(to) || NOTALIGNED(total_len)) { |
1919 | printk (KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); | 1907 | printk(KERN_NOTICE "nand_write_ecc: Attempt to write not page aligned data\n"); |
1920 | return -EINVAL; | 1908 | return -EINVAL; |
1921 | } | 1909 | } |
1922 | 1910 | ||
1923 | /* Grab the lock and see if the device is available */ | 1911 | /* Grab the lock and see if the device is available */ |
1924 | nand_get_device (this, mtd, FL_WRITING); | 1912 | nand_get_device(this, mtd, FL_WRITING); |
1925 | 1913 | ||
1926 | /* Get the current chip-nr */ | 1914 | /* Get the current chip-nr */ |
1927 | chipnr = (int) (to >> this->chip_shift); | 1915 | chipnr = (int)(to >> this->chip_shift); |
1928 | /* Select the NAND device */ | 1916 | /* Select the NAND device */ |
1929 | this->select_chip(mtd, chipnr); | 1917 | this->select_chip(mtd, chipnr); |
1930 | 1918 | ||
@@ -1945,7 +1933,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1945 | autoplace = 1; | 1933 | autoplace = 1; |
1946 | 1934 | ||
1947 | /* Setup start page */ | 1935 | /* Setup start page */ |
1948 | page = (int) (to >> this->page_shift); | 1936 | page = (int)(to >> this->page_shift); |
1949 | /* Invalidate the page cache, if we write to the cached page */ | 1937 | /* Invalidate the page cache, if we write to the cached page */ |
1950 | if (page <= this->pagebuf && this->pagebuf < ((to + total_len) >> this->page_shift)) | 1938 | if (page <= this->pagebuf && this->pagebuf < ((to + total_len) >> this->page_shift)) |
1951 | this->pagebuf = -1; | 1939 | this->pagebuf = -1; |
@@ -1963,9 +1951,9 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1963 | * out of this iov in one go */ | 1951 | * out of this iov in one go */ |
1964 | numpages = (vecs->iov_len - len) >> this->page_shift; | 1952 | numpages = (vecs->iov_len - len) >> this->page_shift; |
1965 | /* Do not cross block boundaries */ | 1953 | /* Do not cross block boundaries */ |
1966 | numpages = min (ppblock - (startpage & (ppblock - 1)), numpages); | 1954 | numpages = min(ppblock - (startpage & (ppblock - 1)), numpages); |
1967 | oobbuf = nand_prepare_oobbuf (mtd, NULL, oobsel, autoplace, numpages); | 1955 | oobbuf = nand_prepare_oobbuf(mtd, NULL, oobsel, autoplace, numpages); |
1968 | bufstart = (u_char *)vecs->iov_base; | 1956 | bufstart = (u_char *) vecs->iov_base; |
1969 | bufstart += len; | 1957 | bufstart += len; |
1970 | this->data_poi = bufstart; | 1958 | this->data_poi = bufstart; |
1971 | oob = 0; | 1959 | oob = 0; |
@@ -1974,8 +1962,8 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1974 | * then use the real pageprogram command, else select | 1962 | * then use the real pageprogram command, else select |
1975 | * cached programming if supported by the chip. | 1963 | * cached programming if supported by the chip. |
1976 | */ | 1964 | */ |
1977 | ret = nand_write_page (mtd, this, page & this->pagemask, | 1965 | ret = nand_write_page(mtd, this, page & this->pagemask, |
1978 | &oobbuf[oob], oobsel, i != numpages); | 1966 | &oobbuf[oob], oobsel, i != numpages); |
1979 | if (ret) | 1967 | if (ret) |
1980 | goto out; | 1968 | goto out; |
1981 | this->data_poi += mtd->oobblock; | 1969 | this->data_poi += mtd->oobblock; |
@@ -1984,7 +1972,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1984 | page++; | 1972 | page++; |
1985 | } | 1973 | } |
1986 | /* Check, if we have to switch to the next tuple */ | 1974 | /* Check, if we have to switch to the next tuple */ |
1987 | if (len >= (int) vecs->iov_len) { | 1975 | if (len >= (int)vecs->iov_len) { |
1988 | vecs++; | 1976 | vecs++; |
1989 | len = 0; | 1977 | len = 0; |
1990 | count--; | 1978 | count--; |
@@ -1998,7 +1986,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
1998 | if (vecs->iov_base != NULL && vecs->iov_len) | 1986 | if (vecs->iov_base != NULL && vecs->iov_len) |
1999 | this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++]; | 1987 | this->data_buf[cnt++] = ((u_char *) vecs->iov_base)[len++]; |
2000 | /* Check, if we have to switch to the next tuple */ | 1988 | /* Check, if we have to switch to the next tuple */ |
2001 | if (len >= (int) vecs->iov_len) { | 1989 | if (len >= (int)vecs->iov_len) { |
2002 | vecs++; | 1990 | vecs++; |
2003 | len = 0; | 1991 | len = 0; |
2004 | count--; | 1992 | count--; |
@@ -2008,16 +1996,15 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
2008 | this->data_poi = this->data_buf; | 1996 | this->data_poi = this->data_buf; |
2009 | bufstart = this->data_poi; | 1997 | bufstart = this->data_poi; |
2010 | numpages = 1; | 1998 | numpages = 1; |
2011 | oobbuf = nand_prepare_oobbuf (mtd, NULL, oobsel, autoplace, numpages); | 1999 | oobbuf = nand_prepare_oobbuf(mtd, NULL, oobsel, autoplace, numpages); |
2012 | ret = nand_write_page (mtd, this, page & this->pagemask, | 2000 | ret = nand_write_page(mtd, this, page & this->pagemask, oobbuf, oobsel, 0); |
2013 | oobbuf, oobsel, 0); | ||
2014 | if (ret) | 2001 | if (ret) |
2015 | goto out; | 2002 | goto out; |
2016 | page++; | 2003 | page++; |
2017 | } | 2004 | } |
2018 | 2005 | ||
2019 | this->data_poi = bufstart; | 2006 | this->data_poi = bufstart; |
2020 | ret = nand_verify_pages (mtd, this, startpage, numpages, oobbuf, oobsel, chipnr, 0); | 2007 | ret = nand_verify_pages(mtd, this, startpage, numpages, oobbuf, oobsel, chipnr, 0); |
2021 | if (ret) | 2008 | if (ret) |
2022 | goto out; | 2009 | goto out; |
2023 | 2010 | ||
@@ -2035,7 +2022,7 @@ static int nand_writev_ecc (struct mtd_info *mtd, const struct kvec *vecs, unsig | |||
2035 | } | 2022 | } |
2036 | } | 2023 | } |
2037 | ret = 0; | 2024 | ret = 0; |
2038 | out: | 2025 | out: |
2039 | /* Deselect and wake up anyone waiting on the device */ | 2026 | /* Deselect and wake up anyone waiting on the device */ |
2040 | nand_release_device(mtd); | 2027 | nand_release_device(mtd); |
2041 | 2028 | ||
@@ -2050,12 +2037,12 @@ out: | |||
2050 | * | 2037 | * |
2051 | * Standard erase command for NAND chips | 2038 | * Standard erase command for NAND chips |
2052 | */ | 2039 | */ |
2053 | static void single_erase_cmd (struct mtd_info *mtd, int page) | 2040 | static void single_erase_cmd(struct mtd_info *mtd, int page) |
2054 | { | 2041 | { |
2055 | struct nand_chip *this = mtd->priv; | 2042 | struct nand_chip *this = mtd->priv; |
2056 | /* Send commands to erase a block */ | 2043 | /* Send commands to erase a block */ |
2057 | this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page); | 2044 | this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page); |
2058 | this->cmdfunc (mtd, NAND_CMD_ERASE2, -1, -1); | 2045 | this->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1); |
2059 | } | 2046 | } |
2060 | 2047 | ||
2061 | /** | 2048 | /** |
@@ -2066,15 +2053,15 @@ static void single_erase_cmd (struct mtd_info *mtd, int page) | |||
2066 | * AND multi block erase command function | 2053 | * AND multi block erase command function |
2067 | * Erase 4 consecutive blocks | 2054 | * Erase 4 consecutive blocks |
2068 | */ | 2055 | */ |
2069 | static void multi_erase_cmd (struct mtd_info *mtd, int page) | 2056 | static void multi_erase_cmd(struct mtd_info *mtd, int page) |
2070 | { | 2057 | { |
2071 | struct nand_chip *this = mtd->priv; | 2058 | struct nand_chip *this = mtd->priv; |
2072 | /* Send commands to erase a block */ | 2059 | /* Send commands to erase a block */ |
2073 | this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page++); | 2060 | this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++); |
2074 | this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page++); | 2061 | this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++); |
2075 | this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page++); | 2062 | this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++); |
2076 | this->cmdfunc (mtd, NAND_CMD_ERASE1, -1, page); | 2063 | this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page); |
2077 | this->cmdfunc (mtd, NAND_CMD_ERASE2, -1, -1); | 2064 | this->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1); |
2078 | } | 2065 | } |
2079 | 2066 | ||
2080 | /** | 2067 | /** |
@@ -2084,9 +2071,9 @@ static void multi_erase_cmd (struct mtd_info *mtd, int page) | |||
2084 | * | 2071 | * |
2085 | * Erase one ore more blocks | 2072 | * Erase one ore more blocks |
2086 | */ | 2073 | */ |
2087 | static int nand_erase (struct mtd_info *mtd, struct erase_info *instr) | 2074 | static int nand_erase(struct mtd_info *mtd, struct erase_info *instr) |
2088 | { | 2075 | { |
2089 | return nand_erase_nand (mtd, instr, 0); | 2076 | return nand_erase_nand(mtd, instr, 0); |
2090 | } | 2077 | } |
2091 | 2078 | ||
2092 | #define BBT_PAGE_MASK 0xffffff3f | 2079 | #define BBT_PAGE_MASK 0xffffff3f |
@@ -2098,7 +2085,7 @@ static int nand_erase (struct mtd_info *mtd, struct erase_info *instr) | |||
2098 | * | 2085 | * |
2099 | * Erase one ore more blocks | 2086 | * Erase one ore more blocks |
2100 | */ | 2087 | */ |
2101 | int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbbt) | 2088 | int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, int allowbbt) |
2102 | { | 2089 | { |
2103 | int page, len, status, pages_per_block, ret, chipnr; | 2090 | int page, len, status, pages_per_block, ret, chipnr; |
2104 | struct nand_chip *this = mtd->priv; | 2091 | struct nand_chip *this = mtd->priv; |
@@ -2107,35 +2094,34 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb | |||
2107 | /* It is used to see if the current page is in the same */ | 2094 | /* It is used to see if the current page is in the same */ |
2108 | /* 256 block group and the same bank as the bbt. */ | 2095 | /* 256 block group and the same bank as the bbt. */ |
2109 | 2096 | ||
2110 | DEBUG (MTD_DEBUG_LEVEL3, | 2097 | DEBUG(MTD_DEBUG_LEVEL3, "nand_erase: start = 0x%08x, len = %i\n", (unsigned int)instr->addr, (unsigned int)instr->len); |
2111 | "nand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len); | ||
2112 | 2098 | ||
2113 | /* Start address must align on block boundary */ | 2099 | /* Start address must align on block boundary */ |
2114 | if (instr->addr & ((1 << this->phys_erase_shift) - 1)) { | 2100 | if (instr->addr & ((1 << this->phys_erase_shift) - 1)) { |
2115 | DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Unaligned address\n"); | 2101 | DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Unaligned address\n"); |
2116 | return -EINVAL; | 2102 | return -EINVAL; |
2117 | } | 2103 | } |
2118 | 2104 | ||
2119 | /* Length must align on block boundary */ | 2105 | /* Length must align on block boundary */ |
2120 | if (instr->len & ((1 << this->phys_erase_shift) - 1)) { | 2106 | if (instr->len & ((1 << this->phys_erase_shift) - 1)) { |
2121 | DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Length not block aligned\n"); | 2107 | DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Length not block aligned\n"); |
2122 | return -EINVAL; | 2108 | return -EINVAL; |
2123 | } | 2109 | } |
2124 | 2110 | ||
2125 | /* Do not allow erase past end of device */ | 2111 | /* Do not allow erase past end of device */ |
2126 | if ((instr->len + instr->addr) > mtd->size) { | 2112 | if ((instr->len + instr->addr) > mtd->size) { |
2127 | DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Erase past end of device\n"); | 2113 | DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Erase past end of device\n"); |
2128 | return -EINVAL; | 2114 | return -EINVAL; |
2129 | } | 2115 | } |
2130 | 2116 | ||
2131 | instr->fail_addr = 0xffffffff; | 2117 | instr->fail_addr = 0xffffffff; |
2132 | 2118 | ||
2133 | /* Grab the lock and see if the device is available */ | 2119 | /* Grab the lock and see if the device is available */ |
2134 | nand_get_device (this, mtd, FL_ERASING); | 2120 | nand_get_device(this, mtd, FL_ERASING); |
2135 | 2121 | ||
2136 | /* Shift to get first page */ | 2122 | /* Shift to get first page */ |
2137 | page = (int) (instr->addr >> this->page_shift); | 2123 | page = (int)(instr->addr >> this->page_shift); |
2138 | chipnr = (int) (instr->addr >> this->chip_shift); | 2124 | chipnr = (int)(instr->addr >> this->chip_shift); |
2139 | 2125 | ||
2140 | /* Calculate pages in each block */ | 2126 | /* Calculate pages in each block */ |
2141 | pages_per_block = 1 << (this->phys_erase_shift - this->page_shift); | 2127 | pages_per_block = 1 << (this->phys_erase_shift - this->page_shift); |
@@ -2146,7 +2132,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb | |||
2146 | /* Check the WP bit */ | 2132 | /* Check the WP bit */ |
2147 | /* Check, if it is write protected */ | 2133 | /* Check, if it is write protected */ |
2148 | if (nand_check_wp(mtd)) { | 2134 | if (nand_check_wp(mtd)) { |
2149 | DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Device is write protected!!!\n"); | 2135 | DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Device is write protected!!!\n"); |
2150 | instr->state = MTD_ERASE_FAILED; | 2136 | instr->state = MTD_ERASE_FAILED; |
2151 | goto erase_exit; | 2137 | goto erase_exit; |
2152 | } | 2138 | } |
@@ -2166,7 +2152,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb | |||
2166 | while (len) { | 2152 | while (len) { |
2167 | /* Check if we have a bad block, we do not erase bad blocks ! */ | 2153 | /* Check if we have a bad block, we do not erase bad blocks ! */ |
2168 | if (nand_block_checkbad(mtd, ((loff_t) page) << this->page_shift, 0, allowbbt)) { | 2154 | if (nand_block_checkbad(mtd, ((loff_t) page) << this->page_shift, 0, allowbbt)) { |
2169 | printk (KERN_WARNING "nand_erase: attempt to erase a bad block at page 0x%08x\n", page); | 2155 | printk(KERN_WARNING "nand_erase: attempt to erase a bad block at page 0x%08x\n", page); |
2170 | instr->state = MTD_ERASE_FAILED; | 2156 | instr->state = MTD_ERASE_FAILED; |
2171 | goto erase_exit; | 2157 | goto erase_exit; |
2172 | } | 2158 | } |
@@ -2176,9 +2162,9 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb | |||
2176 | if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block)) | 2162 | if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block)) |
2177 | this->pagebuf = -1; | 2163 | this->pagebuf = -1; |
2178 | 2164 | ||
2179 | this->erase_cmd (mtd, page & this->pagemask); | 2165 | this->erase_cmd(mtd, page & this->pagemask); |
2180 | 2166 | ||
2181 | status = this->waitfunc (mtd, this, FL_ERASING); | 2167 | status = this->waitfunc(mtd, this, FL_ERASING); |
2182 | 2168 | ||
2183 | /* See if operation failed and additional status checks are available */ | 2169 | /* See if operation failed and additional status checks are available */ |
2184 | if ((status & NAND_STATUS_FAIL) && (this->errstat)) { | 2170 | if ((status & NAND_STATUS_FAIL) && (this->errstat)) { |
@@ -2187,7 +2173,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb | |||
2187 | 2173 | ||
2188 | /* See if block erase succeeded */ | 2174 | /* See if block erase succeeded */ |
2189 | if (status & NAND_STATUS_FAIL) { | 2175 | if (status & NAND_STATUS_FAIL) { |
2190 | DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: " "Failed erase, page 0x%08x\n", page); | 2176 | DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: " "Failed erase, page 0x%08x\n", page); |
2191 | instr->state = MTD_ERASE_FAILED; | 2177 | instr->state = MTD_ERASE_FAILED; |
2192 | instr->fail_addr = (page << this->page_shift); | 2178 | instr->fail_addr = (page << this->page_shift); |
2193 | goto erase_exit; | 2179 | goto erase_exit; |
@@ -2221,7 +2207,7 @@ int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbb | |||
2221 | } | 2207 | } |
2222 | instr->state = MTD_ERASE_DONE; | 2208 | instr->state = MTD_ERASE_DONE; |
2223 | 2209 | ||
2224 | erase_exit: | 2210 | erase_exit: |
2225 | 2211 | ||
2226 | ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO; | 2212 | ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO; |
2227 | /* Do call back function */ | 2213 | /* Do call back function */ |
@@ -2236,9 +2222,9 @@ erase_exit: | |||
2236 | for (chipnr = 0; chipnr < this->numchips; chipnr++) { | 2222 | for (chipnr = 0; chipnr < this->numchips; chipnr++) { |
2237 | if (rewrite_bbt[chipnr]) { | 2223 | if (rewrite_bbt[chipnr]) { |
2238 | /* update the BBT for chip */ | 2224 | /* update the BBT for chip */ |
2239 | DEBUG (MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n", | 2225 | DEBUG(MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n", |
2240 | chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]); | 2226 | chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]); |
2241 | nand_update_bbt (mtd, rewrite_bbt[chipnr]); | 2227 | nand_update_bbt(mtd, rewrite_bbt[chipnr]); |
2242 | } | 2228 | } |
2243 | } | 2229 | } |
2244 | } | 2230 | } |
@@ -2253,31 +2239,30 @@ erase_exit: | |||
2253 | * | 2239 | * |
2254 | * Sync is actually a wait for chip ready function | 2240 | * Sync is actually a wait for chip ready function |
2255 | */ | 2241 | */ |
2256 | static void nand_sync (struct mtd_info *mtd) | 2242 | static void nand_sync(struct mtd_info *mtd) |
2257 | { | 2243 | { |
2258 | struct nand_chip *this = mtd->priv; | 2244 | struct nand_chip *this = mtd->priv; |
2259 | 2245 | ||
2260 | DEBUG (MTD_DEBUG_LEVEL3, "nand_sync: called\n"); | 2246 | DEBUG(MTD_DEBUG_LEVEL3, "nand_sync: called\n"); |
2261 | 2247 | ||
2262 | /* Grab the lock and see if the device is available */ | 2248 | /* Grab the lock and see if the device is available */ |
2263 | nand_get_device (this, mtd, FL_SYNCING); | 2249 | nand_get_device(this, mtd, FL_SYNCING); |
2264 | /* Release it and go back */ | 2250 | /* Release it and go back */ |
2265 | nand_release_device (mtd); | 2251 | nand_release_device(mtd); |
2266 | } | 2252 | } |
2267 | 2253 | ||
2268 | |||
2269 | /** | 2254 | /** |
2270 | * nand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad | 2255 | * nand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad |
2271 | * @mtd: MTD device structure | 2256 | * @mtd: MTD device structure |
2272 | * @ofs: offset relative to mtd start | 2257 | * @ofs: offset relative to mtd start |
2273 | */ | 2258 | */ |
2274 | static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs) | 2259 | static int nand_block_isbad(struct mtd_info *mtd, loff_t ofs) |
2275 | { | 2260 | { |
2276 | /* Check for invalid offset */ | 2261 | /* Check for invalid offset */ |
2277 | if (ofs > mtd->size) | 2262 | if (ofs > mtd->size) |
2278 | return -EINVAL; | 2263 | return -EINVAL; |
2279 | 2264 | ||
2280 | return nand_block_checkbad (mtd, ofs, 1, 0); | 2265 | return nand_block_checkbad(mtd, ofs, 1, 0); |
2281 | } | 2266 | } |
2282 | 2267 | ||
2283 | /** | 2268 | /** |
@@ -2285,17 +2270,17 @@ static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs) | |||
2285 | * @mtd: MTD device structure | 2270 | * @mtd: MTD device structure |
2286 | * @ofs: offset relative to mtd start | 2271 | * @ofs: offset relative to mtd start |
2287 | */ | 2272 | */ |
2288 | static int nand_block_markbad (struct mtd_info *mtd, loff_t ofs) | 2273 | static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) |
2289 | { | 2274 | { |
2290 | struct nand_chip *this = mtd->priv; | 2275 | struct nand_chip *this = mtd->priv; |
2291 | int ret; | 2276 | int ret; |
2292 | 2277 | ||
2293 | if ((ret = nand_block_isbad(mtd, ofs))) { | 2278 | if ((ret = nand_block_isbad(mtd, ofs))) { |
2294 | /* If it was bad already, return success and do nothing. */ | 2279 | /* If it was bad already, return success and do nothing. */ |
2295 | if (ret > 0) | 2280 | if (ret > 0) |
2296 | return 0; | 2281 | return 0; |
2297 | return ret; | 2282 | return ret; |
2298 | } | 2283 | } |
2299 | 2284 | ||
2300 | return this->block_markbad(mtd, ofs); | 2285 | return this->block_markbad(mtd, ofs); |
2301 | } | 2286 | } |
@@ -2308,7 +2293,7 @@ static int nand_suspend(struct mtd_info *mtd) | |||
2308 | { | 2293 | { |
2309 | struct nand_chip *this = mtd->priv; | 2294 | struct nand_chip *this = mtd->priv; |
2310 | 2295 | ||
2311 | return nand_get_device (this, mtd, FL_PM_SUSPENDED); | 2296 | return nand_get_device(this, mtd, FL_PM_SUSPENDED); |
2312 | } | 2297 | } |
2313 | 2298 | ||
2314 | /** | 2299 | /** |
@@ -2322,12 +2307,10 @@ static void nand_resume(struct mtd_info *mtd) | |||
2322 | if (this->state == FL_PM_SUSPENDED) | 2307 | if (this->state == FL_PM_SUSPENDED) |
2323 | nand_release_device(mtd); | 2308 | nand_release_device(mtd); |
2324 | else | 2309 | else |
2325 | printk(KERN_ERR "resume() called for the chip which is not " | 2310 | printk(KERN_ERR "resume() called for the chip which is not in suspended state\n"); |
2326 | "in suspended state\n"); | ||
2327 | 2311 | ||
2328 | } | 2312 | } |
2329 | 2313 | ||
2330 | |||
2331 | /** | 2314 | /** |
2332 | * nand_scan - [NAND Interface] Scan for the NAND device | 2315 | * nand_scan - [NAND Interface] Scan for the NAND device |
2333 | * @mtd: MTD device structure | 2316 | * @mtd: MTD device structure |
@@ -2340,12 +2323,12 @@ static void nand_resume(struct mtd_info *mtd) | |||
2340 | * they are not provided by the board driver | 2323 | * they are not provided by the board driver |
2341 | * | 2324 | * |
2342 | */ | 2325 | */ |
2343 | int nand_scan (struct mtd_info *mtd, int maxchips) | 2326 | int nand_scan(struct mtd_info *mtd, int maxchips) |
2344 | { | 2327 | { |
2345 | int i, nand_maf_id, nand_dev_id, busw, maf_id; | 2328 | int i, nand_maf_id, nand_dev_id, busw, maf_id; |
2346 | struct nand_chip *this = mtd->priv; | 2329 | struct nand_chip *this = mtd->priv; |
2347 | 2330 | ||
2348 | /* Get buswidth to select the correct functions*/ | 2331 | /* Get buswidth to select the correct functions */ |
2349 | busw = this->options & NAND_BUSWIDTH_16; | 2332 | busw = this->options & NAND_BUSWIDTH_16; |
2350 | 2333 | ||
2351 | /* check for proper chip_delay setup, set 20us if not */ | 2334 | /* check for proper chip_delay setup, set 20us if not */ |
@@ -2387,7 +2370,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2387 | this->select_chip(mtd, 0); | 2370 | this->select_chip(mtd, 0); |
2388 | 2371 | ||
2389 | /* Send the command for reading device ID */ | 2372 | /* Send the command for reading device ID */ |
2390 | this->cmdfunc (mtd, NAND_CMD_READID, 0x00, -1); | 2373 | this->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); |
2391 | 2374 | ||
2392 | /* Read manufacturer and device IDs */ | 2375 | /* Read manufacturer and device IDs */ |
2393 | nand_maf_id = this->read_byte(mtd); | 2376 | nand_maf_id = this->read_byte(mtd); |
@@ -2399,7 +2382,8 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2399 | if (nand_dev_id != nand_flash_ids[i].id) | 2382 | if (nand_dev_id != nand_flash_ids[i].id) |
2400 | continue; | 2383 | continue; |
2401 | 2384 | ||
2402 | if (!mtd->name) mtd->name = nand_flash_ids[i].name; | 2385 | if (!mtd->name) |
2386 | mtd->name = nand_flash_ids[i].name; | ||
2403 | this->chipsize = nand_flash_ids[i].chipsize << 20; | 2387 | this->chipsize = nand_flash_ids[i].chipsize << 20; |
2404 | 2388 | ||
2405 | /* New devices have all the information in additional id bytes */ | 2389 | /* New devices have all the information in additional id bytes */ |
@@ -2416,7 +2400,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2416 | mtd->oobsize = (8 << (extid & 0x01)) * (mtd->oobblock >> 9); | 2400 | mtd->oobsize = (8 << (extid & 0x01)) * (mtd->oobblock >> 9); |
2417 | extid >>= 2; | 2401 | extid >>= 2; |
2418 | /* Calc blocksize. Blocksize is multiples of 64KiB */ | 2402 | /* Calc blocksize. Blocksize is multiples of 64KiB */ |
2419 | mtd->erasesize = (64 * 1024) << (extid & 0x03); | 2403 | mtd->erasesize = (64 * 1024) << (extid & 0x03); |
2420 | extid >>= 2; | 2404 | extid >>= 2; |
2421 | /* Get buswidth information */ | 2405 | /* Get buswidth information */ |
2422 | busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; | 2406 | busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; |
@@ -2439,13 +2423,12 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2439 | /* Check, if buswidth is correct. Hardware drivers should set | 2423 | /* Check, if buswidth is correct. Hardware drivers should set |
2440 | * this correct ! */ | 2424 | * this correct ! */ |
2441 | if (busw != (this->options & NAND_BUSWIDTH_16)) { | 2425 | if (busw != (this->options & NAND_BUSWIDTH_16)) { |
2442 | printk (KERN_INFO "NAND device: Manufacturer ID:" | 2426 | printk(KERN_INFO "NAND device: Manufacturer ID:" |
2443 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, | 2427 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, |
2444 | nand_manuf_ids[maf_id].name , mtd->name); | 2428 | nand_manuf_ids[maf_id].name, mtd->name); |
2445 | printk (KERN_WARNING | 2429 | printk(KERN_WARNING |
2446 | "NAND bus width %d instead %d bit\n", | 2430 | "NAND bus width %d instead %d bit\n", |
2447 | (this->options & NAND_BUSWIDTH_16) ? 16 : 8, | 2431 | (this->options & NAND_BUSWIDTH_16) ? 16 : 8, busw ? 16 : 8); |
2448 | busw ? 16 : 8); | ||
2449 | this->select_chip(mtd, -1); | 2432 | this->select_chip(mtd, -1); |
2450 | return 1; | 2433 | return 1; |
2451 | } | 2434 | } |
@@ -2456,13 +2439,12 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2456 | this->chip_shift = ffs(this->chipsize) - 1; | 2439 | this->chip_shift = ffs(this->chipsize) - 1; |
2457 | 2440 | ||
2458 | /* Set the bad block position */ | 2441 | /* Set the bad block position */ |
2459 | this->badblockpos = mtd->oobblock > 512 ? | 2442 | this->badblockpos = mtd->oobblock > 512 ? NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS; |
2460 | NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS; | ||
2461 | 2443 | ||
2462 | /* Get chip options, preserve non chip based options */ | 2444 | /* Get chip options, preserve non chip based options */ |
2463 | this->options &= ~NAND_CHIPOPTIONS_MSK; | 2445 | this->options &= ~NAND_CHIPOPTIONS_MSK; |
2464 | this->options |= nand_flash_ids[i].options & NAND_CHIPOPTIONS_MSK; | 2446 | this->options |= nand_flash_ids[i].options & NAND_CHIPOPTIONS_MSK; |
2465 | /* Set this as a default. Board drivers can override it, if neccecary */ | 2447 | /* Set this as a default. Board drivers can override it, if necessary */ |
2466 | this->options |= NAND_NO_AUTOINCR; | 2448 | this->options |= NAND_NO_AUTOINCR; |
2467 | /* Check if this is a not a samsung device. Do not clear the options | 2449 | /* Check if this is a not a samsung device. Do not clear the options |
2468 | * for chips which are not having an extended id. | 2450 | * for chips which are not having an extended id. |
@@ -2480,23 +2462,23 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2480 | if (mtd->oobblock > 512 && this->cmdfunc == nand_command) | 2462 | if (mtd->oobblock > 512 && this->cmdfunc == nand_command) |
2481 | this->cmdfunc = nand_command_lp; | 2463 | this->cmdfunc = nand_command_lp; |
2482 | 2464 | ||
2483 | printk (KERN_INFO "NAND device: Manufacturer ID:" | 2465 | printk(KERN_INFO "NAND device: Manufacturer ID:" |
2484 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, | 2466 | " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, |
2485 | nand_manuf_ids[maf_id].name , nand_flash_ids[i].name); | 2467 | nand_manuf_ids[maf_id].name, nand_flash_ids[i].name); |
2486 | break; | 2468 | break; |
2487 | } | 2469 | } |
2488 | 2470 | ||
2489 | if (!nand_flash_ids[i].name) { | 2471 | if (!nand_flash_ids[i].name) { |
2490 | printk (KERN_WARNING "No NAND device found!!!\n"); | 2472 | printk(KERN_WARNING "No NAND device found!!!\n"); |
2491 | this->select_chip(mtd, -1); | 2473 | this->select_chip(mtd, -1); |
2492 | return 1; | 2474 | return 1; |
2493 | } | 2475 | } |
2494 | 2476 | ||
2495 | for (i=1; i < maxchips; i++) { | 2477 | for (i = 1; i < maxchips; i++) { |
2496 | this->select_chip(mtd, i); | 2478 | this->select_chip(mtd, i); |
2497 | 2479 | ||
2498 | /* Send the command for reading device ID */ | 2480 | /* Send the command for reading device ID */ |
2499 | this->cmdfunc (mtd, NAND_CMD_READID, 0x00, -1); | 2481 | this->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); |
2500 | 2482 | ||
2501 | /* Read manufacturer and device IDs */ | 2483 | /* Read manufacturer and device IDs */ |
2502 | if (nand_maf_id != this->read_byte(mtd) || | 2484 | if (nand_maf_id != this->read_byte(mtd) || |
@@ -2506,13 +2488,13 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2506 | if (i > 1) | 2488 | if (i > 1) |
2507 | printk(KERN_INFO "%d NAND chips detected\n", i); | 2489 | printk(KERN_INFO "%d NAND chips detected\n", i); |
2508 | 2490 | ||
2509 | /* Allocate buffers, if neccecary */ | 2491 | /* Allocate buffers, if necessary */ |
2510 | if (!this->oob_buf) { | 2492 | if (!this->oob_buf) { |
2511 | size_t len; | 2493 | size_t len; |
2512 | len = mtd->oobsize << (this->phys_erase_shift - this->page_shift); | 2494 | len = mtd->oobsize << (this->phys_erase_shift - this->page_shift); |
2513 | this->oob_buf = kmalloc (len, GFP_KERNEL); | 2495 | this->oob_buf = kmalloc(len, GFP_KERNEL); |
2514 | if (!this->oob_buf) { | 2496 | if (!this->oob_buf) { |
2515 | printk (KERN_ERR "nand_scan(): Cannot allocate oob_buf\n"); | 2497 | printk(KERN_ERR "nand_scan(): Cannot allocate oob_buf\n"); |
2516 | return -ENOMEM; | 2498 | return -ENOMEM; |
2517 | } | 2499 | } |
2518 | this->options |= NAND_OOBBUF_ALLOC; | 2500 | this->options |= NAND_OOBBUF_ALLOC; |
@@ -2521,11 +2503,11 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2521 | if (!this->data_buf) { | 2503 | if (!this->data_buf) { |
2522 | size_t len; | 2504 | size_t len; |
2523 | len = mtd->oobblock + mtd->oobsize; | 2505 | len = mtd->oobblock + mtd->oobsize; |
2524 | this->data_buf = kmalloc (len, GFP_KERNEL); | 2506 | this->data_buf = kmalloc(len, GFP_KERNEL); |
2525 | if (!this->data_buf) { | 2507 | if (!this->data_buf) { |
2526 | if (this->options & NAND_OOBBUF_ALLOC) | 2508 | if (this->options & NAND_OOBBUF_ALLOC) |
2527 | kfree (this->oob_buf); | 2509 | kfree(this->oob_buf); |
2528 | printk (KERN_ERR "nand_scan(): Cannot allocate data_buf\n"); | 2510 | printk(KERN_ERR "nand_scan(): Cannot allocate data_buf\n"); |
2529 | return -ENOMEM; | 2511 | return -ENOMEM; |
2530 | } | 2512 | } |
2531 | this->options |= NAND_DATABUF_ALLOC; | 2513 | this->options |= NAND_DATABUF_ALLOC; |
@@ -2555,8 +2537,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2555 | this->autooob = &nand_oob_64; | 2537 | this->autooob = &nand_oob_64; |
2556 | break; | 2538 | break; |
2557 | default: | 2539 | default: |
2558 | printk (KERN_WARNING "No oob scheme defined for oobsize %d\n", | 2540 | printk(KERN_WARNING "No oob scheme defined for oobsize %d\n", mtd->oobsize); |
2559 | mtd->oobsize); | ||
2560 | BUG(); | 2541 | BUG(); |
2561 | } | 2542 | } |
2562 | } | 2543 | } |
@@ -2571,7 +2552,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2571 | * check ECC mode, default to software | 2552 | * check ECC mode, default to software |
2572 | * if 3byte/512byte hardware ECC is selected and we have 256 byte pagesize | 2553 | * if 3byte/512byte hardware ECC is selected and we have 256 byte pagesize |
2573 | * fallback to software ECC | 2554 | * fallback to software ECC |
2574 | */ | 2555 | */ |
2575 | this->eccsize = 256; /* set default eccsize */ | 2556 | this->eccsize = 256; /* set default eccsize */ |
2576 | this->eccbytes = 3; | 2557 | this->eccbytes = 3; |
2577 | 2558 | ||
@@ -2591,19 +2572,19 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2591 | case NAND_ECC_HW6_512: | 2572 | case NAND_ECC_HW6_512: |
2592 | case NAND_ECC_HW8_512: | 2573 | case NAND_ECC_HW8_512: |
2593 | if (mtd->oobblock == 256) { | 2574 | if (mtd->oobblock == 256) { |
2594 | printk (KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n"); | 2575 | printk(KERN_WARNING "512 byte HW ECC not possible on 256 Byte pagesize, fallback to SW ECC \n"); |
2595 | this->eccmode = NAND_ECC_SOFT; | 2576 | this->eccmode = NAND_ECC_SOFT; |
2596 | this->calculate_ecc = nand_calculate_ecc; | 2577 | this->calculate_ecc = nand_calculate_ecc; |
2597 | this->correct_data = nand_correct_data; | 2578 | this->correct_data = nand_correct_data; |
2598 | } else | 2579 | } else |
2599 | this->eccsize = 512; /* set eccsize to 512 */ | 2580 | this->eccsize = 512; /* set eccsize to 512 */ |
2600 | break; | 2581 | break; |
2601 | 2582 | ||
2602 | case NAND_ECC_HW3_256: | 2583 | case NAND_ECC_HW3_256: |
2603 | break; | 2584 | break; |
2604 | 2585 | ||
2605 | case NAND_ECC_NONE: | 2586 | case NAND_ECC_NONE: |
2606 | printk (KERN_WARNING "NAND_ECC_NONE selected by board driver. This is not recommended !!\n"); | 2587 | printk(KERN_WARNING "NAND_ECC_NONE selected by board driver. This is not recommended !!\n"); |
2607 | this->eccmode = NAND_ECC_NONE; | 2588 | this->eccmode = NAND_ECC_NONE; |
2608 | break; | 2589 | break; |
2609 | 2590 | ||
@@ -2613,13 +2594,13 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2613 | break; | 2594 | break; |
2614 | 2595 | ||
2615 | default: | 2596 | default: |
2616 | printk (KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode); | 2597 | printk(KERN_WARNING "Invalid NAND_ECC_MODE %d\n", this->eccmode); |
2617 | BUG(); | 2598 | BUG(); |
2618 | } | 2599 | } |
2619 | 2600 | ||
2620 | /* Check hardware ecc function availability and adjust number of ecc bytes per | 2601 | /* Check hardware ecc function availability and adjust number of ecc bytes per |
2621 | * calculation step | 2602 | * calculation step |
2622 | */ | 2603 | */ |
2623 | switch (this->eccmode) { | 2604 | switch (this->eccmode) { |
2624 | case NAND_ECC_HW12_2048: | 2605 | case NAND_ECC_HW12_2048: |
2625 | this->eccbytes += 4; | 2606 | this->eccbytes += 4; |
@@ -2631,7 +2612,7 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2631 | case NAND_ECC_HW3_256: | 2612 | case NAND_ECC_HW3_256: |
2632 | if (this->calculate_ecc && this->correct_data && this->enable_hwecc) | 2613 | if (this->calculate_ecc && this->correct_data && this->enable_hwecc) |
2633 | break; | 2614 | break; |
2634 | printk (KERN_WARNING "No ECC functions supplied, Hardware ECC not possible\n"); | 2615 | printk(KERN_WARNING "No ECC functions supplied, Hardware ECC not possible\n"); |
2635 | BUG(); | 2616 | BUG(); |
2636 | } | 2617 | } |
2637 | 2618 | ||
@@ -2659,8 +2640,8 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2659 | 2640 | ||
2660 | /* Initialize state, waitqueue and spinlock */ | 2641 | /* Initialize state, waitqueue and spinlock */ |
2661 | this->state = FL_READY; | 2642 | this->state = FL_READY; |
2662 | init_waitqueue_head (&this->wq); | 2643 | init_waitqueue_head(&this->wq); |
2663 | spin_lock_init (&this->chip_lock); | 2644 | spin_lock_init(&this->chip_lock); |
2664 | 2645 | ||
2665 | /* De-select the device */ | 2646 | /* De-select the device */ |
2666 | this->select_chip(mtd, -1); | 2647 | this->select_chip(mtd, -1); |
@@ -2702,37 +2683,36 @@ int nand_scan (struct mtd_info *mtd, int maxchips) | |||
2702 | return 0; | 2683 | return 0; |
2703 | 2684 | ||
2704 | /* Build bad block table */ | 2685 | /* Build bad block table */ |
2705 | return this->scan_bbt (mtd); | 2686 | return this->scan_bbt(mtd); |
2706 | } | 2687 | } |
2707 | 2688 | ||
2708 | /** | 2689 | /** |
2709 | * nand_release - [NAND Interface] Free resources held by the NAND device | 2690 | * nand_release - [NAND Interface] Free resources held by the NAND device |
2710 | * @mtd: MTD device structure | 2691 | * @mtd: MTD device structure |
2711 | */ | 2692 | */ |
2712 | void nand_release (struct mtd_info *mtd) | 2693 | void nand_release(struct mtd_info *mtd) |
2713 | { | 2694 | { |
2714 | struct nand_chip *this = mtd->priv; | 2695 | struct nand_chip *this = mtd->priv; |
2715 | 2696 | ||
2716 | #ifdef CONFIG_MTD_PARTITIONS | 2697 | #ifdef CONFIG_MTD_PARTITIONS |
2717 | /* Deregister partitions */ | 2698 | /* Deregister partitions */ |
2718 | del_mtd_partitions (mtd); | 2699 | del_mtd_partitions(mtd); |
2719 | #endif | 2700 | #endif |
2720 | /* Deregister the device */ | 2701 | /* Deregister the device */ |
2721 | del_mtd_device (mtd); | 2702 | del_mtd_device(mtd); |
2722 | 2703 | ||
2723 | /* Free bad block table memory */ | 2704 | /* Free bad block table memory */ |
2724 | kfree (this->bbt); | 2705 | kfree(this->bbt); |
2725 | /* Buffer allocated by nand_scan ? */ | 2706 | /* Buffer allocated by nand_scan ? */ |
2726 | if (this->options & NAND_OOBBUF_ALLOC) | 2707 | if (this->options & NAND_OOBBUF_ALLOC) |
2727 | kfree (this->oob_buf); | 2708 | kfree(this->oob_buf); |
2728 | /* Buffer allocated by nand_scan ? */ | 2709 | /* Buffer allocated by nand_scan ? */ |
2729 | if (this->options & NAND_DATABUF_ALLOC) | 2710 | if (this->options & NAND_DATABUF_ALLOC) |
2730 | kfree (this->data_buf); | 2711 | kfree(this->data_buf); |
2731 | } | 2712 | } |
2732 | 2713 | ||
2733 | EXPORT_SYMBOL_GPL (nand_scan); | 2714 | EXPORT_SYMBOL_GPL(nand_scan); |
2734 | EXPORT_SYMBOL_GPL (nand_release); | 2715 | EXPORT_SYMBOL_GPL(nand_release); |
2735 | |||
2736 | 2716 | ||
2737 | static int __init nand_base_init(void) | 2717 | static int __init nand_base_init(void) |
2738 | { | 2718 | { |
@@ -2748,6 +2728,6 @@ static void __exit nand_base_exit(void) | |||
2748 | module_init(nand_base_init); | 2728 | module_init(nand_base_init); |
2749 | module_exit(nand_base_exit); | 2729 | module_exit(nand_base_exit); |
2750 | 2730 | ||
2751 | MODULE_LICENSE ("GPL"); | 2731 | MODULE_LICENSE("GPL"); |
2752 | MODULE_AUTHOR ("Steven J. Hill <sjhill@realitydiluted.com>, Thomas Gleixner <tglx@linutronix.de>"); | 2732 | MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com>, Thomas Gleixner <tglx@linutronix.de>"); |
2753 | MODULE_DESCRIPTION ("Generic NAND flash driver code"); | 2733 | MODULE_DESCRIPTION("Generic NAND flash driver code"); |