8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <asm/errno.h>
12 #include <asm/uaccess.h>
14 #include <linux/slab.h>
16 #include <linux/types.h>
17 #include <linux/bitops.h>
31 static int doc_read(
struct mtd_info *mtd, loff_t
from,
size_t len,
33 static int doc_write(
struct mtd_info *mtd, loff_t to,
size_t len,
35 static int doc_read_oob(
struct mtd_info *mtd, loff_t ofs,
37 static int doc_write_oob(
struct mtd_info *mtd, loff_t ofs,
44 static void DoC_Delay(
void __iomem * docptr,
unsigned short cycles)
49 for (i = 0; i < cycles; i++)
54 static int _DoC_WaitReady(
void __iomem * docptr)
56 unsigned short c = 0xffff;
58 pr_debug(
"_DoC_WaitReady called for out-of-line wait\n");
65 pr_debug(
"_DoC_WaitReady timed out.\n");
70 static inline int DoC_WaitReady(
void __iomem * docptr)
79 if (!(
ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B))
81 ret = _DoC_WaitReady(docptr);
94 static void DoC_Command(
void __iomem * docptr,
unsigned char command,
95 unsigned char xtraflags)
102 WriteDOC(command, docptr, Mil_CDSN_IO);
103 WriteDOC(0x00, docptr, WritePipeTerm);
107 DoC_Delay(docptr, 4);
114 static inline void DoC_Address(
void __iomem * docptr,
int numbytes,
unsigned long ofs,
115 unsigned char xtraflags1,
unsigned char xtraflags2)
119 DoC_Delay(docptr, 4);
126 WriteDOC(ofs & 0xff, docptr, Mil_CDSN_IO);
127 WriteDOC(0x00, docptr, WritePipeTerm);
131 WriteDOC((ofs >> 9) & 0xff, docptr, Mil_CDSN_IO);
132 WriteDOC((ofs >> 17) & 0xff, docptr, Mil_CDSN_IO);
133 WriteDOC(0x00, docptr, WritePipeTerm);
137 WriteDOC(ofs & 0xff, docptr, Mil_CDSN_IO);
138 WriteDOC((ofs >> 9) & 0xff, docptr, Mil_CDSN_IO);
139 WriteDOC((ofs >> 17) & 0xff, docptr, Mil_CDSN_IO);
140 WriteDOC(0x00, docptr, WritePipeTerm);
148 DoC_Delay(docptr, 4);
152 static int DoC_SelectChip(
void __iomem * docptr,
int chip)
155 WriteDOC(chip, docptr, CDSNDeviceSelect);
156 DoC_Delay(docptr, 4);
159 return DoC_WaitReady(docptr);
163 static int DoC_SelectFloor(
void __iomem * docptr,
int floor)
166 WriteDOC(floor, docptr, FloorSelect);
169 return DoC_WaitReady(docptr);
180 DoC_SelectFloor(doc->
virtadr, floor);
181 DoC_SelectChip(doc->
virtadr, chip);
204 if (mfr == 0xff || mfr == 0)
216 "Chip ID: %2.2X (%s:%s)\n",
232 static void DoC_ScanChips(
struct DiskOnChip *
this)
246 ret = DoC_IdentChip(
this, floor, chip);
254 if (!this->numchips) {
255 printk(
"No flash chips recognised.\n");
262 printk(
"No memory for allocating chip info structures\n");
269 for (chip = 0 ; chip < numchips[
floor] ; chip++) {
279 this->
totlen = this->numchips * (1 << this->chipshift);
280 printk(
KERN_INFO "%d flash chips found. Total DiskOnChip size: %ld MiB\n",
281 this->numchips ,this->
totlen >> 20);
303 if (tmp2 == (tmp1+1) % 0xff)
324 old = docmillist->
priv;
327 if (DoCMil_is_alias(
this, old)) {
329 "0x%lX - already configured\n", this->
physadr);
340 mtd->
name =
"DiskOnChip Millennium";
354 mtd->
_read = doc_read;
377 static int doc_read (
struct mtd_info *mtd, loff_t
from,
size_t len,
382 unsigned char syndrome[6], eccbuf[6];
388 if (from + len > ((from | 0x1ff) + 1))
389 len = ((from | 0x1ff) + 1) - from;
392 if (this->curfloor != mychip->
floor) {
393 DoC_SelectFloor(docptr, mychip->
floor);
394 DoC_SelectChip(docptr, mychip->
chip);
395 }
else if (this->curchip != mychip->
chip) {
396 DoC_SelectChip(docptr, mychip->
chip);
398 this->curfloor = mychip->
floor;
399 this->curchip = mychip->
chip;
406 DoC_WaitReady(docptr);
414 dummy =
ReadDOC(docptr, ReadPipeInit);
416 for (i = 0; i < len-1; i++) {
419 buf[
i] =
ReadDOC(docptr, Mil_CDSN_IO + (i & 0xff));
424 buf[len - 1] =
ReadDOC(docptr, LastDataRead);
432 dummy =
ReadDOC(docptr, ReadPipeInit);
434 for (i = 0; i < 5; i++) {
437 eccbuf[
i] =
ReadDOC(docptr, Mil_CDSN_IO + i);
442 eccbuf[5] =
ReadDOC(docptr, LastDataRead);
445 dummy =
ReadDOC(docptr, ECCConf);
446 dummy =
ReadDOC(docptr, ECCConf);
449 if (
ReadDOC(docptr, ECCConf) & 0x80) {
453 printk(
"DiskOnChip ECC Error: Read at %lx\n", (
long)from);
457 for (i = 0; i < 6; i++) {
458 syndrome[
i] =
ReadDOC(docptr, ECCSyndrome0 + i);
462 printk(
"ECC Errors corrected: %x\n", nb_errors);
473 printk(
"ECC DATA at %lx: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
474 (
long)from, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
475 eccbuf[4], eccbuf[5]);
484 static int doc_write (
struct mtd_info *mtd, loff_t to,
size_t len,
485 size_t *retlen,
const u_char *buf)
492 struct Nand *mychip = &this->
chips[to >> (this->chipshift)];
496 if (to + len > ( (to | 0x1ff) + 1))
497 len = ((to | 0x1ff) + 1) - to;
500 if (to & 0x1ff || len != 0x200)
505 if (this->curfloor != mychip->
floor) {
506 DoC_SelectFloor(docptr, mychip->
floor);
507 DoC_SelectChip(docptr, mychip->
chip);
508 }
else if (this->curchip != mychip->
chip) {
509 DoC_SelectChip(docptr, mychip->
chip);
511 this->curfloor = mychip->
floor;
512 this->curchip = mychip->
chip;
516 DoC_WaitReady(docptr);
522 DoC_Address(docptr, 3, to, 0x00, 0x00);
523 DoC_WaitReady(docptr);
532 for (i = 0; i < len; i++) {
535 WriteDOC(buf[i], docptr, Mil_CDSN_IO + i);
540 WriteDOC(0x00, docptr, WritePipeTerm);
549 for (i = 0; i < 6; i++) {
550 eccbuf[
i] =
ReadDOC(docptr, ECCSyndrome0 + i);
558 for (i = 0; i < 6; i++) {
561 WriteDOC(eccbuf[i], docptr, Mil_CDSN_IO + i);
570 WriteDOC(0x55, docptr, Mil_CDSN_IO);
571 WriteDOC(0x55, docptr, Mil_CDSN_IO + 1);
573 WriteDOC(0x00, docptr, WritePipeTerm);
576 printk(
"OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
577 (
long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
578 eccbuf[4], eccbuf[5]);
584 DoC_WaitReady(docptr);
589 dummy =
ReadDOC(docptr, ReadPipeInit);
590 DoC_Delay(docptr, 2);
591 if (
ReadDOC(docptr, Mil_CDSN_IO) & 1) {
592 printk(
"Error programming flash\n");
597 dummy =
ReadDOC(docptr, LastDataRead);
605 static int doc_read_oob(
struct mtd_info *mtd, loff_t ofs,
614 struct Nand *mychip = &this->
chips[ofs >> this->chipshift];
616 size_t len = ops->
len;
623 if (this->curfloor != mychip->
floor) {
624 DoC_SelectFloor(docptr, mychip->
floor);
625 DoC_SelectChip(docptr, mychip->
chip);
626 }
else if (this->curchip != mychip->
chip) {
627 DoC_SelectChip(docptr, mychip->
chip);
629 this->curfloor = mychip->
floor;
630 this->curchip = mychip->
chip;
641 DoC_WaitReady(docptr);
645 dummy =
ReadDOC(docptr, ReadPipeInit);
647 for (i = 0; i < len-1; i++) {
650 buf[
i] =
ReadDOC(docptr, Mil_CDSN_IO + i);
655 buf[len - 1] =
ReadDOC(docptr, LastDataRead);
662 static int doc_write_oob(
struct mtd_info *mtd, loff_t ofs,
672 struct Nand *mychip = &this->
chips[ofs >> this->chipshift];
674 size_t len = ops->
len;
681 if (this->curfloor != mychip->
floor) {
682 DoC_SelectFloor(docptr, mychip->
floor);
683 DoC_SelectChip(docptr, mychip->
chip);
684 }
else if (this->curchip != mychip->
chip) {
685 DoC_SelectChip(docptr, mychip->
chip);
687 this->curfloor = mychip->
floor;
688 this->curchip = mychip->
chip;
696 DoC_WaitReady(docptr);
702 DoC_Address(docptr, 3, ofs, 0x00, 0x00);
707 for (i = 0; i < len; i++) {
710 WriteDOC(buf[i], docptr, Mil_CDSN_IO + i);
715 WriteDOC(0x00, docptr, WritePipeTerm);
720 DoC_WaitReady(docptr);
725 dummy =
ReadDOC(docptr, ReadPipeInit);
726 DoC_Delay(docptr, 2);
727 if (
ReadDOC(docptr, Mil_CDSN_IO) & 1) {
728 printk(
"Error programming oob data\n");
733 dummy =
ReadDOC(docptr, LastDataRead);
747 struct Nand *mychip = &this->
chips[ofs >> this->chipshift];
754 if (this->curfloor != mychip->
floor) {
755 DoC_SelectFloor(docptr, mychip->
floor);
756 DoC_SelectChip(docptr, mychip->
chip);
757 }
else if (this->curchip != mychip->
chip) {
758 DoC_SelectChip(docptr, mychip->
chip);
760 this->curfloor = mychip->
floor;
761 this->curchip = mychip->
chip;
767 DoC_Address(docptr, 2, ofs, 0x00, 0x00);
772 DoC_WaitReady(docptr);
781 dummy =
ReadDOC(docptr, ReadPipeInit);
782 DoC_Delay(docptr, 2);
783 if (
ReadDOC(docptr, Mil_CDSN_IO) & 1) {
784 printk(
"Error Erasing at 0x%x\n", ofs);
790 dummy =
ReadDOC(docptr, LastDataRead);
803 static void __exit cleanup_doc2001(
void)
808 while ((mtd=docmillist)) {