doc2001plus.c 33 KB

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