doc2001plus.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. /*
  2. * Linux driver for Disk-On-Chip Millennium Plus
  3. *
  4. * (c) 2002-2003 Greg Ungerer <gerg@snapgear.com>
  5. * (c) 2002-2003 SnapGear Inc
  6. * (c) 1999 Machine Vision Holdings, Inc.
  7. * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org>
  8. *
  9. * $Id: doc2001plus.c,v 1.14 2005/11/07 11:14:24 gleixner Exp $
  10. *
  11. * Released under GPL
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <asm/errno.h>
  16. #include <asm/io.h>
  17. #include <asm/uaccess.h>
  18. #include <linux/miscdevice.h>
  19. #include <linux/pci.h>
  20. #include <linux/delay.h>
  21. #include <linux/slab.h>
  22. #include <linux/sched.h>
  23. #include <linux/init.h>
  24. #include <linux/types.h>
  25. #include <linux/bitops.h>
  26. #include <linux/mtd/mtd.h>
  27. #include <linux/mtd/nand.h>
  28. #include <linux/mtd/doc2000.h>
  29. /* #define ECC_DEBUG */
  30. /* I have no idea why some DoC chips can not use memcop_form|to_io().
  31. * This may be due to the different revisions of the ASIC controller built-in or
  32. * simplily a QA/Bug issue. Who knows ?? If you have trouble, please uncomment
  33. * this:*/
  34. #undef USE_MEMCPY
  35. static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
  36. size_t *retlen, u_char *buf);
  37. static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
  38. size_t *retlen, const u_char *buf);
  39. static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
  40. size_t *retlen, u_char *buf, u_char *eccbuf,
  41. struct nand_oobinfo *oobsel);
  42. static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
  43. size_t *retlen, const u_char *buf, u_char *eccbuf,
  44. struct nand_oobinfo *oobsel);
  45. static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
  46. struct mtd_oob_ops *ops);
  47. static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
  48. struct mtd_oob_ops *ops);
  49. static int doc_erase (struct mtd_info *mtd, struct erase_info *instr);
  50. static struct mtd_info *docmilpluslist = NULL;
  51. /* Perform the required delay cycles by writing to the NOP register */
  52. static void DoC_Delay(void __iomem * docptr, int cycles)
  53. {
  54. int i;
  55. for (i = 0; (i < cycles); i++)
  56. WriteDOC(0, docptr, Mplus_NOP);
  57. }
  58. #define CDSN_CTRL_FR_B_MASK (CDSN_CTRL_FR_B0 | CDSN_CTRL_FR_B1)
  59. /* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */
  60. static int _DoC_WaitReady(void __iomem * docptr)
  61. {
  62. unsigned int c = 0xffff;
  63. DEBUG(MTD_DEBUG_LEVEL3,
  64. "_DoC_WaitReady called for out-of-line wait\n");
  65. /* Out-of-line routine to wait for chip response */
  66. while (((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) && --c)
  67. ;
  68. if (c == 0)
  69. DEBUG(MTD_DEBUG_LEVEL2, "_DoC_WaitReady timed out.\n");
  70. return (c == 0);
  71. }
  72. static inline int DoC_WaitReady(void __iomem * docptr)
  73. {
  74. /* This is inline, to optimise the common case, where it's ready instantly */
  75. int ret = 0;
  76. /* read form NOP register should be issued prior to the read from CDSNControl
  77. see Software Requirement 11.4 item 2. */
  78. DoC_Delay(docptr, 4);
  79. if ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK)
  80. /* Call the out-of-line routine to wait */
  81. ret = _DoC_WaitReady(docptr);
  82. return ret;
  83. }
  84. /* For some reason the Millennium Plus seems to occassionally put itself
  85. * into reset mode. For me this happens randomly, with no pattern that I
  86. * can detect. M-systems suggest always check this on any block level
  87. * operation and setting to normal mode if in reset mode.
  88. */
  89. static inline void DoC_CheckASIC(void __iomem * docptr)
  90. {
  91. /* Make sure the DoC is in normal mode */
  92. if ((ReadDOC(docptr, Mplus_DOCControl) & DOC_MODE_NORMAL) == 0) {
  93. WriteDOC((DOC_MODE_NORMAL | DOC_MODE_MDWREN), docptr, Mplus_DOCControl);
  94. WriteDOC(~(DOC_MODE_NORMAL | DOC_MODE_MDWREN), docptr, Mplus_CtrlConfirm);
  95. }
  96. }
  97. /* DoC_Command: Send a flash command to the flash chip through the Flash
  98. * command register. Need 2 Write Pipeline Terminates to complete send.
  99. */
  100. static void DoC_Command(void __iomem * docptr, unsigned char command,
  101. unsigned char xtraflags)
  102. {
  103. WriteDOC(command, docptr, Mplus_FlashCmd);
  104. WriteDOC(command, docptr, Mplus_WritePipeTerm);
  105. WriteDOC(command, docptr, Mplus_WritePipeTerm);
  106. }
  107. /* DoC_Address: Set the current address for the flash chip through the Flash
  108. * Address register. Need 2 Write Pipeline Terminates to complete send.
  109. */
  110. static inline void DoC_Address(struct DiskOnChip *doc, int numbytes,
  111. unsigned long ofs, unsigned char xtraflags1,
  112. unsigned char xtraflags2)
  113. {
  114. void __iomem * docptr = doc->virtadr;
  115. /* Allow for possible Mill Plus internal flash interleaving */
  116. ofs >>= doc->interleave;
  117. switch (numbytes) {
  118. case 1:
  119. /* Send single byte, bits 0-7. */
  120. WriteDOC(ofs & 0xff, docptr, Mplus_FlashAddress);
  121. break;
  122. case 2:
  123. /* Send bits 9-16 followed by 17-23 */
  124. WriteDOC((ofs >> 9) & 0xff, docptr, Mplus_FlashAddress);
  125. WriteDOC((ofs >> 17) & 0xff, docptr, Mplus_FlashAddress);
  126. break;
  127. case 3:
  128. /* Send 0-7, 9-16, then 17-23 */
  129. WriteDOC(ofs & 0xff, docptr, Mplus_FlashAddress);
  130. WriteDOC((ofs >> 9) & 0xff, docptr, Mplus_FlashAddress);
  131. WriteDOC((ofs >> 17) & 0xff, docptr, Mplus_FlashAddress);
  132. break;
  133. default:
  134. return;
  135. }
  136. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  137. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  138. }
  139. /* DoC_SelectChip: Select a given flash chip within the current floor */
  140. static int DoC_SelectChip(void __iomem * docptr, int chip)
  141. {
  142. /* No choice for flash chip on Millennium Plus */
  143. return 0;
  144. }
  145. /* DoC_SelectFloor: Select a given floor (bank of flash chips) */
  146. static int DoC_SelectFloor(void __iomem * docptr, int floor)
  147. {
  148. WriteDOC((floor & 0x3), docptr, Mplus_DeviceSelect);
  149. return 0;
  150. }
  151. /*
  152. * Translate the given offset into the appropriate command and offset.
  153. * This does the mapping using the 16bit interleave layout defined by
  154. * M-Systems, and looks like this for a sector pair:
  155. * +-----------+-------+-------+-------+--------------+---------+-----------+
  156. * | 0 --- 511 |512-517|518-519|520-521| 522 --- 1033 |1034-1039|1040 - 1055|
  157. * +-----------+-------+-------+-------+--------------+---------+-----------+
  158. * | Data 0 | ECC 0 |Flags0 |Flags1 | Data 1 |ECC 1 | OOB 1 + 2 |
  159. * +-----------+-------+-------+-------+--------------+---------+-----------+
  160. */
  161. /* FIXME: This lives in INFTL not here. Other users of flash devices
  162. may not want it */
  163. static unsigned int DoC_GetDataOffset(struct mtd_info *mtd, loff_t *from)
  164. {
  165. struct DiskOnChip *this = mtd->priv;
  166. if (this->interleave) {
  167. unsigned int ofs = *from & 0x3ff;
  168. unsigned int cmd;
  169. if (ofs < 512) {
  170. cmd = NAND_CMD_READ0;
  171. ofs &= 0x1ff;
  172. } else if (ofs < 1014) {
  173. cmd = NAND_CMD_READ1;
  174. ofs = (ofs & 0x1ff) + 10;
  175. } else {
  176. cmd = NAND_CMD_READOOB;
  177. ofs = ofs - 1014;
  178. }
  179. *from = (*from & ~0x3ff) | ofs;
  180. return cmd;
  181. } else {
  182. /* No interleave */
  183. if ((*from) & 0x100)
  184. return NAND_CMD_READ1;
  185. return NAND_CMD_READ0;
  186. }
  187. }
  188. static unsigned int DoC_GetECCOffset(struct mtd_info *mtd, loff_t *from)
  189. {
  190. unsigned int ofs, cmd;
  191. if (*from & 0x200) {
  192. cmd = NAND_CMD_READOOB;
  193. ofs = 10 + (*from & 0xf);
  194. } else {
  195. cmd = NAND_CMD_READ1;
  196. ofs = (*from & 0xf);
  197. }
  198. *from = (*from & ~0x3ff) | ofs;
  199. return cmd;
  200. }
  201. static unsigned int DoC_GetFlagsOffset(struct mtd_info *mtd, loff_t *from)
  202. {
  203. unsigned int ofs, cmd;
  204. cmd = NAND_CMD_READ1;
  205. ofs = (*from & 0x200) ? 8 : 6;
  206. *from = (*from & ~0x3ff) | ofs;
  207. return cmd;
  208. }
  209. static unsigned int DoC_GetHdrOffset(struct mtd_info *mtd, loff_t *from)
  210. {
  211. unsigned int ofs, cmd;
  212. cmd = NAND_CMD_READOOB;
  213. ofs = (*from & 0x200) ? 24 : 16;
  214. *from = (*from & ~0x3ff) | ofs;
  215. return cmd;
  216. }
  217. static inline void MemReadDOC(void __iomem * docptr, unsigned char *buf, int len)
  218. {
  219. #ifndef USE_MEMCPY
  220. int i;
  221. for (i = 0; i < len; i++)
  222. buf[i] = ReadDOC(docptr, Mil_CDSN_IO + i);
  223. #else
  224. memcpy_fromio(buf, docptr + DoC_Mil_CDSN_IO, len);
  225. #endif
  226. }
  227. static inline void MemWriteDOC(void __iomem * docptr, unsigned char *buf, int len)
  228. {
  229. #ifndef USE_MEMCPY
  230. int i;
  231. for (i = 0; i < len; i++)
  232. WriteDOC(buf[i], docptr, Mil_CDSN_IO + i);
  233. #else
  234. memcpy_toio(docptr + DoC_Mil_CDSN_IO, buf, len);
  235. #endif
  236. }
  237. /* DoC_IdentChip: Identify a given NAND chip given {floor,chip} */
  238. static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
  239. {
  240. int mfr, id, i, j;
  241. volatile char dummy;
  242. void __iomem * docptr = doc->virtadr;
  243. /* Page in the required floor/chip */
  244. DoC_SelectFloor(docptr, floor);
  245. DoC_SelectChip(docptr, chip);
  246. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  247. WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect);
  248. /* Reset the chip, see Software Requirement 11.4 item 1. */
  249. DoC_Command(docptr, NAND_CMD_RESET, 0);
  250. DoC_WaitReady(docptr);
  251. /* Read the NAND chip ID: 1. Send ReadID command */
  252. DoC_Command(docptr, NAND_CMD_READID, 0);
  253. /* Read the NAND chip ID: 2. Send address byte zero */
  254. DoC_Address(doc, 1, 0x00, 0, 0x00);
  255. WriteDOC(0, docptr, Mplus_FlashControl);
  256. DoC_WaitReady(docptr);
  257. /* Read the manufacturer and device id codes of the flash device through
  258. CDSN IO register see Software Requirement 11.4 item 5.*/
  259. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  260. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  261. mfr = ReadDOC(docptr, Mil_CDSN_IO);
  262. if (doc->interleave)
  263. dummy = ReadDOC(docptr, Mil_CDSN_IO); /* 2 way interleave */
  264. id = ReadDOC(docptr, Mil_CDSN_IO);
  265. if (doc->interleave)
  266. dummy = ReadDOC(docptr, Mil_CDSN_IO); /* 2 way interleave */
  267. dummy = ReadDOC(docptr, Mplus_LastDataRead);
  268. dummy = ReadDOC(docptr, Mplus_LastDataRead);
  269. /* Disable flash internally */
  270. WriteDOC(0, docptr, Mplus_FlashSelect);
  271. /* No response - return failure */
  272. if (mfr == 0xff || mfr == 0)
  273. return 0;
  274. for (i = 0; nand_flash_ids[i].name != NULL; i++) {
  275. if (id == nand_flash_ids[i].id) {
  276. /* Try to identify manufacturer */
  277. for (j = 0; nand_manuf_ids[j].id != 0x0; j++) {
  278. if (nand_manuf_ids[j].id == mfr)
  279. break;
  280. }
  281. printk(KERN_INFO "Flash chip found: Manufacturer ID: %2.2X, "
  282. "Chip ID: %2.2X (%s:%s)\n", mfr, id,
  283. nand_manuf_ids[j].name, nand_flash_ids[i].name);
  284. doc->mfr = mfr;
  285. doc->id = id;
  286. doc->chipshift = ffs((nand_flash_ids[i].chipsize << 20)) - 1;
  287. doc->erasesize = nand_flash_ids[i].erasesize << doc->interleave;
  288. break;
  289. }
  290. }
  291. if (nand_flash_ids[i].name == NULL)
  292. return 0;
  293. return 1;
  294. }
  295. /* DoC_ScanChips: Find all NAND chips present in a DiskOnChip, and identify them */
  296. static void DoC_ScanChips(struct DiskOnChip *this)
  297. {
  298. int floor, chip;
  299. int numchips[MAX_FLOORS_MPLUS];
  300. int ret;
  301. this->numchips = 0;
  302. this->mfr = 0;
  303. this->id = 0;
  304. /* Work out the intended interleave setting */
  305. this->interleave = 0;
  306. if (this->ChipID == DOC_ChipID_DocMilPlus32)
  307. this->interleave = 1;
  308. /* Check the ASIC agrees */
  309. if ( (this->interleave << 2) !=
  310. (ReadDOC(this->virtadr, Mplus_Configuration) & 4)) {
  311. u_char conf = ReadDOC(this->virtadr, Mplus_Configuration);
  312. printk(KERN_NOTICE "Setting DiskOnChip Millennium Plus interleave to %s\n",
  313. this->interleave?"on (16-bit)":"off (8-bit)");
  314. conf ^= 4;
  315. WriteDOC(conf, this->virtadr, Mplus_Configuration);
  316. }
  317. /* For each floor, find the number of valid chips it contains */
  318. for (floor = 0,ret = 1; floor < MAX_FLOORS_MPLUS; floor++) {
  319. numchips[floor] = 0;
  320. for (chip = 0; chip < MAX_CHIPS_MPLUS && ret != 0; chip++) {
  321. ret = DoC_IdentChip(this, floor, chip);
  322. if (ret) {
  323. numchips[floor]++;
  324. this->numchips++;
  325. }
  326. }
  327. }
  328. /* If there are none at all that we recognise, bail */
  329. if (!this->numchips) {
  330. printk("No flash chips recognised.\n");
  331. return;
  332. }
  333. /* Allocate an array to hold the information for each chip */
  334. this->chips = kmalloc(sizeof(struct Nand) * this->numchips, GFP_KERNEL);
  335. if (!this->chips){
  336. printk("MTD: No memory for allocating chip info structures\n");
  337. return;
  338. }
  339. /* Fill out the chip array with {floor, chipno} for each
  340. * detected chip in the device. */
  341. for (floor = 0, ret = 0; floor < MAX_FLOORS_MPLUS; floor++) {
  342. for (chip = 0 ; chip < numchips[floor] ; chip++) {
  343. this->chips[ret].floor = floor;
  344. this->chips[ret].chip = chip;
  345. this->chips[ret].curadr = 0;
  346. this->chips[ret].curmode = 0x50;
  347. ret++;
  348. }
  349. }
  350. /* Calculate and print the total size of the device */
  351. this->totlen = this->numchips * (1 << this->chipshift);
  352. printk(KERN_INFO "%d flash chips found. Total DiskOnChip size: %ld MiB\n",
  353. this->numchips ,this->totlen >> 20);
  354. }
  355. static int DoCMilPlus_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2)
  356. {
  357. int tmp1, tmp2, retval;
  358. if (doc1->physadr == doc2->physadr)
  359. return 1;
  360. /* Use the alias resolution register which was set aside for this
  361. * purpose. If it's value is the same on both chips, they might
  362. * be the same chip, and we write to one and check for a change in
  363. * the other. It's unclear if this register is usuable in the
  364. * DoC 2000 (it's in the Millennium docs), but it seems to work. */
  365. tmp1 = ReadDOC(doc1->virtadr, Mplus_AliasResolution);
  366. tmp2 = ReadDOC(doc2->virtadr, Mplus_AliasResolution);
  367. if (tmp1 != tmp2)
  368. return 0;
  369. WriteDOC((tmp1+1) % 0xff, doc1->virtadr, Mplus_AliasResolution);
  370. tmp2 = ReadDOC(doc2->virtadr, Mplus_AliasResolution);
  371. if (tmp2 == (tmp1+1) % 0xff)
  372. retval = 1;
  373. else
  374. retval = 0;
  375. /* Restore register contents. May not be necessary, but do it just to
  376. * be safe. */
  377. WriteDOC(tmp1, doc1->virtadr, Mplus_AliasResolution);
  378. return retval;
  379. }
  380. /* This routine is found from the docprobe code by symbol_get(),
  381. * which will bump the use count of this module. */
  382. void DoCMilPlus_init(struct mtd_info *mtd)
  383. {
  384. struct DiskOnChip *this = mtd->priv;
  385. struct DiskOnChip *old = NULL;
  386. /* We must avoid being called twice for the same device. */
  387. if (docmilpluslist)
  388. old = docmilpluslist->priv;
  389. while (old) {
  390. if (DoCMilPlus_is_alias(this, old)) {
  391. printk(KERN_NOTICE "Ignoring DiskOnChip Millennium "
  392. "Plus at 0x%lX - already configured\n",
  393. this->physadr);
  394. iounmap(this->virtadr);
  395. kfree(mtd);
  396. return;
  397. }
  398. if (old->nextdoc)
  399. old = old->nextdoc->priv;
  400. else
  401. old = NULL;
  402. }
  403. mtd->name = "DiskOnChip Millennium Plus";
  404. printk(KERN_NOTICE "DiskOnChip Millennium Plus found at "
  405. "address 0x%lX\n", this->physadr);
  406. mtd->type = MTD_NANDFLASH;
  407. mtd->flags = MTD_CAP_NANDFLASH;
  408. mtd->ecctype = MTD_ECC_RS_DiskOnChip;
  409. mtd->size = 0;
  410. mtd->erasesize = 0;
  411. mtd->writesize = 512;
  412. mtd->oobsize = 16;
  413. mtd->owner = THIS_MODULE;
  414. mtd->erase = doc_erase;
  415. mtd->point = NULL;
  416. mtd->unpoint = NULL;
  417. mtd->read = doc_read;
  418. mtd->write = doc_write;
  419. mtd->read_oob = doc_read_oob;
  420. mtd->write_oob = doc_write_oob;
  421. mtd->sync = NULL;
  422. this->totlen = 0;
  423. this->numchips = 0;
  424. this->curfloor = -1;
  425. this->curchip = -1;
  426. /* Ident all the chips present. */
  427. DoC_ScanChips(this);
  428. if (!this->totlen) {
  429. kfree(mtd);
  430. iounmap(this->virtadr);
  431. } else {
  432. this->nextdoc = docmilpluslist;
  433. docmilpluslist = mtd;
  434. mtd->size = this->totlen;
  435. mtd->erasesize = this->erasesize;
  436. add_mtd_device(mtd);
  437. return;
  438. }
  439. }
  440. EXPORT_SYMBOL_GPL(DoCMilPlus_init);
  441. #if 0
  442. static int doc_dumpblk(struct mtd_info *mtd, loff_t from)
  443. {
  444. int i;
  445. loff_t fofs;
  446. struct DiskOnChip *this = mtd->priv;
  447. void __iomem * docptr = this->virtadr;
  448. struct Nand *mychip = &this->chips[from >> (this->chipshift)];
  449. unsigned char *bp, buf[1056];
  450. char c[32];
  451. from &= ~0x3ff;
  452. /* Don't allow read past end of device */
  453. if (from >= this->totlen)
  454. return -EINVAL;
  455. DoC_CheckASIC(docptr);
  456. /* Find the chip which is to be used and select it */
  457. if (this->curfloor != mychip->floor) {
  458. DoC_SelectFloor(docptr, mychip->floor);
  459. DoC_SelectChip(docptr, mychip->chip);
  460. } else if (this->curchip != mychip->chip) {
  461. DoC_SelectChip(docptr, mychip->chip);
  462. }
  463. this->curfloor = mychip->floor;
  464. this->curchip = mychip->chip;
  465. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  466. WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect);
  467. /* Reset the chip, see Software Requirement 11.4 item 1. */
  468. DoC_Command(docptr, NAND_CMD_RESET, 0);
  469. DoC_WaitReady(docptr);
  470. fofs = from;
  471. DoC_Command(docptr, DoC_GetDataOffset(mtd, &fofs), 0);
  472. DoC_Address(this, 3, fofs, 0, 0x00);
  473. WriteDOC(0, docptr, Mplus_FlashControl);
  474. DoC_WaitReady(docptr);
  475. /* disable the ECC engine */
  476. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  477. ReadDOC(docptr, Mplus_ReadPipeInit);
  478. ReadDOC(docptr, Mplus_ReadPipeInit);
  479. /* Read the data via the internal pipeline through CDSN IO
  480. register, see Pipelined Read Operations 11.3 */
  481. MemReadDOC(docptr, buf, 1054);
  482. buf[1054] = ReadDOC(docptr, Mplus_LastDataRead);
  483. buf[1055] = ReadDOC(docptr, Mplus_LastDataRead);
  484. memset(&c[0], 0, sizeof(c));
  485. printk("DUMP OFFSET=%x:\n", (int)from);
  486. for (i = 0, bp = &buf[0]; (i < 1056); i++) {
  487. if ((i % 16) == 0)
  488. printk("%08x: ", i);
  489. printk(" %02x", *bp);
  490. c[(i & 0xf)] = ((*bp >= 0x20) && (*bp <= 0x7f)) ? *bp : '.';
  491. bp++;
  492. if (((i + 1) % 16) == 0)
  493. printk(" %s\n", c);
  494. }
  495. printk("\n");
  496. /* Disable flash internally */
  497. WriteDOC(0, docptr, Mplus_FlashSelect);
  498. return 0;
  499. }
  500. #endif
  501. static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
  502. size_t *retlen, u_char *buf)
  503. {
  504. /* Just a special case of doc_read_ecc */
  505. return doc_read_ecc(mtd, from, len, retlen, buf, NULL, NULL);
  506. }
  507. static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
  508. size_t *retlen, u_char *buf, u_char *eccbuf,
  509. struct nand_oobinfo *oobsel)
  510. {
  511. int ret, i;
  512. volatile char dummy;
  513. loff_t fofs;
  514. unsigned char syndrome[6];
  515. struct DiskOnChip *this = mtd->priv;
  516. void __iomem * docptr = this->virtadr;
  517. struct Nand *mychip = &this->chips[from >> (this->chipshift)];
  518. /* Don't allow read past end of device */
  519. if (from >= this->totlen)
  520. return -EINVAL;
  521. /* Don't allow a single read to cross a 512-byte block boundary */
  522. if (from + len > ((from | 0x1ff) + 1))
  523. len = ((from | 0x1ff) + 1) - from;
  524. DoC_CheckASIC(docptr);
  525. /* Find the chip which is to be used and select it */
  526. if (this->curfloor != mychip->floor) {
  527. DoC_SelectFloor(docptr, mychip->floor);
  528. DoC_SelectChip(docptr, mychip->chip);
  529. } else if (this->curchip != mychip->chip) {
  530. DoC_SelectChip(docptr, mychip->chip);
  531. }
  532. this->curfloor = mychip->floor;
  533. this->curchip = mychip->chip;
  534. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  535. WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect);
  536. /* Reset the chip, see Software Requirement 11.4 item 1. */
  537. DoC_Command(docptr, NAND_CMD_RESET, 0);
  538. DoC_WaitReady(docptr);
  539. fofs = from;
  540. DoC_Command(docptr, DoC_GetDataOffset(mtd, &fofs), 0);
  541. DoC_Address(this, 3, fofs, 0, 0x00);
  542. WriteDOC(0, docptr, Mplus_FlashControl);
  543. DoC_WaitReady(docptr);
  544. if (eccbuf) {
  545. /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/
  546. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  547. WriteDOC(DOC_ECC_EN, docptr, Mplus_ECCConf);
  548. } else {
  549. /* disable the ECC engine */
  550. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  551. }
  552. /* Let the caller know we completed it */
  553. *retlen = len;
  554. ret = 0;
  555. ReadDOC(docptr, Mplus_ReadPipeInit);
  556. ReadDOC(docptr, Mplus_ReadPipeInit);
  557. if (eccbuf) {
  558. /* Read the data via the internal pipeline through CDSN IO
  559. register, see Pipelined Read Operations 11.3 */
  560. MemReadDOC(docptr, buf, len);
  561. /* Read the ECC data following raw data */
  562. MemReadDOC(docptr, eccbuf, 4);
  563. eccbuf[4] = ReadDOC(docptr, Mplus_LastDataRead);
  564. eccbuf[5] = ReadDOC(docptr, Mplus_LastDataRead);
  565. /* Flush the pipeline */
  566. dummy = ReadDOC(docptr, Mplus_ECCConf);
  567. dummy = ReadDOC(docptr, Mplus_ECCConf);
  568. /* Check the ECC Status */
  569. if (ReadDOC(docptr, Mplus_ECCConf) & 0x80) {
  570. int nb_errors;
  571. /* There was an ECC error */
  572. #ifdef ECC_DEBUG
  573. printk("DiskOnChip ECC Error: Read at %lx\n", (long)from);
  574. #endif
  575. /* Read the ECC syndrom through the DiskOnChip ECC logic.
  576. These syndrome will be all ZERO when there is no error */
  577. for (i = 0; i < 6; i++)
  578. syndrome[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i);
  579. nb_errors = doc_decode_ecc(buf, syndrome);
  580. #ifdef ECC_DEBUG
  581. printk("ECC Errors corrected: %x\n", nb_errors);
  582. #endif
  583. if (nb_errors < 0) {
  584. /* We return error, but have actually done the read. Not that
  585. this can be told to user-space, via sys_read(), but at least
  586. MTD-aware stuff can know about it by checking *retlen */
  587. #ifdef ECC_DEBUG
  588. printk("%s(%d): Millennium Plus ECC error (from=0x%x:\n",
  589. __FILE__, __LINE__, (int)from);
  590. printk(" syndrome= %02x:%02x:%02x:%02x:%02x:"
  591. "%02x\n",
  592. syndrome[0], syndrome[1], syndrome[2],
  593. syndrome[3], syndrome[4], syndrome[5]);
  594. printk(" eccbuf= %02x:%02x:%02x:%02x:%02x:"
  595. "%02x\n",
  596. eccbuf[0], eccbuf[1], eccbuf[2],
  597. eccbuf[3], eccbuf[4], eccbuf[5]);
  598. #endif
  599. ret = -EIO;
  600. }
  601. }
  602. #ifdef PSYCHO_DEBUG
  603. printk("ECC DATA at %lx: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
  604. (long)from, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
  605. eccbuf[4], eccbuf[5]);
  606. #endif
  607. /* disable the ECC engine */
  608. WriteDOC(DOC_ECC_DIS, docptr , Mplus_ECCConf);
  609. } else {
  610. /* Read the data via the internal pipeline through CDSN IO
  611. register, see Pipelined Read Operations 11.3 */
  612. MemReadDOC(docptr, buf, len-2);
  613. buf[len-2] = ReadDOC(docptr, Mplus_LastDataRead);
  614. buf[len-1] = ReadDOC(docptr, Mplus_LastDataRead);
  615. }
  616. /* Disable flash internally */
  617. WriteDOC(0, docptr, Mplus_FlashSelect);
  618. return ret;
  619. }
  620. static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
  621. size_t *retlen, const u_char *buf)
  622. {
  623. char eccbuf[6];
  624. return doc_write_ecc(mtd, to, len, retlen, buf, eccbuf, NULL);
  625. }
  626. static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
  627. size_t *retlen, const u_char *buf, u_char *eccbuf,
  628. struct nand_oobinfo *oobsel)
  629. {
  630. int i, before, ret = 0;
  631. loff_t fto;
  632. volatile char dummy;
  633. struct DiskOnChip *this = mtd->priv;
  634. void __iomem * docptr = this->virtadr;
  635. struct Nand *mychip = &this->chips[to >> (this->chipshift)];
  636. /* Don't allow write past end of device */
  637. if (to >= this->totlen)
  638. return -EINVAL;
  639. /* Don't allow writes which aren't exactly one block (512 bytes) */
  640. if ((to & 0x1ff) || (len != 0x200))
  641. return -EINVAL;
  642. /* Determine position of OOB flags, before or after data */
  643. before = (this->interleave && (to & 0x200));
  644. DoC_CheckASIC(docptr);
  645. /* Find the chip which is to be used and select it */
  646. if (this->curfloor != mychip->floor) {
  647. DoC_SelectFloor(docptr, mychip->floor);
  648. DoC_SelectChip(docptr, mychip->chip);
  649. } else if (this->curchip != mychip->chip) {
  650. DoC_SelectChip(docptr, mychip->chip);
  651. }
  652. this->curfloor = mychip->floor;
  653. this->curchip = mychip->chip;
  654. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  655. WriteDOC(DOC_FLASH_CE, docptr, Mplus_FlashSelect);
  656. /* Reset the chip, see Software Requirement 11.4 item 1. */
  657. DoC_Command(docptr, NAND_CMD_RESET, 0);
  658. DoC_WaitReady(docptr);
  659. /* Set device to appropriate plane of flash */
  660. fto = to;
  661. WriteDOC(DoC_GetDataOffset(mtd, &fto), docptr, Mplus_FlashCmd);
  662. /* On interleaved devices the flags for 2nd half 512 are before data */
  663. if (eccbuf && before)
  664. fto -= 2;
  665. /* issue the Serial Data In command to initial the Page Program process */
  666. DoC_Command(docptr, NAND_CMD_SEQIN, 0x00);
  667. DoC_Address(this, 3, fto, 0x00, 0x00);
  668. /* Disable the ECC engine */
  669. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  670. if (eccbuf) {
  671. if (before) {
  672. /* Write the block status BLOCK_USED (0x5555) */
  673. WriteDOC(0x55, docptr, Mil_CDSN_IO);
  674. WriteDOC(0x55, docptr, Mil_CDSN_IO);
  675. }
  676. /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/
  677. WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, Mplus_ECCConf);
  678. }
  679. MemWriteDOC(docptr, (unsigned char *) buf, len);
  680. if (eccbuf) {
  681. /* Write ECC data to flash, the ECC info is generated by
  682. the DiskOnChip ECC logic see Reed-Solomon EDC/ECC 11.1 */
  683. DoC_Delay(docptr, 3);
  684. /* Read the ECC data through the DiskOnChip ECC logic */
  685. for (i = 0; i < 6; i++)
  686. eccbuf[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i);
  687. /* disable the ECC engine */
  688. WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf);
  689. /* Write the ECC data to flash */
  690. MemWriteDOC(docptr, eccbuf, 6);
  691. if (!before) {
  692. /* Write the block status BLOCK_USED (0x5555) */
  693. WriteDOC(0x55, docptr, Mil_CDSN_IO+6);
  694. WriteDOC(0x55, docptr, Mil_CDSN_IO+7);
  695. }
  696. #ifdef PSYCHO_DEBUG
  697. printk("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
  698. (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
  699. eccbuf[4], eccbuf[5]);
  700. #endif
  701. }
  702. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  703. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  704. /* Commit the Page Program command and wait for ready
  705. see Software Requirement 11.4 item 1.*/
  706. DoC_Command(docptr, NAND_CMD_PAGEPROG, 0x00);
  707. DoC_WaitReady(docptr);
  708. /* Read the status of the flash device through CDSN IO register
  709. see Software Requirement 11.4 item 5.*/
  710. DoC_Command(docptr, NAND_CMD_STATUS, 0);
  711. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  712. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  713. DoC_Delay(docptr, 2);
  714. if ((dummy = ReadDOC(docptr, Mplus_LastDataRead)) & 1) {
  715. printk("MTD: Error 0x%x programming at 0x%x\n", dummy, (int)to);
  716. /* Error in programming
  717. FIXME: implement Bad Block Replacement (in nftl.c ??) */
  718. *retlen = 0;
  719. ret = -EIO;
  720. }
  721. dummy = ReadDOC(docptr, Mplus_LastDataRead);
  722. /* Disable flash internally */
  723. WriteDOC(0, docptr, Mplus_FlashSelect);
  724. /* Let the caller know we completed it */
  725. *retlen = len;
  726. return ret;
  727. }
  728. static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
  729. struct mtd_oob_ops *ops)
  730. {
  731. loff_t fofs, base;
  732. struct DiskOnChip *this = mtd->priv;
  733. void __iomem * docptr = this->virtadr;
  734. struct Nand *mychip = &this->chips[ofs >> this->chipshift];
  735. size_t i, size, got, want;
  736. uint8_t *buf = ops->oobbuf;
  737. size_t len = ops->len;
  738. BUG_ON(ops->mode != MTD_OOB_PLACE);
  739. ofs += ops->ooboffs;
  740. DoC_CheckASIC(docptr);
  741. /* Find the chip which is to be used and select it */
  742. if (this->curfloor != mychip->floor) {
  743. DoC_SelectFloor(docptr, mychip->floor);
  744. DoC_SelectChip(docptr, mychip->chip);
  745. } else if (this->curchip != mychip->chip) {
  746. DoC_SelectChip(docptr, mychip->chip);
  747. }
  748. this->curfloor = mychip->floor;
  749. this->curchip = mychip->chip;
  750. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  751. WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect);
  752. /* disable the ECC engine */
  753. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  754. DoC_WaitReady(docptr);
  755. /* Maximum of 16 bytes in the OOB region, so limit read to that */
  756. if (len > 16)
  757. len = 16;
  758. got = 0;
  759. want = len;
  760. for (i = 0; ((i < 3) && (want > 0)); i++) {
  761. /* Figure out which region we are accessing... */
  762. fofs = ofs;
  763. base = ofs & 0xf;
  764. if (!this->interleave) {
  765. DoC_Command(docptr, NAND_CMD_READOOB, 0);
  766. size = 16 - base;
  767. } else if (base < 6) {
  768. DoC_Command(docptr, DoC_GetECCOffset(mtd, &fofs), 0);
  769. size = 6 - base;
  770. } else if (base < 8) {
  771. DoC_Command(docptr, DoC_GetFlagsOffset(mtd, &fofs), 0);
  772. size = 8 - base;
  773. } else {
  774. DoC_Command(docptr, DoC_GetHdrOffset(mtd, &fofs), 0);
  775. size = 16 - base;
  776. }
  777. if (size > want)
  778. size = want;
  779. /* Issue read command */
  780. DoC_Address(this, 3, fofs, 0, 0x00);
  781. WriteDOC(0, docptr, Mplus_FlashControl);
  782. DoC_WaitReady(docptr);
  783. ReadDOC(docptr, Mplus_ReadPipeInit);
  784. ReadDOC(docptr, Mplus_ReadPipeInit);
  785. MemReadDOC(docptr, &buf[got], size - 2);
  786. buf[got + size - 2] = ReadDOC(docptr, Mplus_LastDataRead);
  787. buf[got + size - 1] = ReadDOC(docptr, Mplus_LastDataRead);
  788. ofs += size;
  789. got += size;
  790. want -= size;
  791. }
  792. /* Disable flash internally */
  793. WriteDOC(0, docptr, Mplus_FlashSelect);
  794. ops->retlen = len;
  795. return 0;
  796. }
  797. static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
  798. struct mtd_oob_ops *ops)
  799. {
  800. volatile char dummy;
  801. loff_t fofs, base;
  802. struct DiskOnChip *this = mtd->priv;
  803. void __iomem * docptr = this->virtadr;
  804. struct Nand *mychip = &this->chips[ofs >> this->chipshift];
  805. size_t i, size, got, want;
  806. int ret = 0;
  807. uint8_t *buf = ops->oobbuf;
  808. size_t len = ops->len;
  809. BUG_ON(ops->mode != MTD_OOB_PLACE);
  810. ofs += ops->ooboffs;
  811. DoC_CheckASIC(docptr);
  812. /* Find the chip which is to be used and select it */
  813. if (this->curfloor != mychip->floor) {
  814. DoC_SelectFloor(docptr, mychip->floor);
  815. DoC_SelectChip(docptr, mychip->chip);
  816. } else if (this->curchip != mychip->chip) {
  817. DoC_SelectChip(docptr, mychip->chip);
  818. }
  819. this->curfloor = mychip->floor;
  820. this->curchip = mychip->chip;
  821. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  822. WriteDOC(DOC_FLASH_CE, docptr, Mplus_FlashSelect);
  823. /* Maximum of 16 bytes in the OOB region, so limit write to that */
  824. if (len > 16)
  825. len = 16;
  826. got = 0;
  827. want = len;
  828. for (i = 0; ((i < 3) && (want > 0)); i++) {
  829. /* Reset the chip, see Software Requirement 11.4 item 1. */
  830. DoC_Command(docptr, NAND_CMD_RESET, 0);
  831. DoC_WaitReady(docptr);
  832. /* Figure out which region we are accessing... */
  833. fofs = ofs;
  834. base = ofs & 0x0f;
  835. if (!this->interleave) {
  836. WriteDOC(NAND_CMD_READOOB, docptr, Mplus_FlashCmd);
  837. size = 16 - base;
  838. } else if (base < 6) {
  839. WriteDOC(DoC_GetECCOffset(mtd, &fofs), docptr, Mplus_FlashCmd);
  840. size = 6 - base;
  841. } else if (base < 8) {
  842. WriteDOC(DoC_GetFlagsOffset(mtd, &fofs), docptr, Mplus_FlashCmd);
  843. size = 8 - base;
  844. } else {
  845. WriteDOC(DoC_GetHdrOffset(mtd, &fofs), docptr, Mplus_FlashCmd);
  846. size = 16 - base;
  847. }
  848. if (size > want)
  849. size = want;
  850. /* Issue the Serial Data In command to initial the Page Program process */
  851. DoC_Command(docptr, NAND_CMD_SEQIN, 0x00);
  852. DoC_Address(this, 3, fofs, 0, 0x00);
  853. /* Disable the ECC engine */
  854. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  855. /* Write the data via the internal pipeline through CDSN IO
  856. register, see Pipelined Write Operations 11.2 */
  857. MemWriteDOC(docptr, (unsigned char *) &buf[got], size);
  858. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  859. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  860. /* Commit the Page Program command and wait for ready
  861. see Software Requirement 11.4 item 1.*/
  862. DoC_Command(docptr, NAND_CMD_PAGEPROG, 0x00);
  863. DoC_WaitReady(docptr);
  864. /* Read the status of the flash device through CDSN IO register
  865. see Software Requirement 11.4 item 5.*/
  866. DoC_Command(docptr, NAND_CMD_STATUS, 0x00);
  867. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  868. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  869. DoC_Delay(docptr, 2);
  870. if ((dummy = ReadDOC(docptr, Mplus_LastDataRead)) & 1) {
  871. printk("MTD: Error 0x%x programming oob at 0x%x\n",
  872. dummy, (int)ofs);
  873. /* FIXME: implement Bad Block Replacement */
  874. ops->retlen = 0;
  875. ret = -EIO;
  876. }
  877. dummy = ReadDOC(docptr, Mplus_LastDataRead);
  878. ofs += size;
  879. got += size;
  880. want -= size;
  881. }
  882. /* Disable flash internally */
  883. WriteDOC(0, docptr, Mplus_FlashSelect);
  884. ops->retlen = len;
  885. return ret;
  886. }
  887. int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
  888. {
  889. volatile char dummy;
  890. struct DiskOnChip *this = mtd->priv;
  891. __u32 ofs = instr->addr;
  892. __u32 len = instr->len;
  893. void __iomem * docptr = this->virtadr;
  894. struct Nand *mychip = &this->chips[ofs >> this->chipshift];
  895. DoC_CheckASIC(docptr);
  896. if (len != mtd->erasesize)
  897. printk(KERN_WARNING "MTD: Erase not right size (%x != %x)n",
  898. len, mtd->erasesize);
  899. /* Find the chip which is to be used and select it */
  900. if (this->curfloor != mychip->floor) {
  901. DoC_SelectFloor(docptr, mychip->floor);
  902. DoC_SelectChip(docptr, mychip->chip);
  903. } else if (this->curchip != mychip->chip) {
  904. DoC_SelectChip(docptr, mychip->chip);
  905. }
  906. this->curfloor = mychip->floor;
  907. this->curchip = mychip->chip;
  908. instr->state = MTD_ERASE_PENDING;
  909. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  910. WriteDOC(DOC_FLASH_CE, docptr, Mplus_FlashSelect);
  911. DoC_Command(docptr, NAND_CMD_RESET, 0x00);
  912. DoC_WaitReady(docptr);
  913. DoC_Command(docptr, NAND_CMD_ERASE1, 0);
  914. DoC_Address(this, 2, ofs, 0, 0x00);
  915. DoC_Command(docptr, NAND_CMD_ERASE2, 0);
  916. DoC_WaitReady(docptr);
  917. instr->state = MTD_ERASING;
  918. /* Read the status of the flash device through CDSN IO register
  919. see Software Requirement 11.4 item 5. */
  920. DoC_Command(docptr, NAND_CMD_STATUS, 0);
  921. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  922. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  923. if ((dummy = ReadDOC(docptr, Mplus_LastDataRead)) & 1) {
  924. printk("MTD: Error 0x%x erasing at 0x%x\n", dummy, ofs);
  925. /* FIXME: implement Bad Block Replacement (in nftl.c ??) */
  926. instr->state = MTD_ERASE_FAILED;
  927. } else {
  928. instr->state = MTD_ERASE_DONE;
  929. }
  930. dummy = ReadDOC(docptr, Mplus_LastDataRead);
  931. /* Disable flash internally */
  932. WriteDOC(0, docptr, Mplus_FlashSelect);
  933. mtd_erase_callback(instr);
  934. return 0;
  935. }
  936. /****************************************************************************
  937. *
  938. * Module stuff
  939. *
  940. ****************************************************************************/
  941. static void __exit cleanup_doc2001plus(void)
  942. {
  943. struct mtd_info *mtd;
  944. struct DiskOnChip *this;
  945. while ((mtd=docmilpluslist)) {
  946. this = mtd->priv;
  947. docmilpluslist = this->nextdoc;
  948. del_mtd_device(mtd);
  949. iounmap(this->virtadr);
  950. kfree(this->chips);
  951. kfree(mtd);
  952. }
  953. }
  954. module_exit(cleanup_doc2001plus);
  955. MODULE_LICENSE("GPL");
  956. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com> et al.");
  957. MODULE_DESCRIPTION("Driver for DiskOnChip Millennium Plus");