| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * (C) 2003 Red Hat, Inc. |
|---|
| 3 | 4 | * (C) 2004 Dan Brown <dan_brown@ieee.org> |
|---|
| .. | .. |
|---|
| 57 | 58 | static struct mtd_info *doclist = NULL; |
|---|
| 58 | 59 | |
|---|
| 59 | 60 | struct doc_priv { |
|---|
| 61 | + struct nand_controller base; |
|---|
| 60 | 62 | void __iomem *virtadr; |
|---|
| 61 | 63 | unsigned long physadr; |
|---|
| 62 | 64 | u_char ChipID; |
|---|
| .. | .. |
|---|
| 68 | 70 | int mh1_page; |
|---|
| 69 | 71 | struct rs_control *rs_decoder; |
|---|
| 70 | 72 | struct mtd_info *nextdoc; |
|---|
| 73 | + bool supports_32b_reads; |
|---|
| 71 | 74 | |
|---|
| 72 | 75 | /* Handle the last stage of initialization (BBT scan, partitioning) */ |
|---|
| 73 | 76 | int (*late_init)(struct mtd_info *mtd); |
|---|
| .. | .. |
|---|
| 82 | 85 | #define DoC_is_MillenniumPlus(doc) ((doc)->ChipID == DOC_ChipID_DocMilPlus16 || (doc)->ChipID == DOC_ChipID_DocMilPlus32) |
|---|
| 83 | 86 | #define DoC_is_Millennium(doc) ((doc)->ChipID == DOC_ChipID_DocMil) |
|---|
| 84 | 87 | #define DoC_is_2000(doc) ((doc)->ChipID == DOC_ChipID_Doc2k) |
|---|
| 85 | | - |
|---|
| 86 | | -static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd, |
|---|
| 87 | | - unsigned int bitmask); |
|---|
| 88 | | -static void doc200x_select_chip(struct mtd_info *mtd, int chip); |
|---|
| 89 | 88 | |
|---|
| 90 | 89 | static int debug = 0; |
|---|
| 91 | 90 | module_param(debug, int, 0); |
|---|
| .. | .. |
|---|
| 290 | 289 | return ret; |
|---|
| 291 | 290 | } |
|---|
| 292 | 291 | |
|---|
| 293 | | -static void doc2000_write_byte(struct mtd_info *mtd, u_char datum) |
|---|
| 292 | +static void doc2000_write_byte(struct nand_chip *this, u_char datum) |
|---|
| 294 | 293 | { |
|---|
| 295 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 296 | 294 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 297 | 295 | void __iomem *docptr = doc->virtadr; |
|---|
| 298 | 296 | |
|---|
| .. | .. |
|---|
| 302 | 300 | WriteDOC(datum, docptr, 2k_CDSN_IO); |
|---|
| 303 | 301 | } |
|---|
| 304 | 302 | |
|---|
| 305 | | -static u_char doc2000_read_byte(struct mtd_info *mtd) |
|---|
| 303 | +static void doc2000_writebuf(struct nand_chip *this, const u_char *buf, |
|---|
| 304 | + int len) |
|---|
| 306 | 305 | { |
|---|
| 307 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 308 | | - struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 309 | | - void __iomem *docptr = doc->virtadr; |
|---|
| 310 | | - u_char ret; |
|---|
| 311 | | - |
|---|
| 312 | | - ReadDOC(docptr, CDSNSlowIO); |
|---|
| 313 | | - DoC_Delay(doc, 2); |
|---|
| 314 | | - ret = ReadDOC(docptr, 2k_CDSN_IO); |
|---|
| 315 | | - if (debug) |
|---|
| 316 | | - printk("read_byte returns %02x\n", ret); |
|---|
| 317 | | - return ret; |
|---|
| 318 | | -} |
|---|
| 319 | | - |
|---|
| 320 | | -static void doc2000_writebuf(struct mtd_info *mtd, const u_char *buf, int len) |
|---|
| 321 | | -{ |
|---|
| 322 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 323 | 306 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 324 | 307 | void __iomem *docptr = doc->virtadr; |
|---|
| 325 | 308 | int i; |
|---|
| .. | .. |
|---|
| 334 | 317 | printk("\n"); |
|---|
| 335 | 318 | } |
|---|
| 336 | 319 | |
|---|
| 337 | | -static void doc2000_readbuf(struct mtd_info *mtd, u_char *buf, int len) |
|---|
| 320 | +static void doc2000_readbuf(struct nand_chip *this, u_char *buf, int len) |
|---|
| 338 | 321 | { |
|---|
| 339 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 340 | 322 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 341 | 323 | void __iomem *docptr = doc->virtadr; |
|---|
| 324 | + u32 *buf32 = (u32 *)buf; |
|---|
| 342 | 325 | int i; |
|---|
| 343 | 326 | |
|---|
| 344 | 327 | if (debug) |
|---|
| 345 | 328 | printk("readbuf of %d bytes: ", len); |
|---|
| 346 | 329 | |
|---|
| 347 | | - for (i = 0; i < len; i++) { |
|---|
| 348 | | - buf[i] = ReadDOC(docptr, 2k_CDSN_IO + i); |
|---|
| 330 | + if (!doc->supports_32b_reads || |
|---|
| 331 | + ((((unsigned long)buf) | len) & 3)) { |
|---|
| 332 | + for (i = 0; i < len; i++) |
|---|
| 333 | + buf[i] = ReadDOC(docptr, 2k_CDSN_IO + i); |
|---|
| 334 | + } else { |
|---|
| 335 | + for (i = 0; i < len / 4; i++) |
|---|
| 336 | + buf32[i] = readl(docptr + DoC_2k_CDSN_IO + i); |
|---|
| 349 | 337 | } |
|---|
| 350 | 338 | } |
|---|
| 351 | 339 | |
|---|
| 352 | | -static void doc2000_readbuf_dword(struct mtd_info *mtd, u_char *buf, int len) |
|---|
| 340 | +/* |
|---|
| 341 | + * We need our own readid() here because it's called before the NAND chip |
|---|
| 342 | + * has been initialized, and calling nand_op_readid() would lead to a NULL |
|---|
| 343 | + * pointer exception when dereferencing the NAND timings. |
|---|
| 344 | + */ |
|---|
| 345 | +static void doc200x_readid(struct nand_chip *this, unsigned int cs, u8 *id) |
|---|
| 353 | 346 | { |
|---|
| 354 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 355 | | - struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 356 | | - void __iomem *docptr = doc->virtadr; |
|---|
| 357 | | - int i; |
|---|
| 347 | + u8 addr = 0; |
|---|
| 348 | + struct nand_op_instr instrs[] = { |
|---|
| 349 | + NAND_OP_CMD(NAND_CMD_READID, 0), |
|---|
| 350 | + NAND_OP_ADDR(1, &addr, 50), |
|---|
| 351 | + NAND_OP_8BIT_DATA_IN(2, id, 0), |
|---|
| 352 | + }; |
|---|
| 358 | 353 | |
|---|
| 359 | | - if (debug) |
|---|
| 360 | | - printk("readbuf_dword of %d bytes: ", len); |
|---|
| 354 | + struct nand_operation op = NAND_OPERATION(cs, instrs); |
|---|
| 361 | 355 | |
|---|
| 362 | | - if (unlikely((((unsigned long)buf) | len) & 3)) { |
|---|
| 363 | | - for (i = 0; i < len; i++) { |
|---|
| 364 | | - *(uint8_t *) (&buf[i]) = ReadDOC(docptr, 2k_CDSN_IO + i); |
|---|
| 365 | | - } |
|---|
| 366 | | - } else { |
|---|
| 367 | | - for (i = 0; i < len; i += 4) { |
|---|
| 368 | | - *(uint32_t *) (&buf[i]) = readl(docptr + DoC_2k_CDSN_IO + i); |
|---|
| 369 | | - } |
|---|
| 370 | | - } |
|---|
| 356 | + if (!id) |
|---|
| 357 | + op.ninstrs--; |
|---|
| 358 | + |
|---|
| 359 | + this->controller->ops->exec_op(this, &op, false); |
|---|
| 371 | 360 | } |
|---|
| 372 | 361 | |
|---|
| 373 | 362 | static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr) |
|---|
| .. | .. |
|---|
| 375 | 364 | struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 376 | 365 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 377 | 366 | uint16_t ret; |
|---|
| 367 | + u8 id[2]; |
|---|
| 378 | 368 | |
|---|
| 379 | | - doc200x_select_chip(mtd, nr); |
|---|
| 380 | | - doc200x_hwcontrol(mtd, NAND_CMD_READID, |
|---|
| 381 | | - NAND_CTRL_CLE | NAND_CTRL_CHANGE); |
|---|
| 382 | | - doc200x_hwcontrol(mtd, 0, NAND_CTRL_ALE | NAND_CTRL_CHANGE); |
|---|
| 383 | | - doc200x_hwcontrol(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); |
|---|
| 369 | + doc200x_readid(this, nr, id); |
|---|
| 384 | 370 | |
|---|
| 385 | | - /* We can't use dev_ready here, but at least we wait for the |
|---|
| 386 | | - * command to complete |
|---|
| 387 | | - */ |
|---|
| 388 | | - udelay(50); |
|---|
| 389 | | - |
|---|
| 390 | | - ret = this->read_byte(mtd) << 8; |
|---|
| 391 | | - ret |= this->read_byte(mtd); |
|---|
| 371 | + ret = ((u16)id[0] << 8) | id[1]; |
|---|
| 392 | 372 | |
|---|
| 393 | 373 | if (doc->ChipID == DOC_ChipID_Doc2k && try_dword && !nr) { |
|---|
| 394 | 374 | /* First chip probe. See if we get same results by 32-bit access */ |
|---|
| .. | .. |
|---|
| 398 | 378 | } ident; |
|---|
| 399 | 379 | void __iomem *docptr = doc->virtadr; |
|---|
| 400 | 380 | |
|---|
| 401 | | - doc200x_hwcontrol(mtd, NAND_CMD_READID, |
|---|
| 402 | | - NAND_CTRL_CLE | NAND_CTRL_CHANGE); |
|---|
| 403 | | - doc200x_hwcontrol(mtd, 0, NAND_CTRL_ALE | NAND_CTRL_CHANGE); |
|---|
| 404 | | - doc200x_hwcontrol(mtd, NAND_CMD_NONE, |
|---|
| 405 | | - NAND_NCE | NAND_CTRL_CHANGE); |
|---|
| 406 | | - |
|---|
| 407 | | - udelay(50); |
|---|
| 381 | + doc200x_readid(this, nr, NULL); |
|---|
| 408 | 382 | |
|---|
| 409 | 383 | ident.dword = readl(docptr + DoC_2k_CDSN_IO); |
|---|
| 410 | 384 | if (((ident.byte[0] << 8) | ident.byte[1]) == ret) { |
|---|
| 411 | 385 | pr_info("DiskOnChip 2000 responds to DWORD access\n"); |
|---|
| 412 | | - this->read_buf = &doc2000_readbuf_dword; |
|---|
| 386 | + doc->supports_32b_reads = true; |
|---|
| 413 | 387 | } |
|---|
| 414 | 388 | } |
|---|
| 415 | 389 | |
|---|
| .. | .. |
|---|
| 438 | 412 | pr_debug("Detected %d chips per floor.\n", i); |
|---|
| 439 | 413 | } |
|---|
| 440 | 414 | |
|---|
| 441 | | -static int doc200x_wait(struct mtd_info *mtd, struct nand_chip *this) |
|---|
| 415 | +static void doc2001_write_byte(struct nand_chip *this, u_char datum) |
|---|
| 442 | 416 | { |
|---|
| 443 | | - struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 444 | | - |
|---|
| 445 | | - int status; |
|---|
| 446 | | - |
|---|
| 447 | | - DoC_WaitReady(doc); |
|---|
| 448 | | - nand_status_op(this, NULL); |
|---|
| 449 | | - DoC_WaitReady(doc); |
|---|
| 450 | | - status = (int)this->read_byte(mtd); |
|---|
| 451 | | - |
|---|
| 452 | | - return status; |
|---|
| 453 | | -} |
|---|
| 454 | | - |
|---|
| 455 | | -static void doc2001_write_byte(struct mtd_info *mtd, u_char datum) |
|---|
| 456 | | -{ |
|---|
| 457 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 458 | 417 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 459 | 418 | void __iomem *docptr = doc->virtadr; |
|---|
| 460 | 419 | |
|---|
| .. | .. |
|---|
| 463 | 422 | WriteDOC(datum, docptr, WritePipeTerm); |
|---|
| 464 | 423 | } |
|---|
| 465 | 424 | |
|---|
| 466 | | -static u_char doc2001_read_byte(struct mtd_info *mtd) |
|---|
| 425 | +static void doc2001_writebuf(struct nand_chip *this, const u_char *buf, int len) |
|---|
| 467 | 426 | { |
|---|
| 468 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 469 | | - struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 470 | | - void __iomem *docptr = doc->virtadr; |
|---|
| 471 | | - |
|---|
| 472 | | - //ReadDOC(docptr, CDSNSlowIO); |
|---|
| 473 | | - /* 11.4.5 -- delay twice to allow extended length cycle */ |
|---|
| 474 | | - DoC_Delay(doc, 2); |
|---|
| 475 | | - ReadDOC(docptr, ReadPipeInit); |
|---|
| 476 | | - //return ReadDOC(docptr, Mil_CDSN_IO); |
|---|
| 477 | | - return ReadDOC(docptr, LastDataRead); |
|---|
| 478 | | -} |
|---|
| 479 | | - |
|---|
| 480 | | -static void doc2001_writebuf(struct mtd_info *mtd, const u_char *buf, int len) |
|---|
| 481 | | -{ |
|---|
| 482 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 483 | 427 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 484 | 428 | void __iomem *docptr = doc->virtadr; |
|---|
| 485 | 429 | int i; |
|---|
| .. | .. |
|---|
| 490 | 434 | WriteDOC(0x00, docptr, WritePipeTerm); |
|---|
| 491 | 435 | } |
|---|
| 492 | 436 | |
|---|
| 493 | | -static void doc2001_readbuf(struct mtd_info *mtd, u_char *buf, int len) |
|---|
| 437 | +static void doc2001_readbuf(struct nand_chip *this, u_char *buf, int len) |
|---|
| 494 | 438 | { |
|---|
| 495 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 496 | 439 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 497 | 440 | void __iomem *docptr = doc->virtadr; |
|---|
| 498 | 441 | int i; |
|---|
| .. | .. |
|---|
| 507 | 450 | buf[i] = ReadDOC(docptr, LastDataRead); |
|---|
| 508 | 451 | } |
|---|
| 509 | 452 | |
|---|
| 510 | | -static u_char doc2001plus_read_byte(struct mtd_info *mtd) |
|---|
| 453 | +static void doc2001plus_writebuf(struct nand_chip *this, const u_char *buf, int len) |
|---|
| 511 | 454 | { |
|---|
| 512 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 513 | | - struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 514 | | - void __iomem *docptr = doc->virtadr; |
|---|
| 515 | | - u_char ret; |
|---|
| 516 | | - |
|---|
| 517 | | - ReadDOC(docptr, Mplus_ReadPipeInit); |
|---|
| 518 | | - ReadDOC(docptr, Mplus_ReadPipeInit); |
|---|
| 519 | | - ret = ReadDOC(docptr, Mplus_LastDataRead); |
|---|
| 520 | | - if (debug) |
|---|
| 521 | | - printk("read_byte returns %02x\n", ret); |
|---|
| 522 | | - return ret; |
|---|
| 523 | | -} |
|---|
| 524 | | - |
|---|
| 525 | | -static void doc2001plus_writebuf(struct mtd_info *mtd, const u_char *buf, int len) |
|---|
| 526 | | -{ |
|---|
| 527 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 528 | 455 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 529 | 456 | void __iomem *docptr = doc->virtadr; |
|---|
| 530 | 457 | int i; |
|---|
| .. | .. |
|---|
| 540 | 467 | printk("\n"); |
|---|
| 541 | 468 | } |
|---|
| 542 | 469 | |
|---|
| 543 | | -static void doc2001plus_readbuf(struct mtd_info *mtd, u_char *buf, int len) |
|---|
| 470 | +static void doc2001plus_readbuf(struct nand_chip *this, u_char *buf, int len) |
|---|
| 544 | 471 | { |
|---|
| 545 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 546 | 472 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 547 | 473 | void __iomem *docptr = doc->virtadr; |
|---|
| 548 | 474 | int i; |
|---|
| .. | .. |
|---|
| 561 | 487 | } |
|---|
| 562 | 488 | |
|---|
| 563 | 489 | /* Terminate read pipeline */ |
|---|
| 564 | | - buf[len - 2] = ReadDOC(docptr, Mplus_LastDataRead); |
|---|
| 565 | | - if (debug && i < 16) |
|---|
| 566 | | - printk("%02x ", buf[len - 2]); |
|---|
| 490 | + if (len >= 2) { |
|---|
| 491 | + buf[len - 2] = ReadDOC(docptr, Mplus_LastDataRead); |
|---|
| 492 | + if (debug && i < 16) |
|---|
| 493 | + printk("%02x ", buf[len - 2]); |
|---|
| 494 | + } |
|---|
| 495 | + |
|---|
| 567 | 496 | buf[len - 1] = ReadDOC(docptr, Mplus_LastDataRead); |
|---|
| 568 | 497 | if (debug && i < 16) |
|---|
| 569 | 498 | printk("%02x ", buf[len - 1]); |
|---|
| .. | .. |
|---|
| 571 | 500 | printk("\n"); |
|---|
| 572 | 501 | } |
|---|
| 573 | 502 | |
|---|
| 574 | | -static void doc2001plus_select_chip(struct mtd_info *mtd, int chip) |
|---|
| 503 | +static void doc200x_write_control(struct doc_priv *doc, u8 value) |
|---|
| 575 | 504 | { |
|---|
| 576 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 577 | | - struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 578 | | - void __iomem *docptr = doc->virtadr; |
|---|
| 579 | | - int floor = 0; |
|---|
| 580 | | - |
|---|
| 581 | | - if (debug) |
|---|
| 582 | | - printk("select chip (%d)\n", chip); |
|---|
| 583 | | - |
|---|
| 584 | | - if (chip == -1) { |
|---|
| 585 | | - /* Disable flash internally */ |
|---|
| 586 | | - WriteDOC(0, docptr, Mplus_FlashSelect); |
|---|
| 587 | | - return; |
|---|
| 588 | | - } |
|---|
| 589 | | - |
|---|
| 590 | | - floor = chip / doc->chips_per_floor; |
|---|
| 591 | | - chip -= (floor * doc->chips_per_floor); |
|---|
| 592 | | - |
|---|
| 593 | | - /* Assert ChipEnable and deassert WriteProtect */ |
|---|
| 594 | | - WriteDOC((DOC_FLASH_CE), docptr, Mplus_FlashSelect); |
|---|
| 595 | | - nand_reset_op(this); |
|---|
| 596 | | - |
|---|
| 597 | | - doc->curchip = chip; |
|---|
| 598 | | - doc->curfloor = floor; |
|---|
| 505 | + WriteDOC(value, doc->virtadr, CDSNControl); |
|---|
| 506 | + /* 11.4.3 -- 4 NOPs after CSDNControl write */ |
|---|
| 507 | + DoC_Delay(doc, 4); |
|---|
| 599 | 508 | } |
|---|
| 600 | 509 | |
|---|
| 601 | | -static void doc200x_select_chip(struct mtd_info *mtd, int chip) |
|---|
| 510 | +static void doc200x_exec_instr(struct nand_chip *this, |
|---|
| 511 | + const struct nand_op_instr *instr) |
|---|
| 602 | 512 | { |
|---|
| 603 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 604 | 513 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 605 | | - void __iomem *docptr = doc->virtadr; |
|---|
| 606 | | - int floor = 0; |
|---|
| 514 | + unsigned int i; |
|---|
| 607 | 515 | |
|---|
| 608 | | - if (debug) |
|---|
| 609 | | - printk("select chip (%d)\n", chip); |
|---|
| 516 | + switch (instr->type) { |
|---|
| 517 | + case NAND_OP_CMD_INSTR: |
|---|
| 518 | + doc200x_write_control(doc, CDSN_CTRL_CE | CDSN_CTRL_CLE); |
|---|
| 519 | + doc2000_write_byte(this, instr->ctx.cmd.opcode); |
|---|
| 520 | + break; |
|---|
| 610 | 521 | |
|---|
| 611 | | - if (chip == -1) |
|---|
| 612 | | - return; |
|---|
| 522 | + case NAND_OP_ADDR_INSTR: |
|---|
| 523 | + doc200x_write_control(doc, CDSN_CTRL_CE | CDSN_CTRL_ALE); |
|---|
| 524 | + for (i = 0; i < instr->ctx.addr.naddrs; i++) { |
|---|
| 525 | + u8 addr = instr->ctx.addr.addrs[i]; |
|---|
| 613 | 526 | |
|---|
| 614 | | - floor = chip / doc->chips_per_floor; |
|---|
| 615 | | - chip -= (floor * doc->chips_per_floor); |
|---|
| 527 | + if (DoC_is_2000(doc)) |
|---|
| 528 | + doc2000_write_byte(this, addr); |
|---|
| 529 | + else |
|---|
| 530 | + doc2001_write_byte(this, addr); |
|---|
| 531 | + } |
|---|
| 532 | + break; |
|---|
| 616 | 533 | |
|---|
| 617 | | - /* 11.4.4 -- deassert CE before changing chip */ |
|---|
| 618 | | - doc200x_hwcontrol(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE); |
|---|
| 619 | | - |
|---|
| 620 | | - WriteDOC(floor, docptr, FloorSelect); |
|---|
| 621 | | - WriteDOC(chip, docptr, CDSNDeviceSelect); |
|---|
| 622 | | - |
|---|
| 623 | | - doc200x_hwcontrol(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); |
|---|
| 624 | | - |
|---|
| 625 | | - doc->curchip = chip; |
|---|
| 626 | | - doc->curfloor = floor; |
|---|
| 627 | | -} |
|---|
| 628 | | - |
|---|
| 629 | | -#define CDSN_CTRL_MSK (CDSN_CTRL_CE | CDSN_CTRL_CLE | CDSN_CTRL_ALE) |
|---|
| 630 | | - |
|---|
| 631 | | -static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd, |
|---|
| 632 | | - unsigned int ctrl) |
|---|
| 633 | | -{ |
|---|
| 634 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 635 | | - struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 636 | | - void __iomem *docptr = doc->virtadr; |
|---|
| 637 | | - |
|---|
| 638 | | - if (ctrl & NAND_CTRL_CHANGE) { |
|---|
| 639 | | - doc->CDSNControl &= ~CDSN_CTRL_MSK; |
|---|
| 640 | | - doc->CDSNControl |= ctrl & CDSN_CTRL_MSK; |
|---|
| 641 | | - if (debug) |
|---|
| 642 | | - printk("hwcontrol(%d): %02x\n", cmd, doc->CDSNControl); |
|---|
| 643 | | - WriteDOC(doc->CDSNControl, docptr, CDSNControl); |
|---|
| 644 | | - /* 11.4.3 -- 4 NOPs after CSDNControl write */ |
|---|
| 645 | | - DoC_Delay(doc, 4); |
|---|
| 646 | | - } |
|---|
| 647 | | - if (cmd != NAND_CMD_NONE) { |
|---|
| 534 | + case NAND_OP_DATA_IN_INSTR: |
|---|
| 535 | + doc200x_write_control(doc, CDSN_CTRL_CE); |
|---|
| 648 | 536 | if (DoC_is_2000(doc)) |
|---|
| 649 | | - doc2000_write_byte(mtd, cmd); |
|---|
| 537 | + doc2000_readbuf(this, instr->ctx.data.buf.in, |
|---|
| 538 | + instr->ctx.data.len); |
|---|
| 650 | 539 | else |
|---|
| 651 | | - doc2001_write_byte(mtd, cmd); |
|---|
| 540 | + doc2001_readbuf(this, instr->ctx.data.buf.in, |
|---|
| 541 | + instr->ctx.data.len); |
|---|
| 542 | + break; |
|---|
| 543 | + |
|---|
| 544 | + case NAND_OP_DATA_OUT_INSTR: |
|---|
| 545 | + doc200x_write_control(doc, CDSN_CTRL_CE); |
|---|
| 546 | + if (DoC_is_2000(doc)) |
|---|
| 547 | + doc2000_writebuf(this, instr->ctx.data.buf.out, |
|---|
| 548 | + instr->ctx.data.len); |
|---|
| 549 | + else |
|---|
| 550 | + doc2001_writebuf(this, instr->ctx.data.buf.out, |
|---|
| 551 | + instr->ctx.data.len); |
|---|
| 552 | + break; |
|---|
| 553 | + |
|---|
| 554 | + case NAND_OP_WAITRDY_INSTR: |
|---|
| 555 | + DoC_WaitReady(doc); |
|---|
| 556 | + break; |
|---|
| 652 | 557 | } |
|---|
| 558 | + |
|---|
| 559 | + if (instr->delay_ns) |
|---|
| 560 | + ndelay(instr->delay_ns); |
|---|
| 653 | 561 | } |
|---|
| 654 | 562 | |
|---|
| 655 | | -static void doc2001plus_command(struct mtd_info *mtd, unsigned command, int column, int page_addr) |
|---|
| 563 | +static int doc200x_exec_op(struct nand_chip *this, |
|---|
| 564 | + const struct nand_operation *op, |
|---|
| 565 | + bool check_only) |
|---|
| 656 | 566 | { |
|---|
| 657 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 658 | 567 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 659 | | - void __iomem *docptr = doc->virtadr; |
|---|
| 568 | + unsigned int i; |
|---|
| 660 | 569 | |
|---|
| 661 | | - /* |
|---|
| 662 | | - * Must terminate write pipeline before sending any commands |
|---|
| 663 | | - * to the device. |
|---|
| 664 | | - */ |
|---|
| 665 | | - if (command == NAND_CMD_PAGEPROG) { |
|---|
| 666 | | - WriteDOC(0x00, docptr, Mplus_WritePipeTerm); |
|---|
| 667 | | - WriteDOC(0x00, docptr, Mplus_WritePipeTerm); |
|---|
| 668 | | - } |
|---|
| 570 | + if (check_only) |
|---|
| 571 | + return true; |
|---|
| 669 | 572 | |
|---|
| 670 | | - /* |
|---|
| 671 | | - * Write out the command to the device. |
|---|
| 672 | | - */ |
|---|
| 673 | | - if (command == NAND_CMD_SEQIN) { |
|---|
| 674 | | - int readcmd; |
|---|
| 573 | + doc->curchip = op->cs % doc->chips_per_floor; |
|---|
| 574 | + doc->curfloor = op->cs / doc->chips_per_floor; |
|---|
| 675 | 575 | |
|---|
| 676 | | - if (column >= mtd->writesize) { |
|---|
| 677 | | - /* OOB area */ |
|---|
| 678 | | - column -= mtd->writesize; |
|---|
| 679 | | - readcmd = NAND_CMD_READOOB; |
|---|
| 680 | | - } else if (column < 256) { |
|---|
| 681 | | - /* First 256 bytes --> READ0 */ |
|---|
| 682 | | - readcmd = NAND_CMD_READ0; |
|---|
| 683 | | - } else { |
|---|
| 684 | | - column -= 256; |
|---|
| 685 | | - readcmd = NAND_CMD_READ1; |
|---|
| 686 | | - } |
|---|
| 687 | | - WriteDOC(readcmd, docptr, Mplus_FlashCmd); |
|---|
| 688 | | - } |
|---|
| 689 | | - WriteDOC(command, docptr, Mplus_FlashCmd); |
|---|
| 690 | | - WriteDOC(0, docptr, Mplus_WritePipeTerm); |
|---|
| 691 | | - WriteDOC(0, docptr, Mplus_WritePipeTerm); |
|---|
| 576 | + WriteDOC(doc->curfloor, doc->virtadr, FloorSelect); |
|---|
| 577 | + WriteDOC(doc->curchip, doc->virtadr, CDSNDeviceSelect); |
|---|
| 692 | 578 | |
|---|
| 693 | | - if (column != -1 || page_addr != -1) { |
|---|
| 694 | | - /* Serially input address */ |
|---|
| 695 | | - if (column != -1) { |
|---|
| 696 | | - /* Adjust columns for 16 bit buswidth */ |
|---|
| 697 | | - if (this->options & NAND_BUSWIDTH_16 && |
|---|
| 698 | | - !nand_opcode_8bits(command)) |
|---|
| 699 | | - column >>= 1; |
|---|
| 700 | | - WriteDOC(column, docptr, Mplus_FlashAddress); |
|---|
| 701 | | - } |
|---|
| 702 | | - if (page_addr != -1) { |
|---|
| 703 | | - WriteDOC((unsigned char)(page_addr & 0xff), docptr, Mplus_FlashAddress); |
|---|
| 704 | | - WriteDOC((unsigned char)((page_addr >> 8) & 0xff), docptr, Mplus_FlashAddress); |
|---|
| 705 | | - if (this->options & NAND_ROW_ADDR_3) { |
|---|
| 706 | | - WriteDOC((unsigned char)((page_addr >> 16) & 0x0f), docptr, Mplus_FlashAddress); |
|---|
| 707 | | - printk("high density\n"); |
|---|
| 708 | | - } |
|---|
| 709 | | - } |
|---|
| 710 | | - WriteDOC(0, docptr, Mplus_WritePipeTerm); |
|---|
| 711 | | - WriteDOC(0, docptr, Mplus_WritePipeTerm); |
|---|
| 712 | | - /* deassert ALE */ |
|---|
| 713 | | - if (command == NAND_CMD_READ0 || command == NAND_CMD_READ1 || |
|---|
| 714 | | - command == NAND_CMD_READOOB || command == NAND_CMD_READID) |
|---|
| 715 | | - WriteDOC(0, docptr, Mplus_FlashControl); |
|---|
| 716 | | - } |
|---|
| 579 | + /* Assert CE pin */ |
|---|
| 580 | + doc200x_write_control(doc, CDSN_CTRL_CE); |
|---|
| 717 | 581 | |
|---|
| 718 | | - /* |
|---|
| 719 | | - * program and erase have their own busy handlers |
|---|
| 720 | | - * status and sequential in needs no delay |
|---|
| 721 | | - */ |
|---|
| 722 | | - switch (command) { |
|---|
| 582 | + for (i = 0; i < op->ninstrs; i++) |
|---|
| 583 | + doc200x_exec_instr(this, &op->instrs[i]); |
|---|
| 723 | 584 | |
|---|
| 724 | | - case NAND_CMD_PAGEPROG: |
|---|
| 725 | | - case NAND_CMD_ERASE1: |
|---|
| 726 | | - case NAND_CMD_ERASE2: |
|---|
| 727 | | - case NAND_CMD_SEQIN: |
|---|
| 728 | | - case NAND_CMD_STATUS: |
|---|
| 729 | | - return; |
|---|
| 585 | + /* De-assert CE pin */ |
|---|
| 586 | + doc200x_write_control(doc, 0); |
|---|
| 730 | 587 | |
|---|
| 731 | | - case NAND_CMD_RESET: |
|---|
| 732 | | - if (this->dev_ready) |
|---|
| 733 | | - break; |
|---|
| 734 | | - udelay(this->chip_delay); |
|---|
| 735 | | - WriteDOC(NAND_CMD_STATUS, docptr, Mplus_FlashCmd); |
|---|
| 736 | | - WriteDOC(0, docptr, Mplus_WritePipeTerm); |
|---|
| 737 | | - WriteDOC(0, docptr, Mplus_WritePipeTerm); |
|---|
| 738 | | - while (!(this->read_byte(mtd) & 0x40)) ; |
|---|
| 739 | | - return; |
|---|
| 740 | | - |
|---|
| 741 | | - /* This applies to read commands */ |
|---|
| 742 | | - default: |
|---|
| 743 | | - /* |
|---|
| 744 | | - * If we don't have access to the busy pin, we apply the given |
|---|
| 745 | | - * command delay |
|---|
| 746 | | - */ |
|---|
| 747 | | - if (!this->dev_ready) { |
|---|
| 748 | | - udelay(this->chip_delay); |
|---|
| 749 | | - return; |
|---|
| 750 | | - } |
|---|
| 751 | | - } |
|---|
| 752 | | - |
|---|
| 753 | | - /* Apply this short delay always to ensure that we do wait tWB in |
|---|
| 754 | | - * any case on any machine. */ |
|---|
| 755 | | - ndelay(100); |
|---|
| 756 | | - /* wait until command is processed */ |
|---|
| 757 | | - while (!this->dev_ready(mtd)) ; |
|---|
| 758 | | -} |
|---|
| 759 | | - |
|---|
| 760 | | -static int doc200x_dev_ready(struct mtd_info *mtd) |
|---|
| 761 | | -{ |
|---|
| 762 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 763 | | - struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 764 | | - void __iomem *docptr = doc->virtadr; |
|---|
| 765 | | - |
|---|
| 766 | | - if (DoC_is_MillenniumPlus(doc)) { |
|---|
| 767 | | - /* 11.4.2 -- must NOP four times before checking FR/B# */ |
|---|
| 768 | | - DoC_Delay(doc, 4); |
|---|
| 769 | | - if ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) { |
|---|
| 770 | | - if (debug) |
|---|
| 771 | | - printk("not ready\n"); |
|---|
| 772 | | - return 0; |
|---|
| 773 | | - } |
|---|
| 774 | | - if (debug) |
|---|
| 775 | | - printk("was ready\n"); |
|---|
| 776 | | - return 1; |
|---|
| 777 | | - } else { |
|---|
| 778 | | - /* 11.4.2 -- must NOP four times before checking FR/B# */ |
|---|
| 779 | | - DoC_Delay(doc, 4); |
|---|
| 780 | | - if (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) { |
|---|
| 781 | | - if (debug) |
|---|
| 782 | | - printk("not ready\n"); |
|---|
| 783 | | - return 0; |
|---|
| 784 | | - } |
|---|
| 785 | | - /* 11.4.2 -- Must NOP twice if it's ready */ |
|---|
| 786 | | - DoC_Delay(doc, 2); |
|---|
| 787 | | - if (debug) |
|---|
| 788 | | - printk("was ready\n"); |
|---|
| 789 | | - return 1; |
|---|
| 790 | | - } |
|---|
| 791 | | -} |
|---|
| 792 | | - |
|---|
| 793 | | -static int doc200x_block_bad(struct mtd_info *mtd, loff_t ofs) |
|---|
| 794 | | -{ |
|---|
| 795 | | - /* This is our last resort if we couldn't find or create a BBT. Just |
|---|
| 796 | | - pretend all blocks are good. */ |
|---|
| 797 | 588 | return 0; |
|---|
| 798 | 589 | } |
|---|
| 799 | 590 | |
|---|
| 800 | | -static void doc200x_enable_hwecc(struct mtd_info *mtd, int mode) |
|---|
| 591 | +static void doc2001plus_write_pipe_term(struct doc_priv *doc) |
|---|
| 801 | 592 | { |
|---|
| 802 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 593 | + WriteDOC(0x00, doc->virtadr, Mplus_WritePipeTerm); |
|---|
| 594 | + WriteDOC(0x00, doc->virtadr, Mplus_WritePipeTerm); |
|---|
| 595 | +} |
|---|
| 596 | + |
|---|
| 597 | +static void doc2001plus_exec_instr(struct nand_chip *this, |
|---|
| 598 | + const struct nand_op_instr *instr) |
|---|
| 599 | +{ |
|---|
| 600 | + struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 601 | + unsigned int i; |
|---|
| 602 | + |
|---|
| 603 | + switch (instr->type) { |
|---|
| 604 | + case NAND_OP_CMD_INSTR: |
|---|
| 605 | + WriteDOC(instr->ctx.cmd.opcode, doc->virtadr, Mplus_FlashCmd); |
|---|
| 606 | + doc2001plus_write_pipe_term(doc); |
|---|
| 607 | + break; |
|---|
| 608 | + |
|---|
| 609 | + case NAND_OP_ADDR_INSTR: |
|---|
| 610 | + for (i = 0; i < instr->ctx.addr.naddrs; i++) { |
|---|
| 611 | + u8 addr = instr->ctx.addr.addrs[i]; |
|---|
| 612 | + |
|---|
| 613 | + WriteDOC(addr, doc->virtadr, Mplus_FlashAddress); |
|---|
| 614 | + } |
|---|
| 615 | + doc2001plus_write_pipe_term(doc); |
|---|
| 616 | + /* deassert ALE */ |
|---|
| 617 | + WriteDOC(0, doc->virtadr, Mplus_FlashControl); |
|---|
| 618 | + break; |
|---|
| 619 | + |
|---|
| 620 | + case NAND_OP_DATA_IN_INSTR: |
|---|
| 621 | + doc2001plus_readbuf(this, instr->ctx.data.buf.in, |
|---|
| 622 | + instr->ctx.data.len); |
|---|
| 623 | + break; |
|---|
| 624 | + case NAND_OP_DATA_OUT_INSTR: |
|---|
| 625 | + doc2001plus_writebuf(this, instr->ctx.data.buf.out, |
|---|
| 626 | + instr->ctx.data.len); |
|---|
| 627 | + doc2001plus_write_pipe_term(doc); |
|---|
| 628 | + break; |
|---|
| 629 | + case NAND_OP_WAITRDY_INSTR: |
|---|
| 630 | + DoC_WaitReady(doc); |
|---|
| 631 | + break; |
|---|
| 632 | + } |
|---|
| 633 | + |
|---|
| 634 | + if (instr->delay_ns) |
|---|
| 635 | + ndelay(instr->delay_ns); |
|---|
| 636 | +} |
|---|
| 637 | + |
|---|
| 638 | +static int doc2001plus_exec_op(struct nand_chip *this, |
|---|
| 639 | + const struct nand_operation *op, |
|---|
| 640 | + bool check_only) |
|---|
| 641 | +{ |
|---|
| 642 | + struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 643 | + unsigned int i; |
|---|
| 644 | + |
|---|
| 645 | + if (check_only) |
|---|
| 646 | + return true; |
|---|
| 647 | + |
|---|
| 648 | + doc->curchip = op->cs % doc->chips_per_floor; |
|---|
| 649 | + doc->curfloor = op->cs / doc->chips_per_floor; |
|---|
| 650 | + |
|---|
| 651 | + /* Assert ChipEnable and deassert WriteProtect */ |
|---|
| 652 | + WriteDOC(DOC_FLASH_CE, doc->virtadr, Mplus_FlashSelect); |
|---|
| 653 | + |
|---|
| 654 | + for (i = 0; i < op->ninstrs; i++) |
|---|
| 655 | + doc2001plus_exec_instr(this, &op->instrs[i]); |
|---|
| 656 | + |
|---|
| 657 | + /* De-assert ChipEnable */ |
|---|
| 658 | + WriteDOC(0, doc->virtadr, Mplus_FlashSelect); |
|---|
| 659 | + |
|---|
| 660 | + return 0; |
|---|
| 661 | +} |
|---|
| 662 | + |
|---|
| 663 | +static void doc200x_enable_hwecc(struct nand_chip *this, int mode) |
|---|
| 664 | +{ |
|---|
| 803 | 665 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 804 | 666 | void __iomem *docptr = doc->virtadr; |
|---|
| 805 | 667 | |
|---|
| .. | .. |
|---|
| 816 | 678 | } |
|---|
| 817 | 679 | } |
|---|
| 818 | 680 | |
|---|
| 819 | | -static void doc2001plus_enable_hwecc(struct mtd_info *mtd, int mode) |
|---|
| 681 | +static void doc2001plus_enable_hwecc(struct nand_chip *this, int mode) |
|---|
| 820 | 682 | { |
|---|
| 821 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 822 | 683 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 823 | 684 | void __iomem *docptr = doc->virtadr; |
|---|
| 824 | 685 | |
|---|
| .. | .. |
|---|
| 836 | 697 | } |
|---|
| 837 | 698 | |
|---|
| 838 | 699 | /* This code is only called on write */ |
|---|
| 839 | | -static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, unsigned char *ecc_code) |
|---|
| 700 | +static int doc200x_calculate_ecc(struct nand_chip *this, const u_char *dat, |
|---|
| 701 | + unsigned char *ecc_code) |
|---|
| 840 | 702 | { |
|---|
| 841 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 842 | 703 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 843 | 704 | void __iomem *docptr = doc->virtadr; |
|---|
| 844 | 705 | int i; |
|---|
| .. | .. |
|---|
| 895 | 756 | return 0; |
|---|
| 896 | 757 | } |
|---|
| 897 | 758 | |
|---|
| 898 | | -static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, |
|---|
| 759 | +static int doc200x_correct_data(struct nand_chip *this, u_char *dat, |
|---|
| 899 | 760 | u_char *read_ecc, u_char *isnull) |
|---|
| 900 | 761 | { |
|---|
| 901 | 762 | int i, ret = 0; |
|---|
| 902 | | - struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 903 | 763 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 904 | 764 | void __iomem *docptr = doc->virtadr; |
|---|
| 905 | 765 | uint8_t calc_ecc[6]; |
|---|
| .. | .. |
|---|
| 1046 | 906 | { |
|---|
| 1047 | 907 | struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 1048 | 908 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 909 | + struct nand_memory_organization *memorg; |
|---|
| 1049 | 910 | int ret = 0; |
|---|
| 1050 | 911 | u_char *buf; |
|---|
| 1051 | 912 | struct NFTLMediaHeader *mh; |
|---|
| .. | .. |
|---|
| 1053 | 914 | int numparts = 0; |
|---|
| 1054 | 915 | unsigned blocks, maxblocks; |
|---|
| 1055 | 916 | int offs, numheaders; |
|---|
| 917 | + |
|---|
| 918 | + memorg = nanddev_get_memorg(&this->base); |
|---|
| 1056 | 919 | |
|---|
| 1057 | 920 | buf = kmalloc(mtd->writesize, GFP_KERNEL); |
|---|
| 1058 | 921 | if (!buf) { |
|---|
| .. | .. |
|---|
| 1100 | 963 | implementation of the NAND layer. */ |
|---|
| 1101 | 964 | if (mh->UnitSizeFactor != 0xff) { |
|---|
| 1102 | 965 | this->bbt_erase_shift += (0xff - mh->UnitSizeFactor); |
|---|
| 966 | + memorg->pages_per_eraseblock <<= (0xff - mh->UnitSizeFactor); |
|---|
| 1103 | 967 | mtd->erasesize <<= (0xff - mh->UnitSizeFactor); |
|---|
| 1104 | 968 | pr_info("Setting virtual erase size to %d\n", mtd->erasesize); |
|---|
| 1105 | 969 | blocks = mtd->size >> this->bbt_erase_shift; |
|---|
| .. | .. |
|---|
| 1182 | 1046 | " NoOfBootImageBlocks = %d\n" |
|---|
| 1183 | 1047 | " NoOfBinaryPartitions = %d\n" |
|---|
| 1184 | 1048 | " NoOfBDTLPartitions = %d\n" |
|---|
| 1185 | | - " BlockMultiplerBits = %d\n" |
|---|
| 1049 | + " BlockMultiplierBits = %d\n" |
|---|
| 1186 | 1050 | " FormatFlgs = %d\n" |
|---|
| 1187 | 1051 | " OsakVersion = %d.%d.%d.%d\n" |
|---|
| 1188 | 1052 | " PercentUsed = %d\n", |
|---|
| .. | .. |
|---|
| 1305 | 1169 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 1306 | 1170 | struct mtd_partition parts[5]; |
|---|
| 1307 | 1171 | |
|---|
| 1308 | | - if (this->numchips > doc->chips_per_floor) { |
|---|
| 1172 | + if (nanddev_ntargets(&this->base) > doc->chips_per_floor) { |
|---|
| 1309 | 1173 | pr_err("Multi-floor INFTL devices not yet supported.\n"); |
|---|
| 1310 | 1174 | return -EIO; |
|---|
| 1311 | 1175 | } |
|---|
| .. | .. |
|---|
| 1357 | 1221 | struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 1358 | 1222 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 1359 | 1223 | |
|---|
| 1360 | | - this->read_byte = doc2000_read_byte; |
|---|
| 1361 | | - this->write_buf = doc2000_writebuf; |
|---|
| 1362 | | - this->read_buf = doc2000_readbuf; |
|---|
| 1363 | 1224 | doc->late_init = nftl_scan_bbt; |
|---|
| 1364 | 1225 | |
|---|
| 1365 | 1226 | doc->CDSNControl = CDSN_CTRL_FLASH_IO | CDSN_CTRL_ECC_IO; |
|---|
| .. | .. |
|---|
| 1372 | 1233 | { |
|---|
| 1373 | 1234 | struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 1374 | 1235 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 1375 | | - |
|---|
| 1376 | | - this->read_byte = doc2001_read_byte; |
|---|
| 1377 | | - this->write_buf = doc2001_writebuf; |
|---|
| 1378 | | - this->read_buf = doc2001_readbuf; |
|---|
| 1379 | 1236 | |
|---|
| 1380 | 1237 | ReadDOC(doc->virtadr, ChipID); |
|---|
| 1381 | 1238 | ReadDOC(doc->virtadr, ChipID); |
|---|
| .. | .. |
|---|
| 1403 | 1260 | struct nand_chip *this = mtd_to_nand(mtd); |
|---|
| 1404 | 1261 | struct doc_priv *doc = nand_get_controller_data(this); |
|---|
| 1405 | 1262 | |
|---|
| 1406 | | - this->read_byte = doc2001plus_read_byte; |
|---|
| 1407 | | - this->write_buf = doc2001plus_writebuf; |
|---|
| 1408 | | - this->read_buf = doc2001plus_readbuf; |
|---|
| 1409 | 1263 | doc->late_init = inftl_scan_bbt; |
|---|
| 1410 | | - this->cmd_ctrl = NULL; |
|---|
| 1411 | | - this->select_chip = doc2001plus_select_chip; |
|---|
| 1412 | | - this->cmdfunc = doc2001plus_command; |
|---|
| 1413 | 1264 | this->ecc.hwctl = doc2001plus_enable_hwecc; |
|---|
| 1414 | 1265 | |
|---|
| 1415 | 1266 | doc->chips_per_floor = 1; |
|---|
| .. | .. |
|---|
| 1417 | 1268 | |
|---|
| 1418 | 1269 | return 1; |
|---|
| 1419 | 1270 | } |
|---|
| 1271 | + |
|---|
| 1272 | +static int doc200x_attach_chip(struct nand_chip *chip) |
|---|
| 1273 | +{ |
|---|
| 1274 | + if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST) |
|---|
| 1275 | + return 0; |
|---|
| 1276 | + |
|---|
| 1277 | + chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED; |
|---|
| 1278 | + chip->ecc.size = 512; |
|---|
| 1279 | + chip->ecc.bytes = 6; |
|---|
| 1280 | + chip->ecc.strength = 2; |
|---|
| 1281 | + chip->ecc.options = NAND_ECC_GENERIC_ERASED_CHECK; |
|---|
| 1282 | + chip->ecc.hwctl = doc200x_enable_hwecc; |
|---|
| 1283 | + chip->ecc.calculate = doc200x_calculate_ecc; |
|---|
| 1284 | + chip->ecc.correct = doc200x_correct_data; |
|---|
| 1285 | + |
|---|
| 1286 | + return 0; |
|---|
| 1287 | +} |
|---|
| 1288 | + |
|---|
| 1289 | +static const struct nand_controller_ops doc200x_ops = { |
|---|
| 1290 | + .exec_op = doc200x_exec_op, |
|---|
| 1291 | + .attach_chip = doc200x_attach_chip, |
|---|
| 1292 | +}; |
|---|
| 1293 | + |
|---|
| 1294 | +static const struct nand_controller_ops doc2001plus_ops = { |
|---|
| 1295 | + .exec_op = doc2001plus_exec_op, |
|---|
| 1296 | + .attach_chip = doc200x_attach_chip, |
|---|
| 1297 | +}; |
|---|
| 1420 | 1298 | |
|---|
| 1421 | 1299 | static int __init doc_probe(unsigned long physadr) |
|---|
| 1422 | 1300 | { |
|---|
| .. | .. |
|---|
| 1495 | 1373 | break; |
|---|
| 1496 | 1374 | case DOC_ChipID_DocMilPlus32: |
|---|
| 1497 | 1375 | pr_err("DiskOnChip Millennium Plus 32MB is not supported, ignoring.\n"); |
|---|
| 1376 | + fallthrough; |
|---|
| 1498 | 1377 | default: |
|---|
| 1499 | 1378 | ret = -ENODEV; |
|---|
| 1500 | 1379 | goto notfound; |
|---|
| .. | .. |
|---|
| 1560 | 1439 | goto fail; |
|---|
| 1561 | 1440 | } |
|---|
| 1562 | 1441 | |
|---|
| 1563 | | - |
|---|
| 1564 | 1442 | /* |
|---|
| 1565 | 1443 | * Allocate a RS codec instance |
|---|
| 1566 | 1444 | * |
|---|
| .. | .. |
|---|
| 1578 | 1456 | goto fail; |
|---|
| 1579 | 1457 | } |
|---|
| 1580 | 1458 | |
|---|
| 1459 | + nand_controller_init(&doc->base); |
|---|
| 1460 | + if (ChipID == DOC_ChipID_DocMilPlus16) |
|---|
| 1461 | + doc->base.ops = &doc2001plus_ops; |
|---|
| 1462 | + else |
|---|
| 1463 | + doc->base.ops = &doc200x_ops; |
|---|
| 1464 | + |
|---|
| 1581 | 1465 | mtd = nand_to_mtd(nand); |
|---|
| 1582 | 1466 | nand->bbt_td = (struct nand_bbt_descr *) (doc + 1); |
|---|
| 1583 | 1467 | nand->bbt_md = nand->bbt_td + 1; |
|---|
| .. | .. |
|---|
| 1585 | 1469 | mtd->owner = THIS_MODULE; |
|---|
| 1586 | 1470 | mtd_set_ooblayout(mtd, &doc200x_ooblayout_ops); |
|---|
| 1587 | 1471 | |
|---|
| 1472 | + nand->controller = &doc->base; |
|---|
| 1588 | 1473 | nand_set_controller_data(nand, doc); |
|---|
| 1589 | | - nand->select_chip = doc200x_select_chip; |
|---|
| 1590 | | - nand->cmd_ctrl = doc200x_hwcontrol; |
|---|
| 1591 | | - nand->dev_ready = doc200x_dev_ready; |
|---|
| 1592 | | - nand->waitfunc = doc200x_wait; |
|---|
| 1593 | | - nand->block_bad = doc200x_block_bad; |
|---|
| 1594 | | - nand->ecc.hwctl = doc200x_enable_hwecc; |
|---|
| 1595 | | - nand->ecc.calculate = doc200x_calculate_ecc; |
|---|
| 1596 | | - nand->ecc.correct = doc200x_correct_data; |
|---|
| 1597 | | - |
|---|
| 1598 | | - nand->ecc.mode = NAND_ECC_HW_SYNDROME; |
|---|
| 1599 | | - nand->ecc.size = 512; |
|---|
| 1600 | | - nand->ecc.bytes = 6; |
|---|
| 1601 | | - nand->ecc.strength = 2; |
|---|
| 1602 | | - nand->ecc.options = NAND_ECC_GENERIC_ERASED_CHECK; |
|---|
| 1603 | 1474 | nand->bbt_options = NAND_BBT_USE_FLASH; |
|---|
| 1604 | 1475 | /* Skip the automatic BBT scan so we can run it manually */ |
|---|
| 1605 | | - nand->options |= NAND_SKIP_BBTSCAN; |
|---|
| 1476 | + nand->options |= NAND_SKIP_BBTSCAN | NAND_NO_BBM_QUIRK; |
|---|
| 1606 | 1477 | |
|---|
| 1607 | 1478 | doc->physadr = physadr; |
|---|
| 1608 | 1479 | doc->virtadr = virtadr; |
|---|
| .. | .. |
|---|
| 1653 | 1524 | struct mtd_info *mtd, *nextmtd; |
|---|
| 1654 | 1525 | struct nand_chip *nand; |
|---|
| 1655 | 1526 | struct doc_priv *doc; |
|---|
| 1527 | + int ret; |
|---|
| 1656 | 1528 | |
|---|
| 1657 | 1529 | for (mtd = doclist; mtd; mtd = nextmtd) { |
|---|
| 1658 | 1530 | nand = mtd_to_nand(mtd); |
|---|
| 1659 | 1531 | doc = nand_get_controller_data(nand); |
|---|
| 1660 | 1532 | |
|---|
| 1661 | 1533 | nextmtd = doc->nextdoc; |
|---|
| 1662 | | - nand_release(nand); |
|---|
| 1534 | + ret = mtd_device_unregister(mtd); |
|---|
| 1535 | + WARN_ON(ret); |
|---|
| 1536 | + nand_cleanup(nand); |
|---|
| 1663 | 1537 | iounmap(doc->virtadr); |
|---|
| 1664 | 1538 | release_mem_region(doc->physadr, DOC_IOREMAP_LEN); |
|---|
| 1665 | 1539 | free_rs(doc->rs_decoder); |
|---|