aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/nand/nand_base.c1054
1 files changed, 520 insertions, 534 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 649c238837bb..6036d322bf68 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -10,63 +10,21 @@
10 * http://www.linux-mtd.infradead.org/tech/nand.html 10 * http://www.linux-mtd.infradead.org/tech/nand.html
11 * 11 *
12 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com) 12 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
13 * 2002 Thomas Gleixner (tglx@linutronix.de) 13 * 2002-2006 Thomas Gleixner (tglx@linutronix.de)
14 * 14 *
15 * 02-08-2004 tglx: support for strange chips, which cannot auto increment 15 * Credits:
16 * pages on read / read_oob
17 *
18 * 03-17-2004 tglx: Check ready before auto increment check. Simon Bayes
19 * pointed this out, as he marked an auto increment capable chip
20 * as NOAUTOINCR in the board driver.
21 * Make reads over block boundaries work too
22 *
23 * 04-14-2004 tglx: first working version for 2k page size chips
24 *
25 * 05-19-2004 tglx: Basic support for Renesas AG-AND chips
26 *
27 * 09-24-2004 tglx: add support for hardware controllers (e.g. ECC) shared
28 * among multiple independend devices. Suggestions and initial
29 * patch from Ben Dooks <ben-mtd@fluff.org>
30 *
31 * 12-05-2004 dmarlin: add workaround for Renesas AG-AND chips "disturb"
32 * issue. Basically, any block not rewritten may lose data when
33 * surrounding blocks are rewritten many times. JFFS2 ensures
34 * this doesn't happen for blocks it uses, but the Bad Block
35 * Table(s) may not be rewritten. To ensure they do not lose
36 * data, force them to be rewritten when some of the surrounding
37 * blocks are erased. Rather than tracking a specific nearby
38 * block (which could itself go bad), use a page address 'mask' to
39 * select several blocks in the same area, and rewrite the BBT
40 * when any of them are erased.
41 *
42 * 01-03-2005 dmarlin: added support for the device recovery command sequence
43 * for Renesas AG-AND chips. If there was a sudden loss of power
44 * during an erase operation, a "device recovery" operation must
45 * be performed when power is restored to ensure correct
46 * operation.
47 *
48 * 01-20-2005 dmarlin: added support for optional hardware specific callback
49 * routine to perform extra error status checks on erase and write
50 * failures. This required adding a wrapper function for
51 * nand_read_ecc.
52 *
53 * 08-20-2005 vwool: suspend/resume added
54 *
55 * Credits:
56 * David Woodhouse for adding multichip support 16 * David Woodhouse for adding multichip support
57 * 17 *
58 * Aleph One Ltd. and Toby Churchill Ltd. for supporting the 18 * Aleph One Ltd. and Toby Churchill Ltd. for supporting the
59 * rework for 2K page size chips 19 * rework for 2K page size chips
60 * 20 *
61 * TODO: 21 * TODO:
62 * Enable cached programming for 2k page size chips 22 * Enable cached programming for 2k page size chips
63 * Check, if mtd->ecctype should be set to MTD_ECC_HW 23 * Check, if mtd->ecctype should be set to MTD_ECC_HW
64 * if we have HW ecc support. 24 * if we have HW ecc support.
65 * The AG-AND chips have nice features for speed improvement, 25 * The AG-AND chips have nice features for speed improvement,
66 * which are not supported yet. Read / program 4 pages in one go. 26 * which are not supported yet. Read / program 4 pages in one go.
67 * 27 *
68 * $Id: nand_base.c,v 1.150 2005/09/15 13:58:48 vwool Exp $
69 *
70 * This program is free software; you can redistribute it and/or modify 28 * This program is free software; you can redistribute it and/or modify
71 * it under the terms of the GNU General Public License version 2 as 29 * it under the terms of the GNU General Public License version 2 as
72 * published by the Free Software Foundation. 30 * published by the Free Software Foundation.
@@ -149,11 +107,11 @@ static int nand_erase(struct mtd_info *mtd, struct erase_info *instr);
149static void nand_sync(struct mtd_info *mtd); 107static void nand_sync(struct mtd_info *mtd);
150 108
151/* Some internal functions */ 109/* Some internal functions */
152static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, 110static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
153 int page, uint8_t * oob_buf, 111 int page, uint8_t * oob_buf,
154 struct nand_oobinfo *oobsel, int mode); 112 struct nand_oobinfo *oobsel, int mode);
155#ifdef CONFIG_MTD_NAND_VERIFY_WRITE 113#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
156static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, 114static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *chip,
157 int page, int numpages, uint8_t *oob_buf, 115 int page, int numpages, uint8_t *oob_buf,
158 struct nand_oobinfo *oobsel, int chipnr, 116 struct nand_oobinfo *oobsel, int chipnr,
159 int oobmode); 117 int oobmode);
@@ -161,7 +119,7 @@ static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this,
161#define nand_verify_pages(...) (0) 119#define nand_verify_pages(...) (0)
162#endif 120#endif
163 121
164static int nand_get_device(struct nand_chip *this, struct mtd_info *mtd, 122static int nand_get_device(struct nand_chip *chip, struct mtd_info *mtd,
165 int new_state); 123 int new_state);
166 124
167/* 125/*
@@ -178,17 +136,17 @@ DEFINE_LED_TRIGGER(nand_led_trigger);
178 */ 136 */
179static void nand_release_device(struct mtd_info *mtd) 137static void nand_release_device(struct mtd_info *mtd)
180{ 138{
181 struct nand_chip *this = mtd->priv; 139 struct nand_chip *chip = mtd->priv;
182 140
183 /* De-select the NAND device */ 141 /* De-select the NAND device */
184 this->select_chip(mtd, -1); 142 chip->select_chip(mtd, -1);
185 143
186 /* Release the controller and the chip */ 144 /* Release the controller and the chip */
187 spin_lock(&this->controller->lock); 145 spin_lock(&chip->controller->lock);
188 this->controller->active = NULL; 146 chip->controller->active = NULL;
189 this->state = FL_READY; 147 chip->state = FL_READY;
190 wake_up(&this->controller->wq); 148 wake_up(&chip->controller->wq);
191 spin_unlock(&this->controller->lock); 149 spin_unlock(&chip->controller->lock);
192} 150}
193 151
194/** 152/**
@@ -199,8 +157,8 @@ static void nand_release_device(struct mtd_info *mtd)
199 */ 157 */
200static uint8_t nand_read_byte(struct mtd_info *mtd) 158static uint8_t nand_read_byte(struct mtd_info *mtd)
201{ 159{
202 struct nand_chip *this = mtd->priv; 160 struct nand_chip *chip = mtd->priv;
203 return readb(this->IO_ADDR_R); 161 return readb(chip->IO_ADDR_R);
204} 162}
205 163
206/** 164/**
@@ -212,8 +170,8 @@ static uint8_t nand_read_byte(struct mtd_info *mtd)
212 */ 170 */
213static uint8_t nand_read_byte16(struct mtd_info *mtd) 171static uint8_t nand_read_byte16(struct mtd_info *mtd)
214{ 172{
215 struct nand_chip *this = mtd->priv; 173 struct nand_chip *chip = mtd->priv;
216 return (uint8_t) cpu_to_le16(readw(this->IO_ADDR_R)); 174 return (uint8_t) cpu_to_le16(readw(chip->IO_ADDR_R));
217} 175}
218 176
219/** 177/**
@@ -225,8 +183,8 @@ static uint8_t nand_read_byte16(struct mtd_info *mtd)
225 */ 183 */
226static u16 nand_read_word(struct mtd_info *mtd) 184static u16 nand_read_word(struct mtd_info *mtd)
227{ 185{
228 struct nand_chip *this = mtd->priv; 186 struct nand_chip *chip = mtd->priv;
229 return readw(this->IO_ADDR_R); 187 return readw(chip->IO_ADDR_R);
230} 188}
231 189
232/** 190/**
@@ -236,15 +194,17 @@ static u16 nand_read_word(struct mtd_info *mtd)
236 * 194 *
237 * Default select function for 1 chip devices. 195 * Default select function for 1 chip devices.
238 */ 196 */
239static void nand_select_chip(struct mtd_info *mtd, int chip) 197static void nand_select_chip(struct mtd_info *mtd, int chipnr)
240{ 198{
241 struct nand_chip *this = mtd->priv; 199 struct nand_chip *chip = mtd->priv;
242 switch (chip) { 200
201 switch (chipnr) {
243 case -1: 202 case -1:
244 this->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE); 203 chip->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE);
245 break; 204 break;
246 case 0: 205 case 0:
247 this->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); 206 chip->cmd_ctrl(mtd, NAND_CMD_NONE,
207 NAND_NCE | NAND_CTRL_CHANGE);
248 break; 208 break;
249 209
250 default: 210 default:
@@ -263,10 +223,10 @@ static void nand_select_chip(struct mtd_info *mtd, int chip)
263static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 223static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
264{ 224{
265 int i; 225 int i;
266 struct nand_chip *this = mtd->priv; 226 struct nand_chip *chip = mtd->priv;
267 227
268 for (i = 0; i < len; i++) 228 for (i = 0; i < len; i++)
269 writeb(buf[i], this->IO_ADDR_W); 229 writeb(buf[i], chip->IO_ADDR_W);
270} 230}
271 231
272/** 232/**
@@ -280,10 +240,10 @@ static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
280static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 240static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
281{ 241{
282 int i; 242 int i;
283 struct nand_chip *this = mtd->priv; 243 struct nand_chip *chip = mtd->priv;
284 244
285 for (i = 0; i < len; i++) 245 for (i = 0; i < len; i++)
286 buf[i] = readb(this->IO_ADDR_R); 246 buf[i] = readb(chip->IO_ADDR_R);
287} 247}
288 248
289/** 249/**
@@ -297,10 +257,10 @@ static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
297static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 257static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
298{ 258{
299 int i; 259 int i;
300 struct nand_chip *this = mtd->priv; 260 struct nand_chip *chip = mtd->priv;
301 261
302 for (i = 0; i < len; i++) 262 for (i = 0; i < len; i++)
303 if (buf[i] != readb(this->IO_ADDR_R)) 263 if (buf[i] != readb(chip->IO_ADDR_R))
304 return -EFAULT; 264 return -EFAULT;
305 265
306 return 0; 266 return 0;
@@ -317,12 +277,12 @@ static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
317static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) 277static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
318{ 278{
319 int i; 279 int i;
320 struct nand_chip *this = mtd->priv; 280 struct nand_chip *chip = mtd->priv;
321 u16 *p = (u16 *) buf; 281 u16 *p = (u16 *) buf;
322 len >>= 1; 282 len >>= 1;
323 283
324 for (i = 0; i < len; i++) 284 for (i = 0; i < len; i++)
325 writew(p[i], this->IO_ADDR_W); 285 writew(p[i], chip->IO_ADDR_W);
326 286
327} 287}
328 288
@@ -337,12 +297,12 @@ static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
337static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len) 297static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
338{ 298{
339 int i; 299 int i;
340 struct nand_chip *this = mtd->priv; 300 struct nand_chip *chip = mtd->priv;
341 u16 *p = (u16 *) buf; 301 u16 *p = (u16 *) buf;
342 len >>= 1; 302 len >>= 1;
343 303
344 for (i = 0; i < len; i++) 304 for (i = 0; i < len; i++)
345 p[i] = readw(this->IO_ADDR_R); 305 p[i] = readw(chip->IO_ADDR_R);
346} 306}
347 307
348/** 308/**
@@ -356,12 +316,12 @@ static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
356static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) 316static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
357{ 317{
358 int i; 318 int i;
359 struct nand_chip *this = mtd->priv; 319 struct nand_chip *chip = mtd->priv;
360 u16 *p = (u16 *) buf; 320 u16 *p = (u16 *) buf;
361 len >>= 1; 321 len >>= 1;
362 322
363 for (i = 0; i < len; i++) 323 for (i = 0; i < len; i++)
364 if (p[i] != readw(this->IO_ADDR_R)) 324 if (p[i] != readw(chip->IO_ADDR_R))
365 return -EFAULT; 325 return -EFAULT;
366 326
367 return 0; 327 return 0;
@@ -378,40 +338,37 @@ static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
378static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) 338static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
379{ 339{
380 int page, chipnr, res = 0; 340 int page, chipnr, res = 0;
381 struct nand_chip *this = mtd->priv; 341 struct nand_chip *chip = mtd->priv;
382 u16 bad; 342 u16 bad;
383 343
384 if (getchip) { 344 if (getchip) {
385 page = (int)(ofs >> this->page_shift); 345 page = (int)(ofs >> chip->page_shift);
386 chipnr = (int)(ofs >> this->chip_shift); 346 chipnr = (int)(ofs >> chip->chip_shift);
387 347
388 /* Grab the lock and see if the device is available */ 348 nand_get_device(chip, mtd, FL_READING);
389 nand_get_device(this, mtd, FL_READING);
390 349
391 /* Select the NAND device */ 350 /* Select the NAND device */
392 this->select_chip(mtd, chipnr); 351 chip->select_chip(mtd, chipnr);
393 } else 352 } else
394 page = (int)ofs; 353 page = (int)ofs;
395 354
396 if (this->options & NAND_BUSWIDTH_16) { 355 if (chip->options & NAND_BUSWIDTH_16) {
397 this->cmdfunc(mtd, NAND_CMD_READOOB, this->badblockpos & 0xFE, 356 chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos & 0xFE,
398 page & this->pagemask); 357 page & chip->pagemask);
399 bad = cpu_to_le16(this->read_word(mtd)); 358 bad = cpu_to_le16(chip->read_word(mtd));
400 if (this->badblockpos & 0x1) 359 if (chip->badblockpos & 0x1)
401 bad >>= 8; 360 bad >>= 8;
402 if ((bad & 0xFF) != 0xff) 361 if ((bad & 0xFF) != 0xff)
403 res = 1; 362 res = 1;
404 } else { 363 } else {
405 this->cmdfunc(mtd, NAND_CMD_READOOB, this->badblockpos, 364 chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos,
406 page & this->pagemask); 365 page & chip->pagemask);
407 if (this->read_byte(mtd) != 0xff) 366 if (chip->read_byte(mtd) != 0xff)
408 res = 1; 367 res = 1;
409 } 368 }
410 369
411 if (getchip) { 370 if (getchip)
412 /* Deselect and wake up anyone waiting on the device */
413 nand_release_device(mtd); 371 nand_release_device(mtd);
414 }
415 372
416 return res; 373 return res;
417} 374}
@@ -426,22 +383,22 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
426*/ 383*/
427static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) 384static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
428{ 385{
429 struct nand_chip *this = mtd->priv; 386 struct nand_chip *chip = mtd->priv;
430 uint8_t buf[2] = { 0, 0 }; 387 uint8_t buf[2] = { 0, 0 };
431 size_t retlen; 388 size_t retlen;
432 int block; 389 int block;
433 390
434 /* Get block number */ 391 /* Get block number */
435 block = ((int)ofs) >> this->bbt_erase_shift; 392 block = ((int)ofs) >> chip->bbt_erase_shift;
436 if (this->bbt) 393 if (chip->bbt)
437 this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); 394 chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
438 395
439 /* Do we have a flash based bad block table ? */ 396 /* Do we have a flash based bad block table ? */
440 if (this->options & NAND_USE_FLASH_BBT) 397 if (chip->options & NAND_USE_FLASH_BBT)
441 return nand_update_bbt(mtd, ofs); 398 return nand_update_bbt(mtd, ofs);
442 399
443 /* We write two bytes, so we dont have to mess with 16 bit access */ 400 /* We write two bytes, so we dont have to mess with 16 bit access */
444 ofs += mtd->oobsize + (this->badblockpos & ~0x01); 401 ofs += mtd->oobsize + (chip->badblockpos & ~0x01);
445 return nand_write_oob(mtd, ofs, 2, &retlen, buf); 402 return nand_write_oob(mtd, ofs, 2, &retlen, buf);
446} 403}
447 404
@@ -454,10 +411,10 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
454 */ 411 */
455static int nand_check_wp(struct mtd_info *mtd) 412static int nand_check_wp(struct mtd_info *mtd)
456{ 413{
457 struct nand_chip *this = mtd->priv; 414 struct nand_chip *chip = mtd->priv;
458 /* Check the WP bit */ 415 /* Check the WP bit */
459 this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); 416 chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
460 return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1; 417 return (chip->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1;
461} 418}
462 419
463/** 420/**
@@ -473,10 +430,10 @@ static int nand_check_wp(struct mtd_info *mtd)
473static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, 430static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
474 int allowbbt) 431 int allowbbt)
475{ 432{
476 struct nand_chip *this = mtd->priv; 433 struct nand_chip *chip = mtd->priv;
477 434
478 if (!this->bbt) 435 if (!chip->bbt)
479 return this->block_bad(mtd, ofs, getchip); 436 return chip->block_bad(mtd, ofs, getchip);
480 437
481 /* Return info from the table */ 438 /* Return info from the table */
482 return nand_isbad_bbt(mtd, ofs, allowbbt); 439 return nand_isbad_bbt(mtd, ofs, allowbbt);
@@ -488,13 +445,13 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
488 */ 445 */
489static void nand_wait_ready(struct mtd_info *mtd) 446static void nand_wait_ready(struct mtd_info *mtd)
490{ 447{
491 struct nand_chip *this = mtd->priv; 448 struct nand_chip *chip = mtd->priv;
492 unsigned long timeo = jiffies + 2; 449 unsigned long timeo = jiffies + 2;
493 450
494 led_trigger_event(nand_led_trigger, LED_FULL); 451 led_trigger_event(nand_led_trigger, LED_FULL);
495 /* wait until command is processed or timeout occures */ 452 /* wait until command is processed or timeout occures */
496 do { 453 do {
497 if (this->dev_ready(mtd)) 454 if (chip->dev_ready(mtd))
498 break; 455 break;
499 touch_softlockup_watchdog(); 456 touch_softlockup_watchdog();
500 } while (time_before(jiffies, timeo)); 457 } while (time_before(jiffies, timeo));
@@ -514,7 +471,7 @@ static void nand_wait_ready(struct mtd_info *mtd)
514static void nand_command(struct mtd_info *mtd, unsigned int command, 471static void nand_command(struct mtd_info *mtd, unsigned int command,
515 int column, int page_addr) 472 int column, int page_addr)
516{ 473{
517 register struct nand_chip *this = mtd->priv; 474 register struct nand_chip *chip = mtd->priv;
518 int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE; 475 int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE;
519 476
520 /* 477 /*
@@ -534,10 +491,10 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
534 column -= 256; 491 column -= 256;
535 readcmd = NAND_CMD_READ1; 492 readcmd = NAND_CMD_READ1;
536 } 493 }
537 this->cmd_ctrl(mtd, readcmd, ctrl); 494 chip->cmd_ctrl(mtd, readcmd, ctrl);
538 ctrl &= ~NAND_CTRL_CHANGE; 495 ctrl &= ~NAND_CTRL_CHANGE;
539 } 496 }
540 this->cmd_ctrl(mtd, command, ctrl); 497 chip->cmd_ctrl(mtd, command, ctrl);
541 498
542 /* 499 /*
543 * Address cycle, when necessary 500 * Address cycle, when necessary
@@ -546,20 +503,20 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
546 /* Serially input address */ 503 /* Serially input address */
547 if (column != -1) { 504 if (column != -1) {
548 /* Adjust columns for 16 bit buswidth */ 505 /* Adjust columns for 16 bit buswidth */
549 if (this->options & NAND_BUSWIDTH_16) 506 if (chip->options & NAND_BUSWIDTH_16)
550 column >>= 1; 507 column >>= 1;
551 this->cmd_ctrl(mtd, column, ctrl); 508 chip->cmd_ctrl(mtd, column, ctrl);
552 ctrl &= ~NAND_CTRL_CHANGE; 509 ctrl &= ~NAND_CTRL_CHANGE;
553 } 510 }
554 if (page_addr != -1) { 511 if (page_addr != -1) {
555 this->cmd_ctrl(mtd, page_addr, ctrl); 512 chip->cmd_ctrl(mtd, page_addr, ctrl);
556 ctrl &= ~NAND_CTRL_CHANGE; 513 ctrl &= ~NAND_CTRL_CHANGE;
557 this->cmd_ctrl(mtd, page_addr >> 8, ctrl); 514 chip->cmd_ctrl(mtd, page_addr >> 8, ctrl);
558 /* One more address cycle for devices > 32MiB */ 515 /* One more address cycle for devices > 32MiB */
559 if (this->chipsize > (32 << 20)) 516 if (chip->chipsize > (32 << 20))
560 this->cmd_ctrl(mtd, page_addr >> 16, ctrl); 517 chip->cmd_ctrl(mtd, page_addr >> 16, ctrl);
561 } 518 }
562 this->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); 519 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE);
563 520
564 /* 521 /*
565 * program and erase have their own busy handlers 522 * program and erase have their own busy handlers
@@ -572,17 +529,17 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
572 case NAND_CMD_ERASE2: 529 case NAND_CMD_ERASE2:
573 case NAND_CMD_SEQIN: 530 case NAND_CMD_SEQIN:
574 case NAND_CMD_STATUS: 531 case NAND_CMD_STATUS:
575 this->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE); 532 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE);
576 return; 533 return;
577 534
578 case NAND_CMD_RESET: 535 case NAND_CMD_RESET:
579 if (this->dev_ready) 536 if (chip->dev_ready)
580 break; 537 break;
581 udelay(this->chip_delay); 538 udelay(chip->chip_delay);
582 this->cmd_ctrl(mtd, NAND_CMD_STATUS, 539 chip->cmd_ctrl(mtd, NAND_CMD_STATUS,
583 NAND_CTRL_CLE | NAND_CTRL_CHANGE); 540 NAND_CTRL_CLE | NAND_CTRL_CHANGE);
584 this->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE); 541 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE);
585 while (!(this->read_byte(mtd) & NAND_STATUS_READY)) ; 542 while (!(chip->read_byte(mtd) & NAND_STATUS_READY)) ;
586 return; 543 return;
587 544
588 /* This applies to read commands */ 545 /* This applies to read commands */
@@ -591,8 +548,8 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
591 * If we don't have access to the busy pin, we apply the given 548 * If we don't have access to the busy pin, we apply the given
592 * command delay 549 * command delay
593 */ 550 */
594 if (!this->dev_ready) { 551 if (!chip->dev_ready) {
595 udelay(this->chip_delay); 552 udelay(chip->chip_delay);
596 return; 553 return;
597 } 554 }
598 } 555 }
@@ -618,7 +575,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
618static void nand_command_lp(struct mtd_info *mtd, unsigned int command, 575static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
619 int column, int page_addr) 576 int column, int page_addr)
620{ 577{
621 register struct nand_chip *this = mtd->priv; 578 register struct nand_chip *chip = mtd->priv;
622 579
623 /* Emulate NAND_CMD_READOOB */ 580 /* Emulate NAND_CMD_READOOB */
624 if (command == NAND_CMD_READOOB) { 581 if (command == NAND_CMD_READOOB) {
@@ -627,7 +584,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
627 } 584 }
628 585
629 /* Command latch cycle */ 586 /* Command latch cycle */
630 this->cmd_ctrl(mtd, command & 0xff, 587 chip->cmd_ctrl(mtd, command & 0xff,
631 NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); 588 NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE);
632 589
633 if (column != -1 || page_addr != -1) { 590 if (column != -1 || page_addr != -1) {
@@ -636,23 +593,23 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
636 /* Serially input address */ 593 /* Serially input address */
637 if (column != -1) { 594 if (column != -1) {
638 /* Adjust columns for 16 bit buswidth */ 595 /* Adjust columns for 16 bit buswidth */
639 if (this->options & NAND_BUSWIDTH_16) 596 if (chip->options & NAND_BUSWIDTH_16)
640 column >>= 1; 597 column >>= 1;
641 this->cmd_ctrl(mtd, column, ctrl); 598 chip->cmd_ctrl(mtd, column, ctrl);
642 ctrl &= ~NAND_CTRL_CHANGE; 599 ctrl &= ~NAND_CTRL_CHANGE;
643 this->cmd_ctrl(mtd, column >> 8, ctrl); 600 chip->cmd_ctrl(mtd, column >> 8, ctrl);
644 } 601 }
645 if (page_addr != -1) { 602 if (page_addr != -1) {
646 this->cmd_ctrl(mtd, page_addr, ctrl); 603 chip->cmd_ctrl(mtd, page_addr, ctrl);
647 this->cmd_ctrl(mtd, page_addr >> 8, 604 chip->cmd_ctrl(mtd, page_addr >> 8,
648 NAND_NCE | NAND_ALE); 605 NAND_NCE | NAND_ALE);
649 /* One more address cycle for devices > 128MiB */ 606 /* One more address cycle for devices > 128MiB */
650 if (this->chipsize > (128 << 20)) 607 if (chip->chipsize > (128 << 20))
651 this->cmd_ctrl(mtd, page_addr >> 16, 608 chip->cmd_ctrl(mtd, page_addr >> 16,
652 NAND_NCE | NAND_ALE); 609 NAND_NCE | NAND_ALE);
653 } 610 }
654 } 611 }
655 this->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); 612 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE);
656 613
657 /* 614 /*
658 * program and erase have their own busy handlers 615 * program and erase have their own busy handlers
@@ -677,21 +634,21 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
677 case NAND_CMD_STATUS_ERROR1: 634 case NAND_CMD_STATUS_ERROR1:
678 case NAND_CMD_STATUS_ERROR2: 635 case NAND_CMD_STATUS_ERROR2:
679 case NAND_CMD_STATUS_ERROR3: 636 case NAND_CMD_STATUS_ERROR3:
680 udelay(this->chip_delay); 637 udelay(chip->chip_delay);
681 return; 638 return;
682 639
683 case NAND_CMD_RESET: 640 case NAND_CMD_RESET:
684 if (this->dev_ready) 641 if (chip->dev_ready)
685 break; 642 break;
686 udelay(this->chip_delay); 643 udelay(chip->chip_delay);
687 this->cmd_ctrl(mtd, NAND_CMD_STATUS, NAND_NCE | NAND_CLE); 644 chip->cmd_ctrl(mtd, NAND_CMD_STATUS, NAND_NCE | NAND_CLE);
688 this->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE); 645 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE);
689 while (!(this->read_byte(mtd) & NAND_STATUS_READY)) ; 646 while (!(chip->read_byte(mtd) & NAND_STATUS_READY)) ;
690 return; 647 return;
691 648
692 case NAND_CMD_READ0: 649 case NAND_CMD_READ0:
693 this->cmd_ctrl(mtd, NAND_CMD_READSTART, NAND_NCE | NAND_CLE); 650 chip->cmd_ctrl(mtd, NAND_CMD_READSTART, NAND_NCE | NAND_CLE);
694 this->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE); 651 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE);
695 652
696 /* This applies to read commands */ 653 /* This applies to read commands */
697 default: 654 default:
@@ -699,8 +656,8 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
699 * If we don't have access to the busy pin, we apply the given 656 * If we don't have access to the busy pin, we apply the given
700 * command delay 657 * command delay
701 */ 658 */
702 if (!this->dev_ready) { 659 if (!chip->dev_ready) {
703 udelay(this->chip_delay); 660 udelay(chip->chip_delay);
704 return; 661 return;
705 } 662 }
706 } 663 }
@@ -721,27 +678,27 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
721 * Get the device and lock it for exclusive access 678 * Get the device and lock it for exclusive access
722 */ 679 */
723static int 680static int
724nand_get_device(struct nand_chip *this, struct mtd_info *mtd, int new_state) 681nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, int new_state)
725{ 682{
726 spinlock_t *lock = &this->controller->lock; 683 spinlock_t *lock = &chip->controller->lock;
727 wait_queue_head_t *wq = &this->controller->wq; 684 wait_queue_head_t *wq = &chip->controller->wq;
728 DECLARE_WAITQUEUE(wait, current); 685 DECLARE_WAITQUEUE(wait, current);
729 retry: 686 retry:
730 spin_lock(lock); 687 spin_lock(lock);
731 688
732 /* Hardware controller shared among independend devices */ 689 /* Hardware controller shared among independend devices */
733 /* Hardware controller shared among independend devices */ 690 /* Hardware controller shared among independend devices */
734 if (!this->controller->active) 691 if (!chip->controller->active)
735 this->controller->active = this; 692 chip->controller->active = chip;
736 693
737 if (this->controller->active == this && this->state == FL_READY) { 694 if (chip->controller->active == chip && chip->state == FL_READY) {
738 this->state = new_state; 695 chip->state = new_state;
739 spin_unlock(lock); 696 spin_unlock(lock);
740 return 0; 697 return 0;
741 } 698 }
742 if (new_state == FL_PM_SUSPENDED) { 699 if (new_state == FL_PM_SUSPENDED) {
743 spin_unlock(lock); 700 spin_unlock(lock);
744 return (this->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN; 701 return (chip->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN;
745 } 702 }
746 set_current_state(TASK_UNINTERRUPTIBLE); 703 set_current_state(TASK_UNINTERRUPTIBLE);
747 add_wait_queue(wq, &wait); 704 add_wait_queue(wq, &wait);
@@ -762,7 +719,7 @@ nand_get_device(struct nand_chip *this, struct mtd_info *mtd, int new_state)
762 * general NAND and SmartMedia specs 719 * general NAND and SmartMedia specs
763 * 720 *
764*/ 721*/
765static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state) 722static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip, int state)
766{ 723{
767 724
768 unsigned long timeo = jiffies; 725 unsigned long timeo = jiffies;
@@ -779,28 +736,28 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
779 * any case on any machine. */ 736 * any case on any machine. */
780 ndelay(100); 737 ndelay(100);
781 738
782 if ((state == FL_ERASING) && (this->options & NAND_IS_AND)) 739 if ((state == FL_ERASING) && (chip->options & NAND_IS_AND))
783 this->cmdfunc(mtd, NAND_CMD_STATUS_MULTI, -1, -1); 740 chip->cmdfunc(mtd, NAND_CMD_STATUS_MULTI, -1, -1);
784 else 741 else
785 this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); 742 chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
786 743
787 while (time_before(jiffies, timeo)) { 744 while (time_before(jiffies, timeo)) {
788 /* Check, if we were interrupted */ 745 /* Check, if we were interrupted */
789 if (this->state != state) 746 if (chip->state != state)
790 return 0; 747 return 0;
791 748
792 if (this->dev_ready) { 749 if (chip->dev_ready) {
793 if (this->dev_ready(mtd)) 750 if (chip->dev_ready(mtd))
794 break; 751 break;
795 } else { 752 } else {
796 if (this->read_byte(mtd) & NAND_STATUS_READY) 753 if (chip->read_byte(mtd) & NAND_STATUS_READY)
797 break; 754 break;
798 } 755 }
799 cond_resched(); 756 cond_resched();
800 } 757 }
801 led_trigger_event(nand_led_trigger, LED_OFF); 758 led_trigger_event(nand_led_trigger, LED_OFF);
802 759
803 status = (int)this->read_byte(mtd); 760 status = (int)chip->read_byte(mtd);
804 return status; 761 return status;
805} 762}
806 763
@@ -808,7 +765,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
808 * nand_write_page - [GENERIC] write one page 765 * nand_write_page - [GENERIC] write one page
809 * @mtd: MTD device structure 766 * @mtd: MTD device structure
810 * @this: NAND chip structure 767 * @this: NAND chip structure
811 * @page: startpage inside the chip, must be called with (page & this->pagemask) 768 * @page: startpage inside the chip, must be called with (page & chip->pagemask)
812 * @oob_buf: out of band data buffer 769 * @oob_buf: out of band data buffer
813 * @oobsel: out of band selecttion structre 770 * @oobsel: out of band selecttion structre
814 * @cached: 1 = enable cached programming if supported by chip 771 * @cached: 1 = enable cached programming if supported by chip
@@ -819,75 +776,75 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
819 * 776 *
820 * Cached programming is not supported yet. 777 * Cached programming is not supported yet.
821 */ 778 */
822static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int page, 779static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, int page,
823 uint8_t *oob_buf, struct nand_oobinfo *oobsel, int cached) 780 uint8_t *oob_buf, struct nand_oobinfo *oobsel, int cached)
824{ 781{
825 int i, status; 782 int i, status;
826 uint8_t ecc_code[32]; 783 uint8_t ecc_code[32];
827 int eccmode = oobsel->useecc ? this->ecc.mode : NAND_ECC_NONE; 784 int eccmode = oobsel->useecc ? chip->ecc.mode : NAND_ECC_NONE;
828 int *oob_config = oobsel->eccpos; 785 int *oob_config = oobsel->eccpos;
829 int datidx = 0, eccidx = 0, eccsteps = this->ecc.steps; 786 int datidx = 0, eccidx = 0, eccsteps = chip->ecc.steps;
830 int eccbytes = 0; 787 int eccbytes = 0;
831 788
832 /* FIXME: Enable cached programming */ 789 /* FIXME: Enable cached programming */
833 cached = 0; 790 cached = 0;
834 791
835 /* Send command to begin auto page programming */ 792 /* Send command to begin auto page programming */
836 this->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); 793 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
837 794
838 /* Write out complete page of data, take care of eccmode */ 795 /* Write out complete page of data, take care of eccmode */
839 switch (eccmode) { 796 switch (eccmode) {
840 /* No ecc, write all */ 797 /* No ecc, write all */
841 case NAND_ECC_NONE: 798 case NAND_ECC_NONE:
842 printk(KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n"); 799 printk(KERN_WARNING "Writing data without ECC to NAND-FLASH is not recommended\n");
843 this->write_buf(mtd, this->data_poi, mtd->writesize); 800 chip->write_buf(mtd, chip->data_poi, mtd->writesize);
844 break; 801 break;
845 802
846 /* Software ecc 3/256, write all */ 803 /* Software ecc 3/256, write all */
847 case NAND_ECC_SOFT: 804 case NAND_ECC_SOFT:
848 for (; eccsteps; eccsteps--) { 805 for (; eccsteps; eccsteps--) {
849 this->ecc.calculate(mtd, &this->data_poi[datidx], ecc_code); 806 chip->ecc.calculate(mtd, &chip->data_poi[datidx], ecc_code);
850 for (i = 0; i < 3; i++, eccidx++) 807 for (i = 0; i < 3; i++, eccidx++)
851 oob_buf[oob_config[eccidx]] = ecc_code[i]; 808 oob_buf[oob_config[eccidx]] = ecc_code[i];
852 datidx += this->ecc.size; 809 datidx += chip->ecc.size;
853 } 810 }
854 this->write_buf(mtd, this->data_poi, mtd->writesize); 811 chip->write_buf(mtd, chip->data_poi, mtd->writesize);
855 break; 812 break;
856 default: 813 default:
857 eccbytes = this->ecc.bytes; 814 eccbytes = chip->ecc.bytes;
858 for (; eccsteps; eccsteps--) { 815 for (; eccsteps; eccsteps--) {
859 /* enable hardware ecc logic for write */ 816 /* enable hardware ecc logic for write */
860 this->ecc.hwctl(mtd, NAND_ECC_WRITE); 817 chip->ecc.hwctl(mtd, NAND_ECC_WRITE);
861 this->write_buf(mtd, &this->data_poi[datidx], this->ecc.size); 818 chip->write_buf(mtd, &chip->data_poi[datidx], chip->ecc.size);
862 this->ecc.calculate(mtd, &this->data_poi[datidx], ecc_code); 819 chip->ecc.calculate(mtd, &chip->data_poi[datidx], ecc_code);
863 for (i = 0; i < eccbytes; i++, eccidx++) 820 for (i = 0; i < eccbytes; i++, eccidx++)
864 oob_buf[oob_config[eccidx]] = ecc_code[i]; 821 oob_buf[oob_config[eccidx]] = ecc_code[i];
865 /* If the hardware ecc provides syndromes then 822 /* If the hardware ecc provides syndromes then
866 * the ecc code must be written immidiately after 823 * the ecc code must be written immidiately after
867 * the data bytes (words) */ 824 * the data bytes (words) */
868 if (this->options & NAND_HWECC_SYNDROME) 825 if (chip->options & NAND_HWECC_SYNDROME)
869 this->write_buf(mtd, ecc_code, eccbytes); 826 chip->write_buf(mtd, ecc_code, eccbytes);
870 datidx += this->ecc.size; 827 datidx += chip->ecc.size;
871 } 828 }
872 break; 829 break;
873 } 830 }
874 831
875 /* Write out OOB data */ 832 /* Write out OOB data */
876 if (this->options & NAND_HWECC_SYNDROME) 833 if (chip->options & NAND_HWECC_SYNDROME)
877 this->write_buf(mtd, &oob_buf[oobsel->eccbytes], mtd->oobsize - oobsel->eccbytes); 834 chip->write_buf(mtd, &oob_buf[oobsel->eccbytes], mtd->oobsize - oobsel->eccbytes);
878 else 835 else
879 this->write_buf(mtd, oob_buf, mtd->oobsize); 836 chip->write_buf(mtd, oob_buf, mtd->oobsize);
880 837
881 /* Send command to actually program the data */ 838 /* Send command to actually program the data */
882 this->cmdfunc(mtd, cached ? NAND_CMD_CACHEDPROG : NAND_CMD_PAGEPROG, -1, -1); 839 chip->cmdfunc(mtd, cached ? NAND_CMD_CACHEDPROG : NAND_CMD_PAGEPROG, -1, -1);
883 840
884 if (!cached) { 841 if (!cached) {
885 /* call wait ready function */ 842 /* call wait ready function */
886 status = this->waitfunc(mtd, this, FL_WRITING); 843 status = chip->waitfunc(mtd, chip, FL_WRITING);
887 844
888 /* See if operation failed and additional status checks are available */ 845 /* See if operation failed and additional status checks are available */
889 if ((status & NAND_STATUS_FAIL) && (this->errstat)) { 846 if ((status & NAND_STATUS_FAIL) && (chip->errstat)) {
890 status = this->errstat(mtd, this, FL_WRITING, status, page); 847 status = chip->errstat(mtd, chip, FL_WRITING, status, page);
891 } 848 }
892 849
893 /* See if device thinks it succeeded */ 850 /* See if device thinks it succeeded */
@@ -898,7 +855,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int pag
898 } else { 855 } else {
899 /* FIXME: Implement cached programming ! */ 856 /* FIXME: Implement cached programming ! */
900 /* wait until cache is ready */ 857 /* wait until cache is ready */
901 // status = this->waitfunc (mtd, this, FL_CACHEDRPG); 858 // status = chip->waitfunc (mtd, this, FL_CACHEDRPG);
902 } 859 }
903 return 0; 860 return 0;
904} 861}
@@ -908,7 +865,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int pag
908 * nand_verify_pages - [GENERIC] verify the chip contents after a write 865 * nand_verify_pages - [GENERIC] verify the chip contents after a write
909 * @mtd: MTD device structure 866 * @mtd: MTD device structure
910 * @this: NAND chip structure 867 * @this: NAND chip structure
911 * @page: startpage inside the chip, must be called with (page & this->pagemask) 868 * @page: startpage inside the chip, must be called with (page & chip->pagemask)
912 * @numpages: number of pages to verify 869 * @numpages: number of pages to verify
913 * @oob_buf: out of band data buffer 870 * @oob_buf: out of band data buffer
914 * @oobsel: out of band selecttion structre 871 * @oobsel: out of band selecttion structre
@@ -923,23 +880,23 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *this, int pag
923 * the error later when the ECC page check fails, but we would rather catch 880 * the error later when the ECC page check fails, but we would rather catch
924 * it early in the page write stage. Better to write no data than invalid data. 881 * it early in the page write stage. Better to write no data than invalid data.
925 */ 882 */
926static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, int page, int numpages, 883static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *chip, int page, int numpages,
927 uint8_t *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode) 884 uint8_t *oob_buf, struct nand_oobinfo *oobsel, int chipnr, int oobmode)
928{ 885{
929 int i, j, datidx = 0, oobofs = 0, res = -EIO; 886 int i, j, datidx = 0, oobofs = 0, res = -EIO;
930 int eccsteps = this->eccsteps; 887 int eccsteps = chip->eccsteps;
931 int hweccbytes; 888 int hweccbytes;
932 uint8_t oobdata[64]; 889 uint8_t oobdata[64];
933 890
934 hweccbytes = (this->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0; 891 hweccbytes = (chip->options & NAND_HWECC_SYNDROME) ? (oobsel->eccbytes / eccsteps) : 0;
935 892
936 /* Send command to read back the first page */ 893 /* Send command to read back the first page */
937 this->cmdfunc(mtd, NAND_CMD_READ0, 0, page); 894 chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
938 895
939 for (;;) { 896 for (;;) {
940 for (j = 0; j < eccsteps; j++) { 897 for (j = 0; j < eccsteps; j++) {
941 /* Loop through and verify the data */ 898 /* Loop through and verify the data */
942 if (this->verify_buf(mtd, &this->data_poi[datidx], mtd->eccsize)) { 899 if (chip->verify_buf(mtd, &chip->data_poi[datidx], mtd->eccsize)) {
943 DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); 900 DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page);
944 goto out; 901 goto out;
945 } 902 }
@@ -947,7 +904,7 @@ static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, int p
947 /* Have we a hw generator layout ? */ 904 /* Have we a hw generator layout ? */
948 if (!hweccbytes) 905 if (!hweccbytes)
949 continue; 906 continue;
950 if (this->verify_buf(mtd, &this->oob_buf[oobofs], hweccbytes)) { 907 if (chip->verify_buf(mtd, &chip->oob_buf[oobofs], hweccbytes)) {
951 DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); 908 DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page);
952 goto out; 909 goto out;
953 } 910 }
@@ -958,13 +915,13 @@ static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, int p
958 * compare the ecc bytes 915 * compare the ecc bytes
959 */ 916 */
960 if (oobmode) { 917 if (oobmode) {
961 if (this->verify_buf(mtd, &oob_buf[oobofs], mtd->oobsize - hweccbytes * eccsteps)) { 918 if (chip->verify_buf(mtd, &oob_buf[oobofs], mtd->oobsize - hweccbytes * eccsteps)) {
962 DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page); 919 DEBUG(MTD_DEBUG_LEVEL0, "%s: " "Failed write verify, page 0x%08x ", __FUNCTION__, page);
963 goto out; 920 goto out;
964 } 921 }
965 } else { 922 } else {
966 /* Read always, else autoincrement fails */ 923 /* Read always, else autoincrement fails */
967 this->read_buf(mtd, oobdata, mtd->oobsize - hweccbytes * eccsteps); 924 chip->read_buf(mtd, oobdata, mtd->oobsize - hweccbytes * eccsteps);
968 925
969 if (oobsel->useecc != MTD_NANDECC_OFF && !hweccbytes) { 926 if (oobsel->useecc != MTD_NANDECC_OFF && !hweccbytes) {
970 int ecccnt = oobsel->eccbytes; 927 int ecccnt = oobsel->eccbytes;
@@ -990,8 +947,8 @@ static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, int p
990 * Do this also before returning, so the chip is 947 * Do this also before returning, so the chip is
991 * ready for the next command. 948 * ready for the next command.
992 */ 949 */
993 if (!this->dev_ready) 950 if (!chip->dev_ready)
994 udelay(this->chip_delay); 951 udelay(chip->chip_delay);
995 else 952 else
996 nand_wait_ready(mtd); 953 nand_wait_ready(mtd);
997 954
@@ -1001,14 +958,14 @@ static int nand_verify_pages(struct mtd_info *mtd, struct nand_chip *this, int p
1001 958
1002 /* Check, if the chip supports auto page increment */ 959 /* Check, if the chip supports auto page increment */
1003 if (!NAND_CANAUTOINCR(this)) 960 if (!NAND_CANAUTOINCR(this))
1004 this->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); 961 chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
1005 } 962 }
1006 /* 963 /*
1007 * Terminate the read command. We come here in case of an error 964 * Terminate the read command. We come here in case of an error
1008 * So we must issue a reset command. 965 * So we must issue a reset command.
1009 */ 966 */
1010 out: 967 out:
1011 this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 968 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
1012 return res; 969 return res;
1013} 970}
1014#endif 971#endif
@@ -1051,13 +1008,13 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1051 1008
1052 int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1; 1009 int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1;
1053 int read = 0, oob = 0, ecc_status = 0, ecc_failed = 0; 1010 int read = 0, oob = 0, ecc_status = 0, ecc_failed = 0;
1054 struct nand_chip *this = mtd->priv; 1011 struct nand_chip *chip = mtd->priv;
1055 uint8_t *data_poi, *oob_data = oob_buf; 1012 uint8_t *data_poi, *oob_data = oob_buf;
1056 uint8_t ecc_calc[32]; 1013 uint8_t ecc_calc[32];
1057 uint8_t ecc_code[32]; 1014 uint8_t ecc_code[32];
1058 int eccmode, eccsteps; 1015 int eccmode, eccsteps;
1059 int *oob_config, datidx; 1016 int *oob_config, datidx;
1060 int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; 1017 int blockcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
1061 int eccbytes; 1018 int eccbytes;
1062 int compareecc = 1; 1019 int compareecc = 1;
1063 int oobreadlen; 1020 int oobreadlen;
@@ -1073,35 +1030,35 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1073 1030
1074 /* Grab the lock and see if the device is available */ 1031 /* Grab the lock and see if the device is available */
1075 if (flags & NAND_GET_DEVICE) 1032 if (flags & NAND_GET_DEVICE)
1076 nand_get_device(this, mtd, FL_READING); 1033 nand_get_device(chip, mtd, FL_READING);
1077 1034
1078 /* Autoplace of oob data ? Use the default placement scheme */ 1035 /* Autoplace of oob data ? Use the default placement scheme */
1079 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) 1036 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE)
1080 oobsel = this->autooob; 1037 oobsel = chip->autooob;
1081 1038
1082 eccmode = oobsel->useecc ? this->ecc.mode : NAND_ECC_NONE; 1039 eccmode = oobsel->useecc ? chip->ecc.mode : NAND_ECC_NONE;
1083 oob_config = oobsel->eccpos; 1040 oob_config = oobsel->eccpos;
1084 1041
1085 /* Select the NAND device */ 1042 /* Select the NAND device */
1086 chipnr = (int)(from >> this->chip_shift); 1043 chipnr = (int)(from >> chip->chip_shift);
1087 this->select_chip(mtd, chipnr); 1044 chip->select_chip(mtd, chipnr);
1088 1045
1089 /* First we calculate the starting page */ 1046 /* First we calculate the starting page */
1090 realpage = (int)(from >> this->page_shift); 1047 realpage = (int)(from >> chip->page_shift);
1091 page = realpage & this->pagemask; 1048 page = realpage & chip->pagemask;
1092 1049
1093 /* Get raw starting column */ 1050 /* Get raw starting column */
1094 col = from & (mtd->writesize - 1); 1051 col = from & (mtd->writesize - 1);
1095 1052
1096 end = mtd->writesize; 1053 end = mtd->writesize;
1097 ecc = this->ecc.size; 1054 ecc = chip->ecc.size;
1098 eccbytes = this->ecc.bytes; 1055 eccbytes = chip->ecc.bytes;
1099 1056
1100 if ((eccmode == NAND_ECC_NONE) || (this->options & NAND_HWECC_SYNDROME)) 1057 if ((eccmode == NAND_ECC_NONE) || (chip->options & NAND_HWECC_SYNDROME))
1101 compareecc = 0; 1058 compareecc = 0;
1102 1059
1103 oobreadlen = mtd->oobsize; 1060 oobreadlen = mtd->oobsize;
1104 if (this->options & NAND_HWECC_SYNDROME) 1061 if (chip->options & NAND_HWECC_SYNDROME)
1105 oobreadlen -= oobsel->eccbytes; 1062 oobreadlen -= oobsel->eccbytes;
1106 1063
1107 /* Loop until all data read */ 1064 /* Loop until all data read */
@@ -1115,32 +1072,32 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1115 if (aligned) 1072 if (aligned)
1116 data_poi = &buf[read]; 1073 data_poi = &buf[read];
1117 else 1074 else
1118 data_poi = this->data_buf; 1075 data_poi = chip->data_buf;
1119 1076
1120 /* Check, if we have this page in the buffer 1077 /* Check, if we have this page in the buffer
1121 * 1078 *
1122 * FIXME: Make it work when we must provide oob data too, 1079 * FIXME: Make it work when we must provide oob data too,
1123 * check the usage of data_buf oob field 1080 * check the usage of data_buf oob field
1124 */ 1081 */
1125 if (realpage == this->pagebuf && !oob_buf) { 1082 if (realpage == chip->pagebuf && !oob_buf) {
1126 /* aligned read ? */ 1083 /* aligned read ? */
1127 if (aligned) 1084 if (aligned)
1128 memcpy(data_poi, this->data_buf, end); 1085 memcpy(data_poi, chip->data_buf, end);
1129 goto readdata; 1086 goto readdata;
1130 } 1087 }
1131 1088
1132 /* Check, if we must send the read command */ 1089 /* Check, if we must send the read command */
1133 if (sndcmd) { 1090 if (sndcmd) {
1134 this->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); 1091 chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
1135 sndcmd = 0; 1092 sndcmd = 0;
1136 } 1093 }
1137 1094
1138 /* get oob area, if we have no oob buffer from fs-driver */ 1095 /* get oob area, if we have no oob buffer from fs-driver */
1139 if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE || 1096 if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE ||
1140 oobsel->useecc == MTD_NANDECC_AUTOPL_USR) 1097 oobsel->useecc == MTD_NANDECC_AUTOPL_USR)
1141 oob_data = &this->data_buf[end]; 1098 oob_data = &chip->data_buf[end];
1142 1099
1143 eccsteps = this->ecc.steps; 1100 eccsteps = chip->ecc.steps;
1144 1101
1145 switch (eccmode) { 1102 switch (eccmode) {
1146 case NAND_ECC_NONE:{ 1103 case NAND_ECC_NONE:{
@@ -1151,46 +1108,46 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1151 "Reading data from NAND FLASH without ECC is not recommended\n"); 1108 "Reading data from NAND FLASH without ECC is not recommended\n");
1152 lastwhinge = jiffies; 1109 lastwhinge = jiffies;
1153 } 1110 }
1154 this->read_buf(mtd, data_poi, end); 1111 chip->read_buf(mtd, data_poi, end);
1155 break; 1112 break;
1156 } 1113 }
1157 1114
1158 case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */ 1115 case NAND_ECC_SOFT: /* Software ECC 3/256: Read in a page + oob data */
1159 this->read_buf(mtd, data_poi, end); 1116 chip->read_buf(mtd, data_poi, end);
1160 for (i = 0, datidx = 0; eccsteps; eccsteps--, i += 3, datidx += ecc) 1117 for (i = 0, datidx = 0; eccsteps; eccsteps--, i += 3, datidx += ecc)
1161 this->ecc.calculate(mtd, &data_poi[datidx], &ecc_calc[i]); 1118 chip->ecc.calculate(mtd, &data_poi[datidx], &ecc_calc[i]);
1162 break; 1119 break;
1163 1120
1164 default: 1121 default:
1165 for (i = 0, datidx = 0; eccsteps; eccsteps--, i += eccbytes, datidx += ecc) { 1122 for (i = 0, datidx = 0; eccsteps; eccsteps--, i += eccbytes, datidx += ecc) {
1166 this->ecc.hwctl(mtd, NAND_ECC_READ); 1123 chip->ecc.hwctl(mtd, NAND_ECC_READ);
1167 this->read_buf(mtd, &data_poi[datidx], ecc); 1124 chip->read_buf(mtd, &data_poi[datidx], ecc);
1168 1125
1169 /* HW ecc with syndrome calculation must read the 1126 /* HW ecc with syndrome calculation must read the
1170 * syndrome from flash immidiately after the data */ 1127 * syndrome from flash immidiately after the data */
1171 if (!compareecc) { 1128 if (!compareecc) {
1172 /* Some hw ecc generators need to know when the 1129 /* Some hw ecc generators need to know when the
1173 * syndrome is read from flash */ 1130 * syndrome is read from flash */
1174 this->ecc.hwctl(mtd, NAND_ECC_READSYN); 1131 chip->ecc.hwctl(mtd, NAND_ECC_READSYN);
1175 this->read_buf(mtd, &oob_data[i], eccbytes); 1132 chip->read_buf(mtd, &oob_data[i], eccbytes);
1176 /* We calc error correction directly, it checks the hw 1133 /* We calc error correction directly, it checks the hw
1177 * generator for an error, reads back the syndrome and 1134 * generator for an error, reads back the syndrome and
1178 * does the error correction on the fly */ 1135 * does the error correction on the fly */
1179 ecc_status = this->ecc.correct(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]); 1136 ecc_status = chip->ecc.correct(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]);
1180 if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { 1137 if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) {
1181 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_ecc: " 1138 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_ecc: "
1182 "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr); 1139 "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr);
1183 ecc_failed++; 1140 ecc_failed++;
1184 } 1141 }
1185 } else { 1142 } else {
1186 this->ecc.calculate(mtd, &data_poi[datidx], &ecc_calc[i]); 1143 chip->ecc.calculate(mtd, &data_poi[datidx], &ecc_calc[i]);
1187 } 1144 }
1188 } 1145 }
1189 break; 1146 break;
1190 } 1147 }
1191 1148
1192 /* read oobdata */ 1149 /* read oobdata */
1193 this->read_buf(mtd, &oob_data[mtd->oobsize - oobreadlen], oobreadlen); 1150 chip->read_buf(mtd, &oob_data[mtd->oobsize - oobreadlen], oobreadlen);
1194 1151
1195 /* Skip ECC check, if not requested (ECC_NONE or HW_ECC with syndromes) */ 1152 /* Skip ECC check, if not requested (ECC_NONE or HW_ECC with syndromes) */
1196 if (!compareecc) 1153 if (!compareecc)
@@ -1201,8 +1158,8 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1201 ecc_code[j] = oob_data[oob_config[j]]; 1158 ecc_code[j] = oob_data[oob_config[j]];
1202 1159
1203 /* correct data, if necessary */ 1160 /* correct data, if necessary */
1204 for (i = 0, j = 0, datidx = 0; i < this->ecc.steps; i++, datidx += ecc) { 1161 for (i = 0, j = 0, datidx = 0; i < chip->ecc.steps; i++, datidx += ecc) {
1205 ecc_status = this->ecc.correct(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]); 1162 ecc_status = chip->ecc.correct(mtd, &data_poi[datidx], &ecc_code[j], &ecc_calc[j]);
1206 1163
1207 /* Get next chunk of ecc bytes */ 1164 /* Get next chunk of ecc bytes */
1208 j += eccbytes; 1165 j += eccbytes;
@@ -1239,7 +1196,7 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1239 break; 1196 break;
1240 case MTD_NANDECC_PLACE: 1197 case MTD_NANDECC_PLACE:
1241 /* YAFFS1 legacy mode */ 1198 /* YAFFS1 legacy mode */
1242 oob_data += this->ecc.steps * sizeof(int); 1199 oob_data += chip->ecc.steps * sizeof(int);
1243 default: 1200 default:
1244 oob_data += mtd->oobsize; 1201 oob_data += mtd->oobsize;
1245 } 1202 }
@@ -1249,7 +1206,7 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1249 if (!aligned) { 1206 if (!aligned) {
1250 for (j = col; j < end && read < len; j++) 1207 for (j = col; j < end && read < len; j++)
1251 buf[read++] = data_poi[j]; 1208 buf[read++] = data_poi[j];
1252 this->pagebuf = realpage; 1209 chip->pagebuf = realpage;
1253 } else 1210 } else
1254 read += mtd->writesize; 1211 read += mtd->writesize;
1255 1212
@@ -1258,8 +1215,8 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1258 * arise if a chip which does auto increment 1215 * arise if a chip which does auto increment
1259 * is marked as NOAUTOINCR by the board driver. 1216 * is marked as NOAUTOINCR by the board driver.
1260 */ 1217 */
1261 if (!this->dev_ready) 1218 if (!chip->dev_ready)
1262 udelay(this->chip_delay); 1219 udelay(chip->chip_delay);
1263 else 1220 else
1264 nand_wait_ready(mtd); 1221 nand_wait_ready(mtd);
1265 1222
@@ -1271,17 +1228,17 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1271 /* Increment page address */ 1228 /* Increment page address */
1272 realpage++; 1229 realpage++;
1273 1230
1274 page = realpage & this->pagemask; 1231 page = realpage & chip->pagemask;
1275 /* Check, if we cross a chip boundary */ 1232 /* Check, if we cross a chip boundary */
1276 if (!page) { 1233 if (!page) {
1277 chipnr++; 1234 chipnr++;
1278 this->select_chip(mtd, -1); 1235 chip->select_chip(mtd, -1);
1279 this->select_chip(mtd, chipnr); 1236 chip->select_chip(mtd, chipnr);
1280 } 1237 }
1281 /* Check, if the chip supports auto page increment 1238 /* Check, if the chip supports auto page increment
1282 * or if we have hit a block boundary. 1239 * or if we have hit a block boundary.
1283 */ 1240 */
1284 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) 1241 if (!NAND_CANAUTOINCR(chip) || !(page & blockcheck))
1285 sndcmd = 1; 1242 sndcmd = 1;
1286 } 1243 }
1287 1244
@@ -1311,14 +1268,14 @@ int nand_do_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
1311static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, uint8_t *buf) 1268static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, uint8_t *buf)
1312{ 1269{
1313 int i, col, page, chipnr; 1270 int i, col, page, chipnr;
1314 struct nand_chip *this = mtd->priv; 1271 struct nand_chip *chip = mtd->priv;
1315 int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; 1272 int blockcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
1316 1273
1317 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08x, len = %i\n", (unsigned int)from, (int)len); 1274 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08x, len = %i\n", (unsigned int)from, (int)len);
1318 1275
1319 /* Shift to get page */ 1276 /* Shift to get page */
1320 page = (int)(from >> this->page_shift); 1277 page = (int)(from >> chip->page_shift);
1321 chipnr = (int)(from >> this->chip_shift); 1278 chipnr = (int)(from >> chip->chip_shift);
1322 1279
1323 /* Mask to get column */ 1280 /* Mask to get column */
1324 col = from & (mtd->oobsize - 1); 1281 col = from & (mtd->oobsize - 1);
@@ -1334,13 +1291,13 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *
1334 } 1291 }
1335 1292
1336 /* Grab the lock and see if the device is available */ 1293 /* Grab the lock and see if the device is available */
1337 nand_get_device(this, mtd, FL_READING); 1294 nand_get_device(chip, mtd, FL_READING);
1338 1295
1339 /* Select the NAND device */ 1296 /* Select the NAND device */
1340 this->select_chip(mtd, chipnr); 1297 chip->select_chip(mtd, chipnr);
1341 1298
1342 /* Send the read command */ 1299 /* Send the read command */
1343 this->cmdfunc(mtd, NAND_CMD_READOOB, col, page & this->pagemask); 1300 chip->cmdfunc(mtd, NAND_CMD_READOOB, col, page & chip->pagemask);
1344 /* 1301 /*
1345 * Read the data, if we read more than one page 1302 * Read the data, if we read more than one page
1346 * oob data, let the device transfer the data ! 1303 * oob data, let the device transfer the data !
@@ -1349,7 +1306,7 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *
1349 while (i < len) { 1306 while (i < len) {
1350 int thislen = mtd->oobsize - col; 1307 int thislen = mtd->oobsize - col;
1351 thislen = min_t(int, thislen, len); 1308 thislen = min_t(int, thislen, len);
1352 this->read_buf(mtd, &buf[i], thislen); 1309 chip->read_buf(mtd, &buf[i], thislen);
1353 i += thislen; 1310 i += thislen;
1354 1311
1355 /* Read more ? */ 1312 /* Read more ? */
@@ -1358,10 +1315,10 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *
1358 col = 0; 1315 col = 0;
1359 1316
1360 /* Check, if we cross a chip boundary */ 1317 /* Check, if we cross a chip boundary */
1361 if (!(page & this->pagemask)) { 1318 if (!(page & chip->pagemask)) {
1362 chipnr++; 1319 chipnr++;
1363 this->select_chip(mtd, -1); 1320 chip->select_chip(mtd, -1);
1364 this->select_chip(mtd, chipnr); 1321 chip->select_chip(mtd, chipnr);
1365 } 1322 }
1366 1323
1367 /* Apply delay or wait for ready/busy pin 1324 /* Apply delay or wait for ready/busy pin
@@ -1369,17 +1326,17 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *
1369 * arise if a chip which does auto increment 1326 * arise if a chip which does auto increment
1370 * is marked as NOAUTOINCR by the board driver. 1327 * is marked as NOAUTOINCR by the board driver.
1371 */ 1328 */
1372 if (!this->dev_ready) 1329 if (!chip->dev_ready)
1373 udelay(this->chip_delay); 1330 udelay(chip->chip_delay);
1374 else 1331 else
1375 nand_wait_ready(mtd); 1332 nand_wait_ready(mtd);
1376 1333
1377 /* Check, if the chip supports auto page increment 1334 /* Check, if the chip supports auto page increment
1378 * or if we have hit a block boundary. 1335 * or if we have hit a block boundary.
1379 */ 1336 */
1380 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) { 1337 if (!NAND_CANAUTOINCR(chip) || !(page & blockcheck)) {
1381 /* For subsequent page reads set offset to 0 */ 1338 /* For subsequent page reads set offset to 0 */
1382 this->cmdfunc(mtd, NAND_CMD_READOOB, 0x0, page & this->pagemask); 1339 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0x0, page & chip->pagemask);
1383 } 1340 }
1384 } 1341 }
1385 } 1342 }
@@ -1402,48 +1359,55 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, size_t *
1402 * 1359 *
1403 * Read raw data including oob into buffer 1360 * Read raw data including oob into buffer
1404 */ 1361 */
1405int nand_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, size_t ooblen) 1362int nand_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len,
1363 size_t ooblen)
1406{ 1364{
1407 struct nand_chip *this = mtd->priv; 1365 struct nand_chip *chip = mtd->priv;
1408 int page = (int)(from >> this->page_shift); 1366 int page = (int)(from >> chip->page_shift);
1409 int chip = (int)(from >> this->chip_shift); 1367 int chipnr = (int)(from >> chip->chip_shift);
1410 int sndcmd = 1; 1368 int sndcmd = 1;
1411 int cnt = 0; 1369 int cnt = 0;
1412 int pagesize = mtd->writesize + mtd->oobsize; 1370 int pagesize = mtd->writesize + mtd->oobsize;
1413 int blockcheck = (1 << (this->phys_erase_shift - this->page_shift)) - 1; 1371 int blockcheck;
1414 1372
1415 /* Do not allow reads past end of device */ 1373 /* Do not allow reads past end of device */
1416 if ((from + len) > mtd->size) { 1374 if ((from + len) > mtd->size) {
1417 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_raw: Attempt read beyond end of device\n"); 1375 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_raw: "
1376 "Attempt read beyond end of device\n");
1418 return -EINVAL; 1377 return -EINVAL;
1419 } 1378 }
1420 1379
1421 /* Grab the lock and see if the device is available */ 1380 /* Grab the lock and see if the device is available */
1422 nand_get_device(this, mtd, FL_READING); 1381 nand_get_device(chip, mtd, FL_READING);
1423 1382
1424 this->select_chip(mtd, chip); 1383 chip->select_chip(mtd, chipnr);
1425 1384
1426 /* Add requested oob length */ 1385 /* Add requested oob length */
1427 len += ooblen; 1386 len += ooblen;
1387 blockcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
1428 1388
1429 while (len) { 1389 while (len) {
1430 if (sndcmd) 1390 if (sndcmd)
1431 this->cmdfunc(mtd, NAND_CMD_READ0, 0, page & this->pagemask); 1391 chip->cmdfunc(mtd, NAND_CMD_READ0, 0,
1392 page & chip->pagemask);
1432 sndcmd = 0; 1393 sndcmd = 0;
1433 1394
1434 this->read_buf(mtd, &buf[cnt], pagesize); 1395 chip->read_buf(mtd, &buf[cnt], pagesize);
1435 1396
1436 len -= pagesize; 1397 len -= pagesize;
1437 cnt += pagesize; 1398 cnt += pagesize;
1438 page++; 1399 page++;
1439 1400
1440 if (!this->dev_ready) 1401 if (!chip->dev_ready)
1441 udelay(this->chip_delay); 1402 udelay(chip->chip_delay);
1442 else 1403 else
1443 nand_wait_ready(mtd); 1404 nand_wait_ready(mtd);
1444 1405
1445 /* Check, if the chip supports auto page increment */ 1406 /*
1446 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) 1407 * Check, if the chip supports auto page increment or if we
1408 * cross a block boundary.
1409 */
1410 if (!NAND_CANAUTOINCR(chip) || !(page & blockcheck))
1447 sndcmd = 1; 1411 sndcmd = 1;
1448 } 1412 }
1449 1413
@@ -1466,9 +1430,9 @@ int nand_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, s
1466int nand_write_raw(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, 1430int nand_write_raw(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
1467 uint8_t *buf, uint8_t *oob) 1431 uint8_t *buf, uint8_t *oob)
1468{ 1432{
1469 struct nand_chip *this = mtd->priv; 1433 struct nand_chip *chip = mtd->priv;
1470 int page = (int)(to >> this->page_shift); 1434 int page = (int)(to >> chip->page_shift);
1471 int chip = (int)(to >> this->chip_shift); 1435 int chipnr = (int)(to >> chip->chip_shift);
1472 int ret; 1436 int ret;
1473 1437
1474 *retlen = 0; 1438 *retlen = 0;
@@ -1481,18 +1445,18 @@ int nand_write_raw(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
1481 } 1445 }
1482 1446
1483 /* Grab the lock and see if the device is available */ 1447 /* Grab the lock and see if the device is available */
1484 nand_get_device(this, mtd, FL_WRITING); 1448 nand_get_device(chip, mtd, FL_WRITING);
1485 1449
1486 this->select_chip(mtd, chip); 1450 chip->select_chip(mtd, chipnr);
1487 this->data_poi = buf; 1451 chip->data_poi = buf;
1488 1452
1489 while (len != *retlen) { 1453 while (len != *retlen) {
1490 ret = nand_write_page(mtd, this, page, oob, &mtd->oobinfo, 0); 1454 ret = nand_write_page(mtd, chip, page, oob, &mtd->oobinfo, 0);
1491 if (ret) 1455 if (ret)
1492 return ret; 1456 return ret;
1493 page++; 1457 page++;
1494 *retlen += mtd->writesize; 1458 *retlen += mtd->writesize;
1495 this->data_poi += mtd->writesize; 1459 chip->data_poi += mtd->writesize;
1496 oob += mtd->oobsize; 1460 oob += mtd->oobsize;
1497 } 1461 }
1498 1462
@@ -1528,7 +1492,7 @@ EXPORT_SYMBOL_GPL(nand_write_raw);
1528static uint8_t *nand_prepare_oobbuf(struct mtd_info *mtd, uint8_t *fsbuf, struct nand_oobinfo *oobsel, 1492static uint8_t *nand_prepare_oobbuf(struct mtd_info *mtd, uint8_t *fsbuf, struct nand_oobinfo *oobsel,
1529 int autoplace, int numpages) 1493 int autoplace, int numpages)
1530{ 1494{
1531 struct nand_chip *this = mtd->priv; 1495 struct nand_chip *chip = mtd->priv;
1532 int i, len, ofs; 1496 int i, len, ofs;
1533 1497
1534 /* Zero copy fs supplied buffer */ 1498 /* Zero copy fs supplied buffer */
@@ -1536,29 +1500,29 @@ static uint8_t *nand_prepare_oobbuf(struct mtd_info *mtd, uint8_t *fsbuf, struct
1536 return fsbuf; 1500 return fsbuf;
1537 1501
1538 /* Check, if the buffer must be filled with ff again */ 1502 /* Check, if the buffer must be filled with ff again */
1539 if (this->oobdirty) { 1503 if (chip->oobdirty) {
1540 memset(this->oob_buf, 0xff, mtd->oobsize << (this->phys_erase_shift - this->page_shift)); 1504 memset(chip->oob_buf, 0xff, mtd->oobsize << (chip->phys_erase_shift - chip->page_shift));
1541 this->oobdirty = 0; 1505 chip->oobdirty = 0;
1542 } 1506 }
1543 1507
1544 /* If we have no autoplacement or no fs buffer use the internal one */ 1508 /* If we have no autoplacement or no fs buffer use the internal one */
1545 if (!autoplace || !fsbuf) 1509 if (!autoplace || !fsbuf)
1546 return this->oob_buf; 1510 return chip->oob_buf;
1547 1511
1548 /* Walk through the pages and place the data */ 1512 /* Walk through the pages and place the data */
1549 this->oobdirty = 1; 1513 chip->oobdirty = 1;
1550 ofs = 0; 1514 ofs = 0;
1551 while (numpages--) { 1515 while (numpages--) {
1552 for (i = 0, len = 0; len < mtd->oobavail; i++) { 1516 for (i = 0, len = 0; len < mtd->oobavail; i++) {
1553 int to = ofs + oobsel->oobfree[i][0]; 1517 int to = ofs + oobsel->oobfree[i][0];
1554 int num = oobsel->oobfree[i][1]; 1518 int num = oobsel->oobfree[i][1];
1555 memcpy(&this->oob_buf[to], fsbuf, num); 1519 memcpy(&chip->oob_buf[to], fsbuf, num);
1556 len += num; 1520 len += num;
1557 fsbuf += num; 1521 fsbuf += num;
1558 } 1522 }
1559 ofs += mtd->oobavail; 1523 ofs += mtd->oobavail;
1560 } 1524 }
1561 return this->oob_buf; 1525 return chip->oob_buf;
1562} 1526}
1563 1527
1564#define NOTALIGNED(x) (x & (mtd->writesize-1)) != 0 1528#define NOTALIGNED(x) (x & (mtd->writesize-1)) != 0
@@ -1578,9 +1542,9 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1578{ 1542{
1579 int startpage, page, ret = -EIO, oob = 0, written = 0, chipnr; 1543 int startpage, page, ret = -EIO, oob = 0, written = 0, chipnr;
1580 int autoplace = 0, numpages, totalpages; 1544 int autoplace = 0, numpages, totalpages;
1581 struct nand_chip *this = mtd->priv; 1545 struct nand_chip *chip = mtd->priv;
1582 uint8_t *oobbuf, *bufstart, *eccbuf = NULL; 1546 uint8_t *oobbuf, *bufstart, *eccbuf = NULL;
1583 int ppblock = (1 << (this->phys_erase_shift - this->page_shift)); 1547 int ppblock = (1 << (chip->phys_erase_shift - chip->page_shift));
1584 struct nand_oobinfo *oobsel = &mtd->oobinfo; 1548 struct nand_oobinfo *oobsel = &mtd->oobinfo;
1585 1549
1586 DEBUG(MTD_DEBUG_LEVEL3, "nand_write: to = 0x%08x, len = %i\n", (unsigned int)to, (int)len); 1550 DEBUG(MTD_DEBUG_LEVEL3, "nand_write: to = 0x%08x, len = %i\n", (unsigned int)to, (int)len);
@@ -1601,12 +1565,12 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1601 } 1565 }
1602 1566
1603 /* Grab the lock and see if the device is available */ 1567 /* Grab the lock and see if the device is available */
1604 nand_get_device(this, mtd, FL_WRITING); 1568 nand_get_device(chip, mtd, FL_WRITING);
1605 1569
1606 /* Calculate chipnr */ 1570 /* Calculate chipnr */
1607 chipnr = (int)(to >> this->chip_shift); 1571 chipnr = (int)(to >> chip->chip_shift);
1608 /* Select the NAND device */ 1572 /* Select the NAND device */
1609 this->select_chip(mtd, chipnr); 1573 chip->select_chip(mtd, chipnr);
1610 1574
1611 /* Check, if it is write protected */ 1575 /* Check, if it is write protected */
1612 if (nand_check_wp(mtd)) 1576 if (nand_check_wp(mtd))
@@ -1614,21 +1578,21 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1614 1578
1615 /* Autoplace of oob data ? Use the default placement scheme */ 1579 /* Autoplace of oob data ? Use the default placement scheme */
1616 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) { 1580 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) {
1617 oobsel = this->autooob; 1581 oobsel = chip->autooob;
1618 autoplace = 1; 1582 autoplace = 1;
1619 } 1583 }
1620 if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR) 1584 if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR)
1621 autoplace = 1; 1585 autoplace = 1;
1622 1586
1623 /* Setup variables and oob buffer */ 1587 /* Setup variables and oob buffer */
1624 totalpages = len >> this->page_shift; 1588 totalpages = len >> chip->page_shift;
1625 page = (int)(to >> this->page_shift); 1589 page = (int)(to >> chip->page_shift);
1626 /* Invalidate the page cache, if we write to the cached page */ 1590 /* Invalidate the page cache, if we write to the cached page */
1627 if (page <= this->pagebuf && this->pagebuf < (page + totalpages)) 1591 if (page <= chip->pagebuf && chip->pagebuf < (page + totalpages))
1628 this->pagebuf = -1; 1592 chip->pagebuf = -1;
1629 1593
1630 /* Set it relative to chip */ 1594 /* Set it relative to chip */
1631 page &= this->pagemask; 1595 page &= chip->pagemask;
1632 startpage = page; 1596 startpage = page;
1633 /* Calc number of pages we can write in one go */ 1597 /* Calc number of pages we can write in one go */
1634 numpages = min(ppblock - (startpage & (ppblock - 1)), totalpages); 1598 numpages = min(ppblock - (startpage & (ppblock - 1)), totalpages);
@@ -1638,13 +1602,13 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1638 /* Loop until all data is written */ 1602 /* Loop until all data is written */
1639 while (written < len) { 1603 while (written < len) {
1640 1604
1641 this->data_poi = (uint8_t *) &buf[written]; 1605 chip->data_poi = (uint8_t *) &buf[written];
1642 /* Write one page. If this is the last page to write 1606 /* Write one page. If this is the last page to write
1643 * or the last page in this block, then use the 1607 * or the last page in this block, then use the
1644 * real pageprogram command, else select cached programming 1608 * real pageprogram command, else select cached programming
1645 * if supported by the chip. 1609 * if supported by the chip.
1646 */ 1610 */
1647 ret = nand_write_page(mtd, this, page, &oobbuf[oob], oobsel, (--numpages > 0)); 1611 ret = nand_write_page(mtd, chip, page, &oobbuf[oob], oobsel, (--numpages > 0));
1648 if (ret) { 1612 if (ret) {
1649 DEBUG(MTD_DEBUG_LEVEL0, "nand_write: write_page failed %d\n", ret); 1613 DEBUG(MTD_DEBUG_LEVEL0, "nand_write: write_page failed %d\n", ret);
1650 goto out; 1614 goto out;
@@ -1665,7 +1629,7 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1665 */ 1629 */
1666 if (!(page & (ppblock - 1))) { 1630 if (!(page & (ppblock - 1))) {
1667 int ofs; 1631 int ofs;
1668 this->data_poi = bufstart; 1632 chip->data_poi = bufstart;
1669 ret = nand_verify_pages(mtd, this, startpage, page - startpage, 1633 ret = nand_verify_pages(mtd, this, startpage, page - startpage,
1670 oobbuf, oobsel, chipnr, (eccbuf != NULL)); 1634 oobbuf, oobsel, chipnr, (eccbuf != NULL));
1671 if (ret) { 1635 if (ret) {
@@ -1679,21 +1643,21 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1679 eccbuf += (page - startpage) * ofs; 1643 eccbuf += (page - startpage) * ofs;
1680 totalpages -= page - startpage; 1644 totalpages -= page - startpage;
1681 numpages = min(totalpages, ppblock); 1645 numpages = min(totalpages, ppblock);
1682 page &= this->pagemask; 1646 page &= chip->pagemask;
1683 startpage = page; 1647 startpage = page;
1684 oobbuf = nand_prepare_oobbuf(mtd, eccbuf, oobsel, autoplace, numpages); 1648 oobbuf = nand_prepare_oobbuf(mtd, eccbuf, oobsel, autoplace, numpages);
1685 oob = 0; 1649 oob = 0;
1686 /* Check, if we cross a chip boundary */ 1650 /* Check, if we cross a chip boundary */
1687 if (!page) { 1651 if (!page) {
1688 chipnr++; 1652 chipnr++;
1689 this->select_chip(mtd, -1); 1653 chip->select_chip(mtd, -1);
1690 this->select_chip(mtd, chipnr); 1654 chip->select_chip(mtd, chipnr);
1691 } 1655 }
1692 } 1656 }
1693 } 1657 }
1694 /* Verify the remaining pages */ 1658 /* Verify the remaining pages */
1695 cmp: 1659 cmp:
1696 this->data_poi = bufstart; 1660 chip->data_poi = bufstart;
1697 ret = nand_verify_pages(mtd, this, startpage, totalpages, oobbuf, oobsel, chipnr, (eccbuf != NULL)); 1661 ret = nand_verify_pages(mtd, this, startpage, totalpages, oobbuf, oobsel, chipnr, (eccbuf != NULL));
1698 if (!ret) 1662 if (!ret)
1699 *retlen = written; 1663 *retlen = written;
@@ -1720,13 +1684,13 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1720static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const uint8_t *buf) 1684static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const uint8_t *buf)
1721{ 1685{
1722 int column, page, status, ret = -EIO, chipnr; 1686 int column, page, status, ret = -EIO, chipnr;
1723 struct nand_chip *this = mtd->priv; 1687 struct nand_chip *chip = mtd->priv;
1724 1688
1725 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", (unsigned int)to, (int)len); 1689 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", (unsigned int)to, (int)len);
1726 1690
1727 /* Shift to get page */ 1691 /* Shift to get page */
1728 page = (int)(to >> this->page_shift); 1692 page = (int)(to >> chip->page_shift);
1729 chipnr = (int)(to >> this->chip_shift); 1693 chipnr = (int)(to >> chip->chip_shift);
1730 1694
1731 /* Mask to get column */ 1695 /* Mask to get column */
1732 column = to & (mtd->oobsize - 1); 1696 column = to & (mtd->oobsize - 1);
@@ -1741,45 +1705,45 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *r
1741 } 1705 }
1742 1706
1743 /* Grab the lock and see if the device is available */ 1707 /* Grab the lock and see if the device is available */
1744 nand_get_device(this, mtd, FL_WRITING); 1708 nand_get_device(chip, mtd, FL_WRITING);
1745 1709
1746 /* Select the NAND device */ 1710 /* Select the NAND device */
1747 this->select_chip(mtd, chipnr); 1711 chip->select_chip(mtd, chipnr);
1748 1712
1749 /* Reset the chip. Some chips (like the Toshiba TC5832DC found 1713 /* Reset the chip. Some chips (like the Toshiba TC5832DC found
1750 in one of my DiskOnChip 2000 test units) will clear the whole 1714 in one of my DiskOnChip 2000 test units) will clear the whole
1751 data page too if we don't do this. I have no clue why, but 1715 data page too if we don't do this. I have no clue why, but
1752 I seem to have 'fixed' it in the doc2000 driver in 1716 I seem to have 'fixed' it in the doc2000 driver in
1753 August 1999. dwmw2. */ 1717 August 1999. dwmw2. */
1754 this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 1718 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
1755 1719
1756 /* Check, if it is write protected */ 1720 /* Check, if it is write protected */
1757 if (nand_check_wp(mtd)) 1721 if (nand_check_wp(mtd))
1758 goto out; 1722 goto out;
1759 1723
1760 /* Invalidate the page cache, if we write to the cached page */ 1724 /* Invalidate the page cache, if we write to the cached page */
1761 if (page == this->pagebuf) 1725 if (page == chip->pagebuf)
1762 this->pagebuf = -1; 1726 chip->pagebuf = -1;
1763 1727
1764 if (NAND_MUST_PAD(this)) { 1728 if (NAND_MUST_PAD(chip)) {
1765 /* Write out desired data */ 1729 /* Write out desired data */
1766 this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page & this->pagemask); 1730 chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page & chip->pagemask);
1767 /* prepad 0xff for partial programming */ 1731 /* prepad 0xff for partial programming */
1768 this->write_buf(mtd, ffchars, column); 1732 chip->write_buf(mtd, ffchars, column);
1769 /* write data */ 1733 /* write data */
1770 this->write_buf(mtd, buf, len); 1734 chip->write_buf(mtd, buf, len);
1771 /* postpad 0xff for partial programming */ 1735 /* postpad 0xff for partial programming */
1772 this->write_buf(mtd, ffchars, mtd->oobsize - (len + column)); 1736 chip->write_buf(mtd, ffchars, mtd->oobsize - (len + column));
1773 } else { 1737 } else {
1774 /* Write out desired data */ 1738 /* Write out desired data */
1775 this->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + column, page & this->pagemask); 1739 chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + column, page & chip->pagemask);
1776 /* write data */ 1740 /* write data */
1777 this->write_buf(mtd, buf, len); 1741 chip->write_buf(mtd, buf, len);
1778 } 1742 }
1779 /* Send command to program the OOB data */ 1743 /* Send command to program the OOB data */
1780 this->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); 1744 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1781 1745
1782 status = this->waitfunc(mtd, this, FL_WRITING); 1746 status = chip->waitfunc(mtd, chip, FL_WRITING);
1783 1747
1784 /* See if device thinks it succeeded */ 1748 /* See if device thinks it succeeded */
1785 if (status & NAND_STATUS_FAIL) { 1749 if (status & NAND_STATUS_FAIL) {
@@ -1792,9 +1756,9 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *r
1792 1756
1793#ifdef CONFIG_MTD_NAND_VERIFY_WRITE 1757#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
1794 /* Send command to read back the data */ 1758 /* Send command to read back the data */
1795 this->cmdfunc(mtd, NAND_CMD_READOOB, column, page & this->pagemask); 1759 chip->cmdfunc(mtd, NAND_CMD_READOOB, column, page & chip->pagemask);
1796 1760
1797 if (this->verify_buf(mtd, buf, len)) { 1761 if (chip->verify_buf(mtd, buf, len)) {
1798 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write verify, page 0x%08x\n", page); 1762 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write verify, page 0x%08x\n", page);
1799 ret = -EIO; 1763 ret = -EIO;
1800 goto out; 1764 goto out;
@@ -1817,10 +1781,10 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, size_t *r
1817 */ 1781 */
1818static void single_erase_cmd(struct mtd_info *mtd, int page) 1782static void single_erase_cmd(struct mtd_info *mtd, int page)
1819{ 1783{
1820 struct nand_chip *this = mtd->priv; 1784 struct nand_chip *chip = mtd->priv;
1821 /* Send commands to erase a block */ 1785 /* Send commands to erase a block */
1822 this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page); 1786 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
1823 this->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1); 1787 chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
1824} 1788}
1825 1789
1826/** 1790/**
@@ -1833,13 +1797,13 @@ static void single_erase_cmd(struct mtd_info *mtd, int page)
1833 */ 1797 */
1834static void multi_erase_cmd(struct mtd_info *mtd, int page) 1798static void multi_erase_cmd(struct mtd_info *mtd, int page)
1835{ 1799{
1836 struct nand_chip *this = mtd->priv; 1800 struct nand_chip *chip = mtd->priv;
1837 /* Send commands to erase a block */ 1801 /* Send commands to erase a block */
1838 this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++); 1802 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++);
1839 this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++); 1803 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++);
1840 this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++); 1804 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page++);
1841 this->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page); 1805 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
1842 this->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1); 1806 chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
1843} 1807}
1844 1808
1845/** 1809/**
@@ -1856,71 +1820,75 @@ static int nand_erase(struct mtd_info *mtd, struct erase_info *instr)
1856 1820
1857#define BBT_PAGE_MASK 0xffffff3f 1821#define BBT_PAGE_MASK 0xffffff3f
1858/** 1822/**
1859 * nand_erase_intern - [NAND Interface] erase block(s) 1823 * nand_erase_nand - [Internal] erase block(s)
1860 * @mtd: MTD device structure 1824 * @mtd: MTD device structure
1861 * @instr: erase instruction 1825 * @instr: erase instruction
1862 * @allowbbt: allow erasing the bbt area 1826 * @allowbbt: allow erasing the bbt area
1863 * 1827 *
1864 * Erase one ore more blocks 1828 * Erase one ore more blocks
1865 */ 1829 */
1866int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, int allowbbt) 1830int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
1831 int allowbbt)
1867{ 1832{
1868 int page, len, status, pages_per_block, ret, chipnr; 1833 int page, len, status, pages_per_block, ret, chipnr;
1869 struct nand_chip *this = mtd->priv; 1834 struct nand_chip *chip = mtd->priv;
1870 int rewrite_bbt[NAND_MAX_CHIPS]={0}; /* flags to indicate the page, if bbt needs to be rewritten. */ 1835 int rewrite_bbt[NAND_MAX_CHIPS]={0};
1871 unsigned int bbt_masked_page; /* bbt mask to compare to page being erased. */ 1836 unsigned int bbt_masked_page = 0xffffffff;
1872 /* It is used to see if the current page is in the same */
1873 /* 256 block group and the same bank as the bbt. */
1874 1837
1875 DEBUG(MTD_DEBUG_LEVEL3, "nand_erase: start = 0x%08x, len = %i\n", (unsigned int)instr->addr, (unsigned int)instr->len); 1838 DEBUG(MTD_DEBUG_LEVEL3, "nand_erase: start = 0x%08x, len = %i\n",
1839 (unsigned int)instr->addr, (unsigned int)instr->len);
1876 1840
1877 /* Start address must align on block boundary */ 1841 /* Start address must align on block boundary */
1878 if (instr->addr & ((1 << this->phys_erase_shift) - 1)) { 1842 if (instr->addr & ((1 << chip->phys_erase_shift) - 1)) {
1879 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Unaligned address\n"); 1843 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Unaligned address\n");
1880 return -EINVAL; 1844 return -EINVAL;
1881 } 1845 }
1882 1846
1883 /* Length must align on block boundary */ 1847 /* Length must align on block boundary */
1884 if (instr->len & ((1 << this->phys_erase_shift) - 1)) { 1848 if (instr->len & ((1 << chip->phys_erase_shift) - 1)) {
1885 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Length not block aligned\n"); 1849 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: "
1850 "Length not block aligned\n");
1886 return -EINVAL; 1851 return -EINVAL;
1887 } 1852 }
1888 1853
1889 /* Do not allow erase past end of device */ 1854 /* Do not allow erase past end of device */
1890 if ((instr->len + instr->addr) > mtd->size) { 1855 if ((instr->len + instr->addr) > mtd->size) {
1891 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Erase past end of device\n"); 1856 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: "
1857 "Erase past end of device\n");
1892 return -EINVAL; 1858 return -EINVAL;
1893 } 1859 }
1894 1860
1895 instr->fail_addr = 0xffffffff; 1861 instr->fail_addr = 0xffffffff;
1896 1862
1897 /* Grab the lock and see if the device is available */ 1863 /* Grab the lock and see if the device is available */
1898 nand_get_device(this, mtd, FL_ERASING); 1864 nand_get_device(chip, mtd, FL_ERASING);
1899 1865
1900 /* Shift to get first page */ 1866 /* Shift to get first page */
1901 page = (int)(instr->addr >> this->page_shift); 1867 page = (int)(instr->addr >> chip->page_shift);
1902 chipnr = (int)(instr->addr >> this->chip_shift); 1868 chipnr = (int)(instr->addr >> chip->chip_shift);
1903 1869
1904 /* Calculate pages in each block */ 1870 /* Calculate pages in each block */
1905 pages_per_block = 1 << (this->phys_erase_shift - this->page_shift); 1871 pages_per_block = 1 << (chip->phys_erase_shift - chip->page_shift);
1906 1872
1907 /* Select the NAND device */ 1873 /* Select the NAND device */
1908 this->select_chip(mtd, chipnr); 1874 chip->select_chip(mtd, chipnr);
1909 1875
1910 /* Check the WP bit */
1911 /* Check, if it is write protected */ 1876 /* Check, if it is write protected */
1912 if (nand_check_wp(mtd)) { 1877 if (nand_check_wp(mtd)) {
1913 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: Device is write protected!!!\n"); 1878 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: "
1879 "Device is write protected!!!\n");
1914 instr->state = MTD_ERASE_FAILED; 1880 instr->state = MTD_ERASE_FAILED;
1915 goto erase_exit; 1881 goto erase_exit;
1916 } 1882 }
1917 1883
1918 /* if BBT requires refresh, set the BBT page mask to see if the BBT should be rewritten */ 1884 /*
1919 if (this->options & BBT_AUTO_REFRESH) { 1885 * If BBT requires refresh, set the BBT page mask to see if the BBT
1920 bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK; 1886 * should be rewritten. Otherwise the mask is set to 0xffffffff which
1921 } else { 1887 * can not be matched. This is also done when the bbt is actually
1922 bbt_masked_page = 0xffffffff; /* should not match anything */ 1888 * erased to avoid recusrsive updates
1923 } 1889 */
1890 if (chip->options & BBT_AUTO_REFRESH && !allowbbt)
1891 bbt_masked_page = chip->bbt_td->pages[chipnr] & BBT_PAGE_MASK;
1924 1892
1925 /* Loop through the pages */ 1893 /* Loop through the pages */
1926 len = instr->len; 1894 len = instr->len;
@@ -1928,59 +1896,72 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, int allowbbt
1928 instr->state = MTD_ERASING; 1896 instr->state = MTD_ERASING;
1929 1897
1930 while (len) { 1898 while (len) {
1931 /* Check if we have a bad block, we do not erase bad blocks ! */ 1899 /*
1932 if (nand_block_checkbad(mtd, ((loff_t) page) << this->page_shift, 0, allowbbt)) { 1900 * heck if we have a bad block, we do not erase bad blocks !
1933 printk(KERN_WARNING "nand_erase: attempt to erase a bad block at page 0x%08x\n", page); 1901 */
1902 if (nand_block_checkbad(mtd, ((loff_t) page) <<
1903 chip->page_shift, 0, allowbbt)) {
1904 printk(KERN_WARNING "nand_erase: attempt to erase a "
1905 "bad block at page 0x%08x\n", page);
1934 instr->state = MTD_ERASE_FAILED; 1906 instr->state = MTD_ERASE_FAILED;
1935 goto erase_exit; 1907 goto erase_exit;
1936 } 1908 }
1937 1909
1938 /* Invalidate the page cache, if we erase the block which contains 1910 /*
1939 the current cached page */ 1911 * Invalidate the page cache, if we erase the block which
1940 if (page <= this->pagebuf && this->pagebuf < (page + pages_per_block)) 1912 * contains the current cached page
1941 this->pagebuf = -1; 1913 */
1914 if (page <= chip->pagebuf && chip->pagebuf <
1915 (page + pages_per_block))
1916 chip->pagebuf = -1;
1942 1917
1943 this->erase_cmd(mtd, page & this->pagemask); 1918 chip->erase_cmd(mtd, page & chip->pagemask);
1944 1919
1945 status = this->waitfunc(mtd, this, FL_ERASING); 1920 status = chip->waitfunc(mtd, chip, FL_ERASING);
1946 1921
1947 /* See if operation failed and additional status checks are available */ 1922 /*
1948 if ((status & NAND_STATUS_FAIL) && (this->errstat)) { 1923 * See if operation failed and additional status checks are
1949 status = this->errstat(mtd, this, FL_ERASING, status, page); 1924 * available
1950 } 1925 */
1926 if ((status & NAND_STATUS_FAIL) && (chip->errstat))
1927 status = chip->errstat(mtd, chip, FL_ERASING,
1928 status, page);
1951 1929
1952 /* See if block erase succeeded */ 1930 /* See if block erase succeeded */
1953 if (status & NAND_STATUS_FAIL) { 1931 if (status & NAND_STATUS_FAIL) {
1954 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: " "Failed erase, page 0x%08x\n", page); 1932 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase: "
1933 "Failed erase, page 0x%08x\n", page);
1955 instr->state = MTD_ERASE_FAILED; 1934 instr->state = MTD_ERASE_FAILED;
1956 instr->fail_addr = (page << this->page_shift); 1935 instr->fail_addr = (page << chip->page_shift);
1957 goto erase_exit; 1936 goto erase_exit;
1958 } 1937 }
1959 1938
1960 /* if BBT requires refresh, set the BBT rewrite flag to the page being erased */ 1939 /*
1961 if (this->options & BBT_AUTO_REFRESH) { 1940 * If BBT requires refresh, set the BBT rewrite flag to the
1962 if (((page & BBT_PAGE_MASK) == bbt_masked_page) && 1941 * page being erased
1963 (page != this->bbt_td->pages[chipnr])) { 1942 */
1964 rewrite_bbt[chipnr] = (page << this->page_shift); 1943 if (bbt_masked_page != 0xffffffff &&
1965 } 1944 (page & BBT_PAGE_MASK) == bbt_masked_page)
1966 } 1945 rewrite_bbt[chipnr] = (page << chip->page_shift);
1967 1946
1968 /* Increment page address and decrement length */ 1947 /* Increment page address and decrement length */
1969 len -= (1 << this->phys_erase_shift); 1948 len -= (1 << chip->phys_erase_shift);
1970 page += pages_per_block; 1949 page += pages_per_block;
1971 1950
1972 /* Check, if we cross a chip boundary */ 1951 /* Check, if we cross a chip boundary */
1973 if (len && !(page & this->pagemask)) { 1952 if (len && !(page & chip->pagemask)) {
1974 chipnr++; 1953 chipnr++;
1975 this->select_chip(mtd, -1); 1954 chip->select_chip(mtd, -1);
1976 this->select_chip(mtd, chipnr); 1955 chip->select_chip(mtd, chipnr);
1977
1978 /* if BBT requires refresh and BBT-PERCHIP,
1979 * set the BBT page mask to see if this BBT should be rewritten */
1980 if ((this->options & BBT_AUTO_REFRESH) && (this->bbt_td->options & NAND_BBT_PERCHIP)) {
1981 bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK;
1982 }
1983 1956
1957 /*
1958 * If BBT requires refresh and BBT-PERCHIP, set the BBT
1959 * page mask to see if this BBT should be rewritten
1960 */
1961 if (bbt_masked_page != 0xffffffff &&
1962 (chip->bbt_td->options & NAND_BBT_PERCHIP))
1963 bbt_masked_page = chip->bbt_td->pages[chipnr] &
1964 BBT_PAGE_MASK;
1984 } 1965 }
1985 } 1966 }
1986 instr->state = MTD_ERASE_DONE; 1967 instr->state = MTD_ERASE_DONE;
@@ -1995,16 +1976,21 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, int allowbbt
1995 /* Deselect and wake up anyone waiting on the device */ 1976 /* Deselect and wake up anyone waiting on the device */
1996 nand_release_device(mtd); 1977 nand_release_device(mtd);
1997 1978
1998 /* if BBT requires refresh and erase was successful, rewrite any selected bad block tables */ 1979 /*
1999 if ((this->options & BBT_AUTO_REFRESH) && (!ret)) { 1980 * If BBT requires refresh and erase was successful, rewrite any
2000 for (chipnr = 0; chipnr < this->numchips; chipnr++) { 1981 * selected bad block tables
2001 if (rewrite_bbt[chipnr]) { 1982 */
2002 /* update the BBT for chip */ 1983 if (bbt_masked_page == 0xffffffff || ret)
2003 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n", 1984 return ret;
2004 chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]); 1985
2005 nand_update_bbt(mtd, rewrite_bbt[chipnr]); 1986 for (chipnr = 0; chipnr < chip->numchips; chipnr++) {
2006 } 1987 if (!rewrite_bbt[chipnr])
2007 } 1988 continue;
1989 /* update the BBT for chip */
1990 DEBUG(MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt "
1991 "(%d:0x%0x 0x%0x)\n", chipnr, rewrite_bbt[chipnr],
1992 chip->bbt_td->pages[chipnr]);
1993 nand_update_bbt(mtd, rewrite_bbt[chipnr]);
2008 } 1994 }
2009 1995
2010 /* Return more or less happy */ 1996 /* Return more or less happy */
@@ -2019,38 +2005,38 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, int allowbbt
2019 */ 2005 */
2020static void nand_sync(struct mtd_info *mtd) 2006static void nand_sync(struct mtd_info *mtd)
2021{ 2007{
2022 struct nand_chip *this = mtd->priv; 2008 struct nand_chip *chip = mtd->priv;
2023 2009
2024 DEBUG(MTD_DEBUG_LEVEL3, "nand_sync: called\n"); 2010 DEBUG(MTD_DEBUG_LEVEL3, "nand_sync: called\n");
2025 2011
2026 /* Grab the lock and see if the device is available */ 2012 /* Grab the lock and see if the device is available */
2027 nand_get_device(this, mtd, FL_SYNCING); 2013 nand_get_device(chip, mtd, FL_SYNCING);
2028 /* Release it and go back */ 2014 /* Release it and go back */
2029 nand_release_device(mtd); 2015 nand_release_device(mtd);
2030} 2016}
2031 2017
2032/** 2018/**
2033 * nand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad 2019 * nand_block_isbad - [MTD Interface] Check if block at offset is bad
2034 * @mtd: MTD device structure 2020 * @mtd: MTD device structure
2035 * @ofs: offset relative to mtd start 2021 * @ofs: offset relative to mtd start
2036 */ 2022 */
2037static int nand_block_isbad(struct mtd_info *mtd, loff_t ofs) 2023static int nand_block_isbad(struct mtd_info *mtd, loff_t offs)
2038{ 2024{
2039 /* Check for invalid offset */ 2025 /* Check for invalid offset */
2040 if (ofs > mtd->size) 2026 if (offs > mtd->size)
2041 return -EINVAL; 2027 return -EINVAL;
2042 2028
2043 return nand_block_checkbad(mtd, ofs, 1, 0); 2029 return nand_block_checkbad(mtd, offs, 1, 0);
2044} 2030}
2045 2031
2046/** 2032/**
2047 * nand_block_markbad - [MTD Interface] Mark the block at the given offset as bad 2033 * nand_block_markbad - [MTD Interface] Mark block at the given offset as bad
2048 * @mtd: MTD device structure 2034 * @mtd: MTD device structure
2049 * @ofs: offset relative to mtd start 2035 * @ofs: offset relative to mtd start
2050 */ 2036 */
2051static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) 2037static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
2052{ 2038{
2053 struct nand_chip *this = mtd->priv; 2039 struct nand_chip *chip = mtd->priv;
2054 int ret; 2040 int ret;
2055 2041
2056 if ((ret = nand_block_isbad(mtd, ofs))) { 2042 if ((ret = nand_block_isbad(mtd, ofs))) {
@@ -2060,7 +2046,7 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
2060 return ret; 2046 return ret;
2061 } 2047 }
2062 2048
2063 return this->block_markbad(mtd, ofs); 2049 return chip->block_markbad(mtd, ofs);
2064} 2050}
2065 2051
2066/** 2052/**
@@ -2069,9 +2055,9 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
2069 */ 2055 */
2070static int nand_suspend(struct mtd_info *mtd) 2056static int nand_suspend(struct mtd_info *mtd)
2071{ 2057{
2072 struct nand_chip *this = mtd->priv; 2058 struct nand_chip *chip = mtd->priv;
2073 2059
2074 return nand_get_device(this, mtd, FL_PM_SUSPENDED); 2060 return nand_get_device(chip, mtd, FL_PM_SUSPENDED);
2075} 2061}
2076 2062
2077/** 2063/**
@@ -2080,9 +2066,9 @@ static int nand_suspend(struct mtd_info *mtd)
2080 */ 2066 */
2081static void nand_resume(struct mtd_info *mtd) 2067static void nand_resume(struct mtd_info *mtd)
2082{ 2068{
2083 struct nand_chip *this = mtd->priv; 2069 struct nand_chip *chip = mtd->priv;
2084 2070
2085 if (this->state == FL_PM_SUSPENDED) 2071 if (chip->state == FL_PM_SUSPENDED)
2086 nand_release_device(mtd); 2072 nand_release_device(mtd);
2087 else 2073 else
2088 printk(KERN_ERR "nand_resume() called for a chip which is not " 2074 printk(KERN_ERR "nand_resume() called for a chip which is not "
@@ -2092,114 +2078,114 @@ static void nand_resume(struct mtd_info *mtd)
2092/* 2078/*
2093 * Free allocated data structures 2079 * Free allocated data structures
2094 */ 2080 */
2095static void nand_free_kmem(struct nand_chip *this) 2081static void nand_free_kmem(struct nand_chip *chip)
2096{ 2082{
2097 /* Buffer allocated by nand_scan ? */ 2083 /* Buffer allocated by nand_scan ? */
2098 if (this->options & NAND_OOBBUF_ALLOC) 2084 if (chip->options & NAND_OOBBUF_ALLOC)
2099 kfree(this->oob_buf); 2085 kfree(chip->oob_buf);
2100 /* Buffer allocated by nand_scan ? */ 2086 /* Buffer allocated by nand_scan ? */
2101 if (this->options & NAND_DATABUF_ALLOC) 2087 if (chip->options & NAND_DATABUF_ALLOC)
2102 kfree(this->data_buf); 2088 kfree(chip->data_buf);
2103 /* Controller allocated by nand_scan ? */ 2089 /* Controller allocated by nand_scan ? */
2104 if (this->options & NAND_CONTROLLER_ALLOC) 2090 if (chip->options & NAND_CONTROLLER_ALLOC)
2105 kfree(this->controller); 2091 kfree(chip->controller);
2106} 2092}
2107 2093
2108/* 2094/*
2109 * Allocate buffers and data structures 2095 * Allocate buffers and data structures
2110 */ 2096 */
2111static int nand_allocate_kmem(struct mtd_info *mtd, struct nand_chip *this) 2097static int nand_allocate_kmem(struct mtd_info *mtd, struct nand_chip *chip)
2112{ 2098{
2113 size_t len; 2099 size_t len;
2114 2100
2115 if (!this->oob_buf) { 2101 if (!chip->oob_buf) {
2116 len = mtd->oobsize << 2102 len = mtd->oobsize <<
2117 (this->phys_erase_shift - this->page_shift); 2103 (chip->phys_erase_shift - chip->page_shift);
2118 this->oob_buf = kmalloc(len, GFP_KERNEL); 2104 chip->oob_buf = kmalloc(len, GFP_KERNEL);
2119 if (!this->oob_buf) 2105 if (!chip->oob_buf)
2120 goto outerr; 2106 goto outerr;
2121 this->options |= NAND_OOBBUF_ALLOC; 2107 chip->options |= NAND_OOBBUF_ALLOC;
2122 } 2108 }
2123 2109
2124 if (!this->data_buf) { 2110 if (!chip->data_buf) {
2125 len = mtd->writesize + mtd->oobsize; 2111 len = mtd->writesize + mtd->oobsize;
2126 this->data_buf = kmalloc(len, GFP_KERNEL); 2112 chip->data_buf = kmalloc(len, GFP_KERNEL);
2127 if (!this->data_buf) 2113 if (!chip->data_buf)
2128 goto outerr; 2114 goto outerr;
2129 this->options |= NAND_DATABUF_ALLOC; 2115 chip->options |= NAND_DATABUF_ALLOC;
2130 } 2116 }
2131 2117
2132 if (!this->controller) { 2118 if (!chip->controller) {
2133 this->controller = kzalloc(sizeof(struct nand_hw_control), 2119 chip->controller = kzalloc(sizeof(struct nand_hw_control),
2134 GFP_KERNEL); 2120 GFP_KERNEL);
2135 if (!this->controller) 2121 if (!chip->controller)
2136 goto outerr; 2122 goto outerr;
2137 this->options |= NAND_CONTROLLER_ALLOC; 2123 chip->options |= NAND_CONTROLLER_ALLOC;
2138 } 2124 }
2139 return 0; 2125 return 0;
2140 2126
2141 outerr: 2127 outerr:
2142 printk(KERN_ERR "nand_scan(): Cannot allocate buffers\n"); 2128 printk(KERN_ERR "nand_scan(): Cannot allocate buffers\n");
2143 nand_free_kmem(this); 2129 nand_free_kmem(chip);
2144 return -ENOMEM; 2130 return -ENOMEM;
2145} 2131}
2146 2132
2147/* 2133/*
2148 * Set default functions 2134 * Set default functions
2149 */ 2135 */
2150static void nand_set_defaults(struct nand_chip *this, int busw) 2136static void nand_set_defaults(struct nand_chip *chip, int busw)
2151{ 2137{
2152 /* check for proper chip_delay setup, set 20us if not */ 2138 /* check for proper chip_delay setup, set 20us if not */
2153 if (!this->chip_delay) 2139 if (!chip->chip_delay)
2154 this->chip_delay = 20; 2140 chip->chip_delay = 20;
2155 2141
2156 /* check, if a user supplied command function given */ 2142 /* check, if a user supplied command function given */
2157 if (this->cmdfunc == NULL) 2143 if (chip->cmdfunc == NULL)
2158 this->cmdfunc = nand_command; 2144 chip->cmdfunc = nand_command;
2159 2145
2160 /* check, if a user supplied wait function given */ 2146 /* check, if a user supplied wait function given */
2161 if (this->waitfunc == NULL) 2147 if (chip->waitfunc == NULL)
2162 this->waitfunc = nand_wait; 2148 chip->waitfunc = nand_wait;
2163 2149
2164 if (!this->select_chip) 2150 if (!chip->select_chip)
2165 this->select_chip = nand_select_chip; 2151 chip->select_chip = nand_select_chip;
2166 if (!this->read_byte) 2152 if (!chip->read_byte)
2167 this->read_byte = busw ? nand_read_byte16 : nand_read_byte; 2153 chip->read_byte = busw ? nand_read_byte16 : nand_read_byte;
2168 if (!this->read_word) 2154 if (!chip->read_word)
2169 this->read_word = nand_read_word; 2155 chip->read_word = nand_read_word;
2170 if (!this->block_bad) 2156 if (!chip->block_bad)
2171 this->block_bad = nand_block_bad; 2157 chip->block_bad = nand_block_bad;
2172 if (!this->block_markbad) 2158 if (!chip->block_markbad)
2173 this->block_markbad = nand_default_block_markbad; 2159 chip->block_markbad = nand_default_block_markbad;
2174 if (!this->write_buf) 2160 if (!chip->write_buf)
2175 this->write_buf = busw ? nand_write_buf16 : nand_write_buf; 2161 chip->write_buf = busw ? nand_write_buf16 : nand_write_buf;
2176 if (!this->read_buf) 2162 if (!chip->read_buf)
2177 this->read_buf = busw ? nand_read_buf16 : nand_read_buf; 2163 chip->read_buf = busw ? nand_read_buf16 : nand_read_buf;
2178 if (!this->verify_buf) 2164 if (!chip->verify_buf)
2179 this->verify_buf = busw ? nand_verify_buf16 : nand_verify_buf; 2165 chip->verify_buf = busw ? nand_verify_buf16 : nand_verify_buf;
2180 if (!this->scan_bbt) 2166 if (!chip->scan_bbt)
2181 this->scan_bbt = nand_default_bbt; 2167 chip->scan_bbt = nand_default_bbt;
2182} 2168}
2183 2169
2184/* 2170/*
2185 * Get the flash and manufacturer id and lookup if the typ is supported 2171 * Get the flash and manufacturer id and lookup if the type is supported
2186 */ 2172 */
2187static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, 2173static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2188 struct nand_chip *this, 2174 struct nand_chip *chip,
2189 int busw, int *maf_id) 2175 int busw, int *maf_id)
2190{ 2176{
2191 struct nand_flash_dev *type = NULL; 2177 struct nand_flash_dev *type = NULL;
2192 int i, dev_id, maf_idx; 2178 int i, dev_id, maf_idx;
2193 2179
2194 /* Select the device */ 2180 /* Select the device */
2195 this->select_chip(mtd, 0); 2181 chip->select_chip(mtd, 0);
2196 2182
2197 /* Send the command for reading device ID */ 2183 /* Send the command for reading device ID */
2198 this->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); 2184 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
2199 2185
2200 /* Read manufacturer and device IDs */ 2186 /* Read manufacturer and device IDs */
2201 *maf_id = this->read_byte(mtd); 2187 *maf_id = chip->read_byte(mtd);
2202 dev_id = this->read_byte(mtd); 2188 dev_id = chip->read_byte(mtd);
2203 2189
2204 /* Lookup the flash id */ 2190 /* Lookup the flash id */
2205 for (i = 0; nand_flash_ids[i].name != NULL; i++) { 2191 for (i = 0; nand_flash_ids[i].name != NULL; i++) {
@@ -2212,15 +2198,15 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2212 if (!type) 2198 if (!type)
2213 return ERR_PTR(-ENODEV); 2199 return ERR_PTR(-ENODEV);
2214 2200
2215 this->chipsize = nand_flash_ids[i].chipsize << 20; 2201 chip->chipsize = nand_flash_ids[i].chipsize << 20;
2216 2202
2217 /* Newer devices have all the information in additional id bytes */ 2203 /* Newer devices have all the information in additional id bytes */
2218 if (!nand_flash_ids[i].pagesize) { 2204 if (!nand_flash_ids[i].pagesize) {
2219 int extid; 2205 int extid;
2220 /* The 3rd id byte contains non relevant data ATM */ 2206 /* The 3rd id byte contains non relevant data ATM */
2221 extid = this->read_byte(mtd); 2207 extid = chip->read_byte(mtd);
2222 /* The 4th id byte is the important one */ 2208 /* The 4th id byte is the important one */
2223 extid = this->read_byte(mtd); 2209 extid = chip->read_byte(mtd);
2224 /* Calc pagesize */ 2210 /* Calc pagesize */
2225 mtd->writesize = 1024 << (extid & 0x3); 2211 mtd->writesize = 1024 << (extid & 0x3);
2226 extid >>= 2; 2212 extid >>= 2;
@@ -2235,7 +2221,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2235 2221
2236 } else { 2222 } else {
2237 /* 2223 /*
2238 * Old devices have this data hardcoded in the device id table 2224 * Old devices have chip data hardcoded in the device id table
2239 */ 2225 */
2240 mtd->erasesize = nand_flash_ids[i].erasesize; 2226 mtd->erasesize = nand_flash_ids[i].erasesize;
2241 mtd->writesize = nand_flash_ids[i].pagesize; 2227 mtd->writesize = nand_flash_ids[i].pagesize;
@@ -2251,55 +2237,55 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2251 2237
2252 /* 2238 /*
2253 * Check, if buswidth is correct. Hardware drivers should set 2239 * Check, if buswidth is correct. Hardware drivers should set
2254 * this correct ! 2240 * chip correct !
2255 */ 2241 */
2256 if (busw != (this->options & NAND_BUSWIDTH_16)) { 2242 if (busw != (chip->options & NAND_BUSWIDTH_16)) {
2257 printk(KERN_INFO "NAND device: Manufacturer ID:" 2243 printk(KERN_INFO "NAND device: Manufacturer ID:"
2258 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id, 2244 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id,
2259 dev_id, nand_manuf_ids[maf_idx].name, mtd->name); 2245 dev_id, nand_manuf_ids[maf_idx].name, mtd->name);
2260 printk(KERN_WARNING "NAND bus width %d instead %d bit\n", 2246 printk(KERN_WARNING "NAND bus width %d instead %d bit\n",
2261 (this->options & NAND_BUSWIDTH_16) ? 16 : 8, 2247 (chip->options & NAND_BUSWIDTH_16) ? 16 : 8,
2262 busw ? 16 : 8); 2248 busw ? 16 : 8);
2263 return ERR_PTR(-EINVAL); 2249 return ERR_PTR(-EINVAL);
2264 } 2250 }
2265 2251
2266 /* Calculate the address shift from the page size */ 2252 /* Calculate the address shift from the page size */
2267 this->page_shift = ffs(mtd->writesize) - 1; 2253 chip->page_shift = ffs(mtd->writesize) - 1;
2268 /* Convert chipsize to number of pages per chip -1. */ 2254 /* Convert chipsize to number of pages per chip -1. */
2269 this->pagemask = (this->chipsize >> this->page_shift) - 1; 2255 chip->pagemask = (chip->chipsize >> chip->page_shift) - 1;
2270 2256
2271 this->bbt_erase_shift = this->phys_erase_shift = 2257 chip->bbt_erase_shift = chip->phys_erase_shift =
2272 ffs(mtd->erasesize) - 1; 2258 ffs(mtd->erasesize) - 1;
2273 this->chip_shift = ffs(this->chipsize) - 1; 2259 chip->chip_shift = ffs(chip->chipsize) - 1;
2274 2260
2275 /* Set the bad block position */ 2261 /* Set the bad block position */
2276 this->badblockpos = mtd->writesize > 512 ? 2262 chip->badblockpos = mtd->writesize > 512 ?
2277 NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS; 2263 NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
2278 2264
2279 /* Get chip options, preserve non chip based options */ 2265 /* Get chip options, preserve non chip based options */
2280 this->options &= ~NAND_CHIPOPTIONS_MSK; 2266 chip->options &= ~NAND_CHIPOPTIONS_MSK;
2281 this->options |= nand_flash_ids[i].options & NAND_CHIPOPTIONS_MSK; 2267 chip->options |= nand_flash_ids[i].options & NAND_CHIPOPTIONS_MSK;
2282 2268
2283 /* 2269 /*
2284 * Set this as a default. Board drivers can override it, if necessary 2270 * Set chip as a default. Board drivers can override it, if necessary
2285 */ 2271 */
2286 this->options |= NAND_NO_AUTOINCR; 2272 chip->options |= NAND_NO_AUTOINCR;
2287 2273
2288 /* Check if this is a not a samsung device. Do not clear the 2274 /* Check if chip is a not a samsung device. Do not clear the
2289 * options for chips which are not having an extended id. 2275 * options for chips which are not having an extended id.
2290 */ 2276 */
2291 if (*maf_id != NAND_MFR_SAMSUNG && !nand_flash_ids[i].pagesize) 2277 if (*maf_id != NAND_MFR_SAMSUNG && !nand_flash_ids[i].pagesize)
2292 this->options &= ~NAND_SAMSUNG_LP_OPTIONS; 2278 chip->options &= ~NAND_SAMSUNG_LP_OPTIONS;
2293 2279
2294 /* Check for AND chips with 4 page planes */ 2280 /* Check for AND chips with 4 page planes */
2295 if (this->options & NAND_4PAGE_ARRAY) 2281 if (chip->options & NAND_4PAGE_ARRAY)
2296 this->erase_cmd = multi_erase_cmd; 2282 chip->erase_cmd = multi_erase_cmd;
2297 else 2283 else
2298 this->erase_cmd = single_erase_cmd; 2284 chip->erase_cmd = single_erase_cmd;
2299 2285
2300 /* Do not replace user supplied command function ! */ 2286 /* Do not replace user supplied command function ! */
2301 if (mtd->writesize > 512 && this->cmdfunc == nand_command) 2287 if (mtd->writesize > 512 && chip->cmdfunc == nand_command)
2302 this->cmdfunc = nand_command_lp; 2288 chip->cmdfunc = nand_command_lp;
2303 2289
2304 printk(KERN_INFO "NAND device: Manufacturer ID:" 2290 printk(KERN_INFO "NAND device: Manufacturer ID:"
2305 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id, dev_id, 2291 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id, dev_id,
@@ -2334,7 +2320,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2334int nand_scan(struct mtd_info *mtd, int maxchips) 2320int nand_scan(struct mtd_info *mtd, int maxchips)
2335{ 2321{
2336 int i, busw, nand_maf_id; 2322 int i, busw, nand_maf_id;
2337 struct nand_chip *this = mtd->priv; 2323 struct nand_chip *chip = mtd->priv;
2338 struct nand_flash_dev *type; 2324 struct nand_flash_dev *type;
2339 2325
2340 /* Many callers got this wrong, so check for it for a while... */ 2326 /* Many callers got this wrong, so check for it for a while... */
@@ -2344,57 +2330,57 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
2344 } 2330 }
2345 2331
2346 /* Get buswidth to select the correct functions */ 2332 /* Get buswidth to select the correct functions */
2347 busw = this->options & NAND_BUSWIDTH_16; 2333 busw = chip->options & NAND_BUSWIDTH_16;
2348 /* Set the default functions */ 2334 /* Set the default functions */
2349 nand_set_defaults(this, busw); 2335 nand_set_defaults(chip, busw);
2350 2336
2351 /* Read the flash type */ 2337 /* Read the flash type */
2352 type = nand_get_flash_type(mtd, this, busw, &nand_maf_id); 2338 type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id);
2353 2339
2354 if (IS_ERR(type)) { 2340 if (IS_ERR(type)) {
2355 printk(KERN_WARNING "No NAND device found!!!\n"); 2341 printk(KERN_WARNING "No NAND device found!!!\n");
2356 this->select_chip(mtd, -1); 2342 chip->select_chip(mtd, -1);
2357 return PTR_ERR(type); 2343 return PTR_ERR(type);
2358 } 2344 }
2359 2345
2360 /* Check for a chip array */ 2346 /* Check for a chip array */
2361 for (i = 1; i < maxchips; i++) { 2347 for (i = 1; i < maxchips; i++) {
2362 this->select_chip(mtd, i); 2348 chip->select_chip(mtd, i);
2363 /* Send the command for reading device ID */ 2349 /* Send the command for reading device ID */
2364 this->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); 2350 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
2365 /* Read manufacturer and device IDs */ 2351 /* Read manufacturer and device IDs */
2366 if (nand_maf_id != this->read_byte(mtd) || 2352 if (nand_maf_id != chip->read_byte(mtd) ||
2367 type->id != this->read_byte(mtd)) 2353 type->id != chip->read_byte(mtd))
2368 break; 2354 break;
2369 } 2355 }
2370 if (i > 1) 2356 if (i > 1)
2371 printk(KERN_INFO "%d NAND chips detected\n", i); 2357 printk(KERN_INFO "%d NAND chips detected\n", i);
2372 2358
2373 /* Store the number of chips and calc total size for mtd */ 2359 /* Store the number of chips and calc total size for mtd */
2374 this->numchips = i; 2360 chip->numchips = i;
2375 mtd->size = i * this->chipsize; 2361 mtd->size = i * chip->chipsize;
2376 2362
2377 /* Allocate buffers and data structures */ 2363 /* Allocate buffers and data structures */
2378 if (nand_allocate_kmem(mtd, this)) 2364 if (nand_allocate_kmem(mtd, chip))
2379 return -ENOMEM; 2365 return -ENOMEM;
2380 2366
2381 /* Preset the internal oob buffer */ 2367 /* Preset the internal oob buffer */
2382 memset(this->oob_buf, 0xff, 2368 memset(chip->oob_buf, 0xff,
2383 mtd->oobsize << (this->phys_erase_shift - this->page_shift)); 2369 mtd->oobsize << (chip->phys_erase_shift - chip->page_shift));
2384 2370
2385 /* 2371 /*
2386 * If no default placement scheme is given, select an appropriate one 2372 * If no default placement scheme is given, select an appropriate one
2387 */ 2373 */
2388 if (!this->autooob) { 2374 if (!chip->autooob) {
2389 switch (mtd->oobsize) { 2375 switch (mtd->oobsize) {
2390 case 8: 2376 case 8:
2391 this->autooob = &nand_oob_8; 2377 chip->autooob = &nand_oob_8;
2392 break; 2378 break;
2393 case 16: 2379 case 16:
2394 this->autooob = &nand_oob_16; 2380 chip->autooob = &nand_oob_16;
2395 break; 2381 break;
2396 case 64: 2382 case 64:
2397 this->autooob = &nand_oob_64; 2383 chip->autooob = &nand_oob_64;
2398 break; 2384 break;
2399 default: 2385 default:
2400 printk(KERN_WARNING "No oob scheme defined for " 2386 printk(KERN_WARNING "No oob scheme defined for "
@@ -2408,45 +2394,45 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
2408 * dependend oob data 2394 * dependend oob data
2409 */ 2395 */
2410 mtd->oobavail = 0; 2396 mtd->oobavail = 0;
2411 for (i = 0; this->autooob->oobfree[i][1]; i++) 2397 for (i = 0; chip->autooob->oobfree[i][1]; i++)
2412 mtd->oobavail += this->autooob->oobfree[i][1]; 2398 mtd->oobavail += chip->autooob->oobfree[i][1];
2413 2399
2414 /* 2400 /*
2415 * check ECC mode, default to software if 3byte/512byte hardware ECC is 2401 * check ECC mode, default to software if 3byte/512byte hardware ECC is
2416 * selected and we have 256 byte pagesize fallback to software ECC 2402 * selected and we have 256 byte pagesize fallback to software ECC
2417 */ 2403 */
2418 switch (this->ecc.mode) { 2404 switch (chip->ecc.mode) {
2419 case NAND_ECC_HW: 2405 case NAND_ECC_HW:
2420 case NAND_ECC_HW_SYNDROME: 2406 case NAND_ECC_HW_SYNDROME:
2421 if (!this->ecc.calculate || !this->ecc.correct || 2407 if (!chip->ecc.calculate || !chip->ecc.correct ||
2422 !this->ecc.hwctl) { 2408 !chip->ecc.hwctl) {
2423 printk(KERN_WARNING "No ECC functions supplied, " 2409 printk(KERN_WARNING "No ECC functions supplied, "
2424 "Hardware ECC not possible\n"); 2410 "Hardware ECC not possible\n");
2425 BUG(); 2411 BUG();
2426 } 2412 }
2427 if (mtd->writesize >= this->ecc.size) 2413 if (mtd->writesize >= chip->ecc.size)
2428 break; 2414 break;
2429 printk(KERN_WARNING "%d byte HW ECC not possible on " 2415 printk(KERN_WARNING "%d byte HW ECC not possible on "
2430 "%d byte page size, fallback to SW ECC\n", 2416 "%d byte page size, fallback to SW ECC\n",
2431 this->ecc.size, mtd->writesize); 2417 chip->ecc.size, mtd->writesize);
2432 this->ecc.mode = NAND_ECC_SOFT; 2418 chip->ecc.mode = NAND_ECC_SOFT;
2433 2419
2434 case NAND_ECC_SOFT: 2420 case NAND_ECC_SOFT:
2435 this->ecc.calculate = nand_calculate_ecc; 2421 chip->ecc.calculate = nand_calculate_ecc;
2436 this->ecc.correct = nand_correct_data; 2422 chip->ecc.correct = nand_correct_data;
2437 this->ecc.size = 256; 2423 chip->ecc.size = 256;
2438 this->ecc.bytes = 3; 2424 chip->ecc.bytes = 3;
2439 break; 2425 break;
2440 2426
2441 case NAND_ECC_NONE: 2427 case NAND_ECC_NONE:
2442 printk(KERN_WARNING "NAND_ECC_NONE selected by board driver. " 2428 printk(KERN_WARNING "NAND_ECC_NONE selected by board driver. "
2443 "This is not recommended !!\n"); 2429 "This is not recommended !!\n");
2444 this->ecc.size = mtd->writesize; 2430 chip->ecc.size = mtd->writesize;
2445 this->ecc.bytes = 0; 2431 chip->ecc.bytes = 0;
2446 break; 2432 break;
2447 default: 2433 default:
2448 printk(KERN_WARNING "Invalid NAND_ECC_MODE %d\n", 2434 printk(KERN_WARNING "Invalid NAND_ECC_MODE %d\n",
2449 this->ecc.mode); 2435 chip->ecc.mode);
2450 BUG(); 2436 BUG();
2451 } 2437 }
2452 2438
@@ -2454,22 +2440,22 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
2454 * Set the number of read / write steps for one page depending on ECC 2440 * Set the number of read / write steps for one page depending on ECC
2455 * mode 2441 * mode
2456 */ 2442 */
2457 this->ecc.steps = mtd->writesize / this->ecc.size; 2443 chip->ecc.steps = mtd->writesize / chip->ecc.size;
2458 if(this->ecc.steps * this->ecc.size != mtd->writesize) { 2444 if(chip->ecc.steps * chip->ecc.size != mtd->writesize) {
2459 printk(KERN_WARNING "Invalid ecc parameters\n"); 2445 printk(KERN_WARNING "Invalid ecc parameters\n");
2460 BUG(); 2446 BUG();
2461 } 2447 }
2462 2448
2463 /* Initialize state, waitqueue and spinlock */ 2449 /* Initialize state, waitqueue and spinlock */
2464 this->state = FL_READY; 2450 chip->state = FL_READY;
2465 init_waitqueue_head(&this->controller->wq); 2451 init_waitqueue_head(&chip->controller->wq);
2466 spin_lock_init(&this->controller->lock); 2452 spin_lock_init(&chip->controller->lock);
2467 2453
2468 /* De-select the device */ 2454 /* De-select the device */
2469 this->select_chip(mtd, -1); 2455 chip->select_chip(mtd, -1);
2470 2456
2471 /* Invalidate the pagebuffer reference */ 2457 /* Invalidate the pagebuffer reference */
2472 this->pagebuf = -1; 2458 chip->pagebuf = -1;
2473 2459
2474 /* Fill in remaining MTD driver data */ 2460 /* Fill in remaining MTD driver data */
2475 mtd->type = MTD_NANDFLASH; 2461 mtd->type = MTD_NANDFLASH;
@@ -2491,14 +2477,14 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
2491 mtd->block_markbad = nand_block_markbad; 2477 mtd->block_markbad = nand_block_markbad;
2492 2478
2493 /* and make the autooob the default one */ 2479 /* and make the autooob the default one */
2494 memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo)); 2480 memcpy(&mtd->oobinfo, chip->autooob, sizeof(mtd->oobinfo));
2495 2481
2496 /* Check, if we should skip the bad block table scan */ 2482 /* Check, if we should skip the bad block table scan */
2497 if (this->options & NAND_SKIP_BBTSCAN) 2483 if (chip->options & NAND_SKIP_BBTSCAN)
2498 return 0; 2484 return 0;
2499 2485
2500 /* Build bad block table */ 2486 /* Build bad block table */
2501 return this->scan_bbt(mtd); 2487 return chip->scan_bbt(mtd);
2502} 2488}
2503 2489
2504/** 2490/**
@@ -2507,7 +2493,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
2507*/ 2493*/
2508void nand_release(struct mtd_info *mtd) 2494void nand_release(struct mtd_info *mtd)
2509{ 2495{
2510 struct nand_chip *this = mtd->priv; 2496 struct nand_chip *chip = mtd->priv;
2511 2497
2512#ifdef CONFIG_MTD_PARTITIONS 2498#ifdef CONFIG_MTD_PARTITIONS
2513 /* Deregister partitions */ 2499 /* Deregister partitions */
@@ -2517,9 +2503,9 @@ void nand_release(struct mtd_info *mtd)
2517 del_mtd_device(mtd); 2503 del_mtd_device(mtd);
2518 2504
2519 /* Free bad block table memory */ 2505 /* Free bad block table memory */
2520 kfree(this->bbt); 2506 kfree(chip->bbt);
2521 /* Free buffers */ 2507 /* Free buffers */
2522 nand_free_kmem(this); 2508 nand_free_kmem(chip);
2523} 2509}
2524 2510
2525EXPORT_SYMBOL_GPL(nand_scan); 2511EXPORT_SYMBOL_GPL(nand_scan);