doc2001plus.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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, size_t len,
  46. size_t *retlen, u_char *buf);
  47. static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
  48. size_t *retlen, const u_char *buf);
  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->oobblock = 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_ecc = doc_read_ecc;
  420. mtd->write_ecc = doc_write_ecc;
  421. mtd->read_oob = doc_read_oob;
  422. mtd->write_oob = doc_write_oob;
  423. mtd->sync = NULL;
  424. this->totlen = 0;
  425. this->numchips = 0;
  426. this->curfloor = -1;
  427. this->curchip = -1;
  428. /* Ident all the chips present. */
  429. DoC_ScanChips(this);
  430. if (!this->totlen) {
  431. kfree(mtd);
  432. iounmap(this->virtadr);
  433. } else {
  434. this->nextdoc = docmilpluslist;
  435. docmilpluslist = mtd;
  436. mtd->size = this->totlen;
  437. mtd->erasesize = this->erasesize;
  438. add_mtd_device(mtd);
  439. return;
  440. }
  441. }
  442. EXPORT_SYMBOL_GPL(DoCMilPlus_init);
  443. #if 0
  444. static int doc_dumpblk(struct mtd_info *mtd, loff_t from)
  445. {
  446. int i;
  447. loff_t fofs;
  448. struct DiskOnChip *this = mtd->priv;
  449. void __iomem * docptr = this->virtadr;
  450. struct Nand *mychip = &this->chips[from >> (this->chipshift)];
  451. unsigned char *bp, buf[1056];
  452. char c[32];
  453. from &= ~0x3ff;
  454. /* Don't allow read past end of device */
  455. if (from >= this->totlen)
  456. return -EINVAL;
  457. DoC_CheckASIC(docptr);
  458. /* Find the chip which is to be used and select it */
  459. if (this->curfloor != mychip->floor) {
  460. DoC_SelectFloor(docptr, mychip->floor);
  461. DoC_SelectChip(docptr, mychip->chip);
  462. } else if (this->curchip != mychip->chip) {
  463. DoC_SelectChip(docptr, mychip->chip);
  464. }
  465. this->curfloor = mychip->floor;
  466. this->curchip = mychip->chip;
  467. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  468. WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect);
  469. /* Reset the chip, see Software Requirement 11.4 item 1. */
  470. DoC_Command(docptr, NAND_CMD_RESET, 0);
  471. DoC_WaitReady(docptr);
  472. fofs = from;
  473. DoC_Command(docptr, DoC_GetDataOffset(mtd, &fofs), 0);
  474. DoC_Address(this, 3, fofs, 0, 0x00);
  475. WriteDOC(0, docptr, Mplus_FlashControl);
  476. DoC_WaitReady(docptr);
  477. /* disable the ECC engine */
  478. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  479. ReadDOC(docptr, Mplus_ReadPipeInit);
  480. ReadDOC(docptr, Mplus_ReadPipeInit);
  481. /* Read the data via the internal pipeline through CDSN IO
  482. register, see Pipelined Read Operations 11.3 */
  483. MemReadDOC(docptr, buf, 1054);
  484. buf[1054] = ReadDOC(docptr, Mplus_LastDataRead);
  485. buf[1055] = ReadDOC(docptr, Mplus_LastDataRead);
  486. memset(&c[0], 0, sizeof(c));
  487. printk("DUMP OFFSET=%x:\n", (int)from);
  488. for (i = 0, bp = &buf[0]; (i < 1056); i++) {
  489. if ((i % 16) == 0)
  490. printk("%08x: ", i);
  491. printk(" %02x", *bp);
  492. c[(i & 0xf)] = ((*bp >= 0x20) && (*bp <= 0x7f)) ? *bp : '.';
  493. bp++;
  494. if (((i + 1) % 16) == 0)
  495. printk(" %s\n", c);
  496. }
  497. printk("\n");
  498. /* Disable flash internally */
  499. WriteDOC(0, docptr, Mplus_FlashSelect);
  500. return 0;
  501. }
  502. #endif
  503. static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
  504. size_t *retlen, u_char *buf)
  505. {
  506. /* Just a special case of doc_read_ecc */
  507. return doc_read_ecc(mtd, from, len, retlen, buf, NULL, NULL);
  508. }
  509. static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
  510. size_t *retlen, u_char *buf, u_char *eccbuf,
  511. struct nand_oobinfo *oobsel)
  512. {
  513. int ret, i;
  514. volatile char dummy;
  515. loff_t fofs;
  516. unsigned char syndrome[6];
  517. struct DiskOnChip *this = mtd->priv;
  518. void __iomem * docptr = this->virtadr;
  519. struct Nand *mychip = &this->chips[from >> (this->chipshift)];
  520. /* Don't allow read past end of device */
  521. if (from >= this->totlen)
  522. return -EINVAL;
  523. /* Don't allow a single read to cross a 512-byte block boundary */
  524. if (from + len > ((from | 0x1ff) + 1))
  525. len = ((from | 0x1ff) + 1) - from;
  526. DoC_CheckASIC(docptr);
  527. /* Find the chip which is to be used and select it */
  528. if (this->curfloor != mychip->floor) {
  529. DoC_SelectFloor(docptr, mychip->floor);
  530. DoC_SelectChip(docptr, mychip->chip);
  531. } else if (this->curchip != mychip->chip) {
  532. DoC_SelectChip(docptr, mychip->chip);
  533. }
  534. this->curfloor = mychip->floor;
  535. this->curchip = mychip->chip;
  536. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  537. WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect);
  538. /* Reset the chip, see Software Requirement 11.4 item 1. */
  539. DoC_Command(docptr, NAND_CMD_RESET, 0);
  540. DoC_WaitReady(docptr);
  541. fofs = from;
  542. DoC_Command(docptr, DoC_GetDataOffset(mtd, &fofs), 0);
  543. DoC_Address(this, 3, fofs, 0, 0x00);
  544. WriteDOC(0, docptr, Mplus_FlashControl);
  545. DoC_WaitReady(docptr);
  546. if (eccbuf) {
  547. /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/
  548. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  549. WriteDOC(DOC_ECC_EN, docptr, Mplus_ECCConf);
  550. } else {
  551. /* disable the ECC engine */
  552. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  553. }
  554. /* Let the caller know we completed it */
  555. *retlen = len;
  556. ret = 0;
  557. ReadDOC(docptr, Mplus_ReadPipeInit);
  558. ReadDOC(docptr, Mplus_ReadPipeInit);
  559. if (eccbuf) {
  560. /* Read the data via the internal pipeline through CDSN IO
  561. register, see Pipelined Read Operations 11.3 */
  562. MemReadDOC(docptr, buf, len);
  563. /* Read the ECC data following raw data */
  564. MemReadDOC(docptr, eccbuf, 4);
  565. eccbuf[4] = ReadDOC(docptr, Mplus_LastDataRead);
  566. eccbuf[5] = ReadDOC(docptr, Mplus_LastDataRead);
  567. /* Flush the pipeline */
  568. dummy = ReadDOC(docptr, Mplus_ECCConf);
  569. dummy = ReadDOC(docptr, Mplus_ECCConf);
  570. /* Check the ECC Status */
  571. if (ReadDOC(docptr, Mplus_ECCConf) & 0x80) {
  572. int nb_errors;
  573. /* There was an ECC error */
  574. #ifdef ECC_DEBUG
  575. printk("DiskOnChip ECC Error: Read at %lx\n", (long)from);
  576. #endif
  577. /* Read the ECC syndrom through the DiskOnChip ECC logic.
  578. These syndrome will be all ZERO when there is no error */
  579. for (i = 0; i < 6; i++)
  580. syndrome[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i);
  581. nb_errors = doc_decode_ecc(buf, syndrome);
  582. #ifdef ECC_DEBUG
  583. printk("ECC Errors corrected: %x\n", nb_errors);
  584. #endif
  585. if (nb_errors < 0) {
  586. /* We return error, but have actually done the read. Not that
  587. this can be told to user-space, via sys_read(), but at least
  588. MTD-aware stuff can know about it by checking *retlen */
  589. #ifdef ECC_DEBUG
  590. printk("%s(%d): Millennium Plus ECC error (from=0x%x:\n",
  591. __FILE__, __LINE__, (int)from);
  592. printk(" syndrome= %02x:%02x:%02x:%02x:%02x:"
  593. "%02x\n",
  594. syndrome[0], syndrome[1], syndrome[2],
  595. syndrome[3], syndrome[4], syndrome[5]);
  596. printk(" eccbuf= %02x:%02x:%02x:%02x:%02x:"
  597. "%02x\n",
  598. eccbuf[0], eccbuf[1], eccbuf[2],
  599. eccbuf[3], eccbuf[4], eccbuf[5]);
  600. #endif
  601. ret = -EIO;
  602. }
  603. }
  604. #ifdef PSYCHO_DEBUG
  605. printk("ECC DATA at %lx: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
  606. (long)from, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
  607. eccbuf[4], eccbuf[5]);
  608. #endif
  609. /* disable the ECC engine */
  610. WriteDOC(DOC_ECC_DIS, docptr , Mplus_ECCConf);
  611. } else {
  612. /* Read the data via the internal pipeline through CDSN IO
  613. register, see Pipelined Read Operations 11.3 */
  614. MemReadDOC(docptr, buf, len-2);
  615. buf[len-2] = ReadDOC(docptr, Mplus_LastDataRead);
  616. buf[len-1] = ReadDOC(docptr, Mplus_LastDataRead);
  617. }
  618. /* Disable flash internally */
  619. WriteDOC(0, docptr, Mplus_FlashSelect);
  620. return ret;
  621. }
  622. static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
  623. size_t *retlen, const u_char *buf)
  624. {
  625. char eccbuf[6];
  626. return doc_write_ecc(mtd, to, len, retlen, buf, eccbuf, NULL);
  627. }
  628. static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
  629. size_t *retlen, const u_char *buf, u_char *eccbuf,
  630. struct nand_oobinfo *oobsel)
  631. {
  632. int i, before, ret = 0;
  633. loff_t fto;
  634. volatile char dummy;
  635. struct DiskOnChip *this = mtd->priv;
  636. void __iomem * docptr = this->virtadr;
  637. struct Nand *mychip = &this->chips[to >> (this->chipshift)];
  638. /* Don't allow write past end of device */
  639. if (to >= this->totlen)
  640. return -EINVAL;
  641. /* Don't allow writes which aren't exactly one block (512 bytes) */
  642. if ((to & 0x1ff) || (len != 0x200))
  643. return -EINVAL;
  644. /* Determine position of OOB flags, before or after data */
  645. before = (this->interleave && (to & 0x200));
  646. DoC_CheckASIC(docptr);
  647. /* Find the chip which is to be used and select it */
  648. if (this->curfloor != mychip->floor) {
  649. DoC_SelectFloor(docptr, mychip->floor);
  650. DoC_SelectChip(docptr, mychip->chip);
  651. } else if (this->curchip != mychip->chip) {
  652. DoC_SelectChip(docptr, mychip->chip);
  653. }
  654. this->curfloor = mychip->floor;
  655. this->curchip = mychip->chip;
  656. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  657. WriteDOC(DOC_FLASH_CE, docptr, Mplus_FlashSelect);
  658. /* Reset the chip, see Software Requirement 11.4 item 1. */
  659. DoC_Command(docptr, NAND_CMD_RESET, 0);
  660. DoC_WaitReady(docptr);
  661. /* Set device to appropriate plane of flash */
  662. fto = to;
  663. WriteDOC(DoC_GetDataOffset(mtd, &fto), docptr, Mplus_FlashCmd);
  664. /* On interleaved devices the flags for 2nd half 512 are before data */
  665. if (eccbuf && before)
  666. fto -= 2;
  667. /* issue the Serial Data In command to initial the Page Program process */
  668. DoC_Command(docptr, NAND_CMD_SEQIN, 0x00);
  669. DoC_Address(this, 3, fto, 0x00, 0x00);
  670. /* Disable the ECC engine */
  671. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  672. if (eccbuf) {
  673. if (before) {
  674. /* Write the block status BLOCK_USED (0x5555) */
  675. WriteDOC(0x55, docptr, Mil_CDSN_IO);
  676. WriteDOC(0x55, docptr, Mil_CDSN_IO);
  677. }
  678. /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/
  679. WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, Mplus_ECCConf);
  680. }
  681. MemWriteDOC(docptr, (unsigned char *) buf, len);
  682. if (eccbuf) {
  683. /* Write ECC data to flash, the ECC info is generated by
  684. the DiskOnChip ECC logic see Reed-Solomon EDC/ECC 11.1 */
  685. DoC_Delay(docptr, 3);
  686. /* Read the ECC data through the DiskOnChip ECC logic */
  687. for (i = 0; i < 6; i++)
  688. eccbuf[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i);
  689. /* disable the ECC engine */
  690. WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf);
  691. /* Write the ECC data to flash */
  692. MemWriteDOC(docptr, eccbuf, 6);
  693. if (!before) {
  694. /* Write the block status BLOCK_USED (0x5555) */
  695. WriteDOC(0x55, docptr, Mil_CDSN_IO+6);
  696. WriteDOC(0x55, docptr, Mil_CDSN_IO+7);
  697. }
  698. #ifdef PSYCHO_DEBUG
  699. printk("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
  700. (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
  701. eccbuf[4], eccbuf[5]);
  702. #endif
  703. }
  704. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  705. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  706. /* Commit the Page Program command and wait for ready
  707. see Software Requirement 11.4 item 1.*/
  708. DoC_Command(docptr, NAND_CMD_PAGEPROG, 0x00);
  709. DoC_WaitReady(docptr);
  710. /* Read the status of the flash device through CDSN IO register
  711. see Software Requirement 11.4 item 5.*/
  712. DoC_Command(docptr, NAND_CMD_STATUS, 0);
  713. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  714. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  715. DoC_Delay(docptr, 2);
  716. if ((dummy = ReadDOC(docptr, Mplus_LastDataRead)) & 1) {
  717. printk("MTD: Error 0x%x programming at 0x%x\n", dummy, (int)to);
  718. /* Error in programming
  719. FIXME: implement Bad Block Replacement (in nftl.c ??) */
  720. *retlen = 0;
  721. ret = -EIO;
  722. }
  723. dummy = ReadDOC(docptr, Mplus_LastDataRead);
  724. /* Disable flash internally */
  725. WriteDOC(0, docptr, Mplus_FlashSelect);
  726. /* Let the caller know we completed it */
  727. *retlen = len;
  728. return ret;
  729. }
  730. static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
  731. size_t *retlen, u_char *buf)
  732. {
  733. loff_t fofs, base;
  734. struct DiskOnChip *this = mtd->priv;
  735. void __iomem * docptr = this->virtadr;
  736. struct Nand *mychip = &this->chips[ofs >> this->chipshift];
  737. size_t i, size, got, want;
  738. DoC_CheckASIC(docptr);
  739. /* Find the chip which is to be used and select it */
  740. if (this->curfloor != mychip->floor) {
  741. DoC_SelectFloor(docptr, mychip->floor);
  742. DoC_SelectChip(docptr, mychip->chip);
  743. } else if (this->curchip != mychip->chip) {
  744. DoC_SelectChip(docptr, mychip->chip);
  745. }
  746. this->curfloor = mychip->floor;
  747. this->curchip = mychip->chip;
  748. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  749. WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect);
  750. /* disable the ECC engine */
  751. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  752. DoC_WaitReady(docptr);
  753. /* Maximum of 16 bytes in the OOB region, so limit read to that */
  754. if (len > 16)
  755. len = 16;
  756. got = 0;
  757. want = len;
  758. for (i = 0; ((i < 3) && (want > 0)); i++) {
  759. /* Figure out which region we are accessing... */
  760. fofs = ofs;
  761. base = ofs & 0xf;
  762. if (!this->interleave) {
  763. DoC_Command(docptr, NAND_CMD_READOOB, 0);
  764. size = 16 - base;
  765. } else if (base < 6) {
  766. DoC_Command(docptr, DoC_GetECCOffset(mtd, &fofs), 0);
  767. size = 6 - base;
  768. } else if (base < 8) {
  769. DoC_Command(docptr, DoC_GetFlagsOffset(mtd, &fofs), 0);
  770. size = 8 - base;
  771. } else {
  772. DoC_Command(docptr, DoC_GetHdrOffset(mtd, &fofs), 0);
  773. size = 16 - base;
  774. }
  775. if (size > want)
  776. size = want;
  777. /* Issue read command */
  778. DoC_Address(this, 3, fofs, 0, 0x00);
  779. WriteDOC(0, docptr, Mplus_FlashControl);
  780. DoC_WaitReady(docptr);
  781. ReadDOC(docptr, Mplus_ReadPipeInit);
  782. ReadDOC(docptr, Mplus_ReadPipeInit);
  783. MemReadDOC(docptr, &buf[got], size - 2);
  784. buf[got + size - 2] = ReadDOC(docptr, Mplus_LastDataRead);
  785. buf[got + size - 1] = ReadDOC(docptr, Mplus_LastDataRead);
  786. ofs += size;
  787. got += size;
  788. want -= size;
  789. }
  790. /* Disable flash internally */
  791. WriteDOC(0, docptr, Mplus_FlashSelect);
  792. *retlen = len;
  793. return 0;
  794. }
  795. static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
  796. size_t *retlen, const u_char *buf)
  797. {
  798. volatile char dummy;
  799. loff_t fofs, base;
  800. struct DiskOnChip *this = mtd->priv;
  801. void __iomem * docptr = this->virtadr;
  802. struct Nand *mychip = &this->chips[ofs >> this->chipshift];
  803. size_t i, size, got, want;
  804. int ret = 0;
  805. DoC_CheckASIC(docptr);
  806. /* Find the chip which is to be used and select it */
  807. if (this->curfloor != mychip->floor) {
  808. DoC_SelectFloor(docptr, mychip->floor);
  809. DoC_SelectChip(docptr, mychip->chip);
  810. } else if (this->curchip != mychip->chip) {
  811. DoC_SelectChip(docptr, mychip->chip);
  812. }
  813. this->curfloor = mychip->floor;
  814. this->curchip = mychip->chip;
  815. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  816. WriteDOC(DOC_FLASH_CE, docptr, Mplus_FlashSelect);
  817. /* Maximum of 16 bytes in the OOB region, so limit write to that */
  818. if (len > 16)
  819. len = 16;
  820. got = 0;
  821. want = len;
  822. for (i = 0; ((i < 3) && (want > 0)); i++) {
  823. /* Reset the chip, see Software Requirement 11.4 item 1. */
  824. DoC_Command(docptr, NAND_CMD_RESET, 0);
  825. DoC_WaitReady(docptr);
  826. /* Figure out which region we are accessing... */
  827. fofs = ofs;
  828. base = ofs & 0x0f;
  829. if (!this->interleave) {
  830. WriteDOC(NAND_CMD_READOOB, docptr, Mplus_FlashCmd);
  831. size = 16 - base;
  832. } else if (base < 6) {
  833. WriteDOC(DoC_GetECCOffset(mtd, &fofs), docptr, Mplus_FlashCmd);
  834. size = 6 - base;
  835. } else if (base < 8) {
  836. WriteDOC(DoC_GetFlagsOffset(mtd, &fofs), docptr, Mplus_FlashCmd);
  837. size = 8 - base;
  838. } else {
  839. WriteDOC(DoC_GetHdrOffset(mtd, &fofs), docptr, Mplus_FlashCmd);
  840. size = 16 - base;
  841. }
  842. if (size > want)
  843. size = want;
  844. /* Issue the Serial Data In command to initial the Page Program process */
  845. DoC_Command(docptr, NAND_CMD_SEQIN, 0x00);
  846. DoC_Address(this, 3, fofs, 0, 0x00);
  847. /* Disable the ECC engine */
  848. WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf);
  849. /* Write the data via the internal pipeline through CDSN IO
  850. register, see Pipelined Write Operations 11.2 */
  851. MemWriteDOC(docptr, (unsigned char *) &buf[got], size);
  852. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  853. WriteDOC(0x00, docptr, Mplus_WritePipeTerm);
  854. /* Commit the Page Program command and wait for ready
  855. see Software Requirement 11.4 item 1.*/
  856. DoC_Command(docptr, NAND_CMD_PAGEPROG, 0x00);
  857. DoC_WaitReady(docptr);
  858. /* Read the status of the flash device through CDSN IO register
  859. see Software Requirement 11.4 item 5.*/
  860. DoC_Command(docptr, NAND_CMD_STATUS, 0x00);
  861. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  862. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  863. DoC_Delay(docptr, 2);
  864. if ((dummy = ReadDOC(docptr, Mplus_LastDataRead)) & 1) {
  865. printk("MTD: Error 0x%x programming oob at 0x%x\n",
  866. dummy, (int)ofs);
  867. /* FIXME: implement Bad Block Replacement */
  868. *retlen = 0;
  869. ret = -EIO;
  870. }
  871. dummy = ReadDOC(docptr, Mplus_LastDataRead);
  872. ofs += size;
  873. got += size;
  874. want -= size;
  875. }
  876. /* Disable flash internally */
  877. WriteDOC(0, docptr, Mplus_FlashSelect);
  878. *retlen = len;
  879. return ret;
  880. }
  881. int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
  882. {
  883. volatile char dummy;
  884. struct DiskOnChip *this = mtd->priv;
  885. __u32 ofs = instr->addr;
  886. __u32 len = instr->len;
  887. void __iomem * docptr = this->virtadr;
  888. struct Nand *mychip = &this->chips[ofs >> this->chipshift];
  889. DoC_CheckASIC(docptr);
  890. if (len != mtd->erasesize)
  891. printk(KERN_WARNING "MTD: Erase not right size (%x != %x)n",
  892. len, mtd->erasesize);
  893. /* Find the chip which is to be used and select it */
  894. if (this->curfloor != mychip->floor) {
  895. DoC_SelectFloor(docptr, mychip->floor);
  896. DoC_SelectChip(docptr, mychip->chip);
  897. } else if (this->curchip != mychip->chip) {
  898. DoC_SelectChip(docptr, mychip->chip);
  899. }
  900. this->curfloor = mychip->floor;
  901. this->curchip = mychip->chip;
  902. instr->state = MTD_ERASE_PENDING;
  903. /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */
  904. WriteDOC(DOC_FLASH_CE, docptr, Mplus_FlashSelect);
  905. DoC_Command(docptr, NAND_CMD_RESET, 0x00);
  906. DoC_WaitReady(docptr);
  907. DoC_Command(docptr, NAND_CMD_ERASE1, 0);
  908. DoC_Address(this, 2, ofs, 0, 0x00);
  909. DoC_Command(docptr, NAND_CMD_ERASE2, 0);
  910. DoC_WaitReady(docptr);
  911. instr->state = MTD_ERASING;
  912. /* Read the status of the flash device through CDSN IO register
  913. see Software Requirement 11.4 item 5. */
  914. DoC_Command(docptr, NAND_CMD_STATUS, 0);
  915. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  916. dummy = ReadDOC(docptr, Mplus_ReadPipeInit);
  917. if ((dummy = ReadDOC(docptr, Mplus_LastDataRead)) & 1) {
  918. printk("MTD: Error 0x%x erasing at 0x%x\n", dummy, ofs);
  919. /* FIXME: implement Bad Block Replacement (in nftl.c ??) */
  920. instr->state = MTD_ERASE_FAILED;
  921. } else {
  922. instr->state = MTD_ERASE_DONE;
  923. }
  924. dummy = ReadDOC(docptr, Mplus_LastDataRead);
  925. /* Disable flash internally */
  926. WriteDOC(0, docptr, Mplus_FlashSelect);
  927. mtd_erase_callback(instr);
  928. return 0;
  929. }
  930. /****************************************************************************
  931. *
  932. * Module stuff
  933. *
  934. ****************************************************************************/
  935. static void __exit cleanup_doc2001plus(void)
  936. {
  937. struct mtd_info *mtd;
  938. struct DiskOnChip *this;
  939. while ((mtd=docmilpluslist)) {
  940. this = mtd->priv;
  941. docmilpluslist = this->nextdoc;
  942. del_mtd_device(mtd);
  943. iounmap(this->virtadr);
  944. kfree(this->chips);
  945. kfree(mtd);
  946. }
  947. }
  948. module_exit(cleanup_doc2001plus);
  949. MODULE_LICENSE("GPL");
  950. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com> et al.");
  951. MODULE_DESCRIPTION("Driver for DiskOnChip Millennium Plus");