📄 doc2000.c
字号:
doc->pageadrlen = doc->chipshift > 25 ? 3 : 2; doc->erasesize = nand_flash_ids[i].erasesize; return 1; } return 0; } } /* We haven't fully identified the chip. Print as much as we know. */ printk(KERN_WARNING "Unknown flash chip found: %2.2X %2.2X\n", id, mfr); printk(KERN_WARNING "Please report to dwmw2@infradead.org\n"); return 0;}/* DoC_ScanChips: Find all NAND chips present in a DiskOnChip, and identify them */static void DoC_ScanChips(struct DiskOnChip *this, int maxchips){ int floor, chip; int numchips[MAX_FLOORS]; int ret = 1; this->numchips = 0; this->mfr = 0; this->id = 0; /* For each floor, find the number of valid chips it contains */ for (floor = 0; floor < MAX_FLOORS; floor++) { ret = 1; numchips[floor] = 0; for (chip = 0; chip < maxchips && ret != 0; chip++) { ret = DoC_IdentChip(this, floor, chip); if (ret) { numchips[floor]++; this->numchips++; } } } /* If there are none at all that we recognise, bail */ if (!this->numchips) { printk(KERN_NOTICE "No flash chips recognised.\n"); return; } /* Allocate an array to hold the information for each chip */ this->chips = kmalloc(sizeof(struct Nand) * this->numchips, GFP_KERNEL); if (!this->chips) { printk(KERN_NOTICE "No memory for allocating chip info structures\n"); return; } ret = 0; /* Fill out the chip array with {floor, chipno} for each * detected chip in the device. */ for (floor = 0; floor < MAX_FLOORS; floor++) { for (chip = 0; chip < numchips[floor]; chip++) { this->chips[ret].floor = floor; this->chips[ret].chip = chip; this->chips[ret].curadr = 0; this->chips[ret].curmode = 0x50; ret++; } } /* Calculate and print the total size of the device */ this->totlen = this->numchips * (1 << this->chipshift); printk(KERN_INFO "%d flash chips found. Total DiskOnChip size: %ld MiB\n", this->numchips, this->totlen >> 20);}static int DoC2k_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2){ int tmp1, tmp2, retval; if (doc1->physadr == doc2->physadr) return 1; /* Use the alias resolution register which was set aside for this * purpose. If it's value is the same on both chips, they might * be the same chip, and we write to one and check for a change in * the other. It's unclear if this register is usuable in the * DoC 2000 (it's in the Millennium docs), but it seems to work. */ tmp1 = ReadDOC(doc1->virtadr, AliasResolution); tmp2 = ReadDOC(doc2->virtadr, AliasResolution); if (tmp1 != tmp2) return 0; WriteDOC((tmp1 + 1) % 0xff, doc1->virtadr, AliasResolution); tmp2 = ReadDOC(doc2->virtadr, AliasResolution); if (tmp2 == (tmp1 + 1) % 0xff) retval = 1; else retval = 0; /* Restore register contents. May not be necessary, but do it just to * be safe. */ WriteDOC(tmp1, doc1->virtadr, AliasResolution); return retval;}/* This routine is found from the docprobe code by symbol_get(), * which will bump the use count of this module. */void DoC2k_init(struct mtd_info *mtd){ struct DiskOnChip *this = mtd->priv; struct DiskOnChip *old = NULL; int maxchips; /* We must avoid being called twice for the same device. */ if (doc2klist) old = doc2klist->priv; while (old) { if (DoC2k_is_alias(old, this)) { printk(KERN_NOTICE "Ignoring DiskOnChip 2000 at 0x%lX - already configured\n", this->physadr); iounmap(this->virtadr); kfree(mtd); return; } if (old->nextdoc) old = old->nextdoc->priv; else old = NULL; } switch (this->ChipID) { case DOC_ChipID_Doc2kTSOP: mtd->name = "DiskOnChip 2000 TSOP"; this->ioreg = DoC_Mil_CDSN_IO; /* Pretend it's a Millennium */ this->ChipID = DOC_ChipID_DocMil; maxchips = MAX_CHIPS; break; case DOC_ChipID_Doc2k: mtd->name = "DiskOnChip 2000"; this->ioreg = DoC_2k_CDSN_IO; maxchips = MAX_CHIPS; break; case DOC_ChipID_DocMil: mtd->name = "DiskOnChip Millennium"; this->ioreg = DoC_Mil_CDSN_IO; maxchips = MAX_CHIPS_MIL; break; default: printk("Unknown ChipID 0x%02x\n", this->ChipID); kfree(mtd); iounmap(this->virtadr); return; } printk(KERN_NOTICE "%s found at address 0x%lX\n", mtd->name, this->physadr); mtd->type = MTD_NANDFLASH; mtd->flags = MTD_CAP_NANDFLASH; mtd->size = 0; mtd->erasesize = 0; mtd->writesize = 512; mtd->oobsize = 16; mtd->owner = THIS_MODULE; mtd->erase = doc_erase; mtd->point = NULL; mtd->unpoint = NULL; mtd->read = doc_read; mtd->write = doc_write; mtd->read_oob = doc_read_oob; mtd->write_oob = doc_write_oob; mtd->sync = NULL; this->totlen = 0; this->numchips = 0; this->curfloor = -1; this->curchip = -1; mutex_init(&this->lock); /* Ident all the chips present. */ DoC_ScanChips(this, maxchips); if (!this->totlen) { kfree(mtd); iounmap(this->virtadr); } else { this->nextdoc = doc2klist; doc2klist = mtd; mtd->size = this->totlen; mtd->erasesize = this->erasesize; add_mtd_device(mtd); return; }}EXPORT_SYMBOL_GPL(DoC2k_init);static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf){ struct DiskOnChip *this = mtd->priv; void __iomem *docptr = this->virtadr; struct Nand *mychip; unsigned char syndrome[6], eccbuf[6]; volatile char dummy; int i, len256 = 0, ret=0; size_t left = len; /* Don't allow read past end of device */ if (from >= this->totlen) return -EINVAL; mutex_lock(&this->lock); *retlen = 0; while (left) { len = left; /* Don't allow a single read to cross a 512-byte block boundary */ if (from + len > ((from | 0x1ff) + 1)) len = ((from | 0x1ff) + 1) - from; /* The ECC will not be calculated correctly if less than 512 is read */ if (len != 0x200) printk(KERN_WARNING "ECC needs a full sector read (adr: %lx size %lx)\n", (long) from, (long) len); /* printk("DoC_Read (adr: %lx size %lx)\n", (long) from, (long) len); */ /* Find the chip which is to be used and select it */ mychip = &this->chips[from >> (this->chipshift)]; if (this->curfloor != mychip->floor) { DoC_SelectFloor(this, mychip->floor); DoC_SelectChip(this, mychip->chip); } else if (this->curchip != mychip->chip) { DoC_SelectChip(this, mychip->chip); } this->curfloor = mychip->floor; this->curchip = mychip->chip; DoC_Command(this, (!this->page256 && (from & 0x100)) ? NAND_CMD_READ1 : NAND_CMD_READ0, CDSN_CTRL_WP); DoC_Address(this, ADDR_COLUMN_PAGE, from, CDSN_CTRL_WP, CDSN_CTRL_ECC_IO); /* Prime the ECC engine */ WriteDOC(DOC_ECC_RESET, docptr, ECCConf); WriteDOC(DOC_ECC_EN, docptr, ECCConf); /* treat crossing 256-byte sector for 2M x 8bits devices */ if (this->page256 && from + len > (from | 0xff) + 1) { len256 = (from | 0xff) + 1 - from; DoC_ReadBuf(this, buf, len256); DoC_Command(this, NAND_CMD_READ0, CDSN_CTRL_WP); DoC_Address(this, ADDR_COLUMN_PAGE, from + len256, CDSN_CTRL_WP, CDSN_CTRL_ECC_IO); } DoC_ReadBuf(this, &buf[len256], len - len256); /* Let the caller know we completed it */ *retlen += len; /* Read the ECC data through the DiskOnChip ECC logic */ /* Note: this will work even with 2M x 8bit devices as */ /* they have 8 bytes of OOB per 256 page. mf. */ DoC_ReadBuf(this, eccbuf, 6); /* Flush the pipeline */ if (DoC_is_Millennium(this)) { dummy = ReadDOC(docptr, ECCConf); dummy = ReadDOC(docptr, ECCConf); i = ReadDOC(docptr, ECCConf); } else { dummy = ReadDOC(docptr, 2k_ECCStatus); dummy = ReadDOC(docptr, 2k_ECCStatus); i = ReadDOC(docptr, 2k_ECCStatus); } /* Check the ECC Status */ if (i & 0x80) { int nb_errors; /* There was an ECC error */#ifdef ECC_DEBUG printk(KERN_ERR "DiskOnChip ECC Error: Read at %lx\n", (long)from);#endif /* Read the ECC syndrom through the DiskOnChip ECC logic. These syndrome will be all ZERO when there is no error */ for (i = 0; i < 6; i++) { syndrome[i] = ReadDOC(docptr, ECCSyndrome0 + i); } nb_errors = doc_decode_ecc(buf, syndrome);#ifdef ECC_DEBUG printk(KERN_ERR "Errors corrected: %x\n", nb_errors);#endif if (nb_errors < 0) { /* We return error, but have actually done the read. Not that this can be told to user-space, via sys_read(), but at least MTD-aware stuff can know about it by checking *retlen */ ret = -EIO; } }#ifdef PSYCHO_DEBUG printk(KERN_DEBUG "ECC DATA at %lxB: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", (long)from, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], eccbuf[4], eccbuf[5]);#endif /* disable the ECC engine */ WriteDOC(DOC_ECC_DIS, docptr , ECCConf); /* according to 11.4.1, we need to wait for the busy line * drop if we read to the end of the page. */ if(0 == ((from + len) & 0x1ff)) { DoC_WaitReady(this); } from += len; left -= len; buf += len; } mutex_unlock(&this->lock); return ret;}static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, size_t * retlen, const u_char * buf){ struct DiskOnChip *this = mtd->priv; int di; /* Yes, DI is a hangover from when I was disassembling the binary driver */ void __iomem *docptr = this->virtadr; unsigned char eccbuf[6]; volatile char dummy; int len256 = 0; struct Nand *mychip; size_t left = len; int status; /* Don't allow write past end of device */ if (to >= this->totlen) return -EINVAL; mutex_lock(&this->lock); *retlen = 0; while (left) { len = left; /* Don't allow a single write to cross a 512-byte block boundary */ if (to + len > ((to | 0x1ff) + 1)) len = ((to | 0x1ff) + 1) - to; /* The ECC will not be calculated correctly if less than 512 is written *//* DBB- if (len != 0x200 && eccbuf) printk(KERN_WARNING "ECC needs a full sector write (adr: %lx size %lx)\n", (long) to, (long) len); -DBB */ /* printk("DoC_Write (adr: %lx size %lx)\n", (long) to, (long) len); */ /* Find the chip which is to be used and select it */ mychip = &this->chips[to >> (this->chipshift)]; if (this->curfloor != mychip->floor) { DoC_SelectFloor(this, mychip->floor); DoC_SelectChip(this, mychip->chip); } else if (this->curchip != mychip->chip) { DoC_SelectChip(this, mychip->chip); } this->curfloor = mychip->floor; this->curchip = mychip->chip; /* Set device to main plane of flash */ DoC_Command(this, NAND_CMD_RESET, CDSN_CTRL_WP);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -