doc2000.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. /*
  2. * Linux driver for Disk-On-Chip 2000 and Millennium
  3. * (c) 1999 Machine Vision Holdings, Inc.
  4. * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org>
  5. *
  6. * $Id: doc2000.c,v 1.67 2005/11/07 11:14:24 gleixner Exp $
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <asm/errno.h>
  11. #include <asm/io.h>
  12. #include <asm/uaccess.h>
  13. #include <linux/miscdevice.h>
  14. #include <linux/pci.h>
  15. #include <linux/delay.h>
  16. #include <linux/slab.h>
  17. #include <linux/sched.h>
  18. #include <linux/init.h>
  19. #include <linux/types.h>
  20. #include <linux/bitops.h>
  21. #include <linux/mutex.h>
  22. #include <linux/mtd/mtd.h>
  23. #include <linux/mtd/nand.h>
  24. #include <linux/mtd/doc2000.h>
  25. #define DOC_SUPPORT_2000
  26. #define DOC_SUPPORT_2000TSOP
  27. #define DOC_SUPPORT_MILLENNIUM
  28. #ifdef DOC_SUPPORT_2000
  29. #define DoC_is_2000(doc) (doc->ChipID == DOC_ChipID_Doc2k)
  30. #else
  31. #define DoC_is_2000(doc) (0)
  32. #endif
  33. #if defined(DOC_SUPPORT_2000TSOP) || defined(DOC_SUPPORT_MILLENNIUM)
  34. #define DoC_is_Millennium(doc) (doc->ChipID == DOC_ChipID_DocMil)
  35. #else
  36. #define DoC_is_Millennium(doc) (0)
  37. #endif
  38. /* #define ECC_DEBUG */
  39. /* I have no idea why some DoC chips can not use memcpy_from|to_io().
  40. * This may be due to the different revisions of the ASIC controller built-in or
  41. * simplily a QA/Bug issue. Who knows ?? If you have trouble, please uncomment
  42. * this:
  43. #undef USE_MEMCPY
  44. */
  45. static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
  46. size_t *retlen, u_char *buf);
  47. static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
  48. size_t *retlen, const u_char *buf);
  49. static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
  50. size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
  51. static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
  52. size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
  53. static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
  54. size_t *retlen, u_char *buf);
  55. static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
  56. size_t *retlen, const u_char *buf);
  57. static int doc_write_oob_nolock(struct mtd_info *mtd, loff_t ofs, size_t len,
  58. size_t *retlen, const u_char *buf);
  59. static int doc_erase (struct mtd_info *mtd, struct erase_info *instr);
  60. static struct mtd_info *doc2klist = NULL;
  61. /* Perform the required delay cycles by reading from the appropriate register */
  62. static void DoC_Delay(struct DiskOnChip *doc, unsigned short cycles)
  63. {
  64. volatile char dummy;
  65. int i;
  66. for (i = 0; i < cycles; i++) {
  67. if (DoC_is_Millennium(doc))
  68. dummy = ReadDOC(doc->virtadr, NOP);
  69. else
  70. dummy = ReadDOC(doc->virtadr, DOCStatus);
  71. }
  72. }
  73. /* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */
  74. static int _DoC_WaitReady(struct DiskOnChip *doc)
  75. {
  76. void __iomem *docptr = doc->virtadr;
  77. unsigned long timeo = jiffies + (HZ * 10);
  78. DEBUG(MTD_DEBUG_LEVEL3,
  79. "_DoC_WaitReady called for out-of-line wait\n");
  80. /* Out-of-line routine to wait for chip response */
  81. while (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) {
  82. /* issue 2 read from NOP register after reading from CDSNControl register
  83. see Software Requirement 11.4 item 2. */
  84. DoC_Delay(doc, 2);
  85. if (time_after(jiffies, timeo)) {
  86. DEBUG(MTD_DEBUG_LEVEL2, "_DoC_WaitReady timed out.\n");
  87. return -EIO;
  88. }
  89. udelay(1);
  90. cond_resched();
  91. }
  92. return 0;
  93. }
  94. static inline int DoC_WaitReady(struct DiskOnChip *doc)
  95. {
  96. void __iomem *docptr = doc->virtadr;
  97. /* This is inline, to optimise the common case, where it's ready instantly */
  98. int ret = 0;
  99. /* 4 read form NOP register should be issued in prior to the read from CDSNControl
  100. see Software Requirement 11.4 item 2. */
  101. DoC_Delay(doc, 4);
  102. if (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B))
  103. /* Call the out-of-line routine to wait */
  104. ret = _DoC_WaitReady(doc);
  105. /* issue 2 read from NOP register after reading from CDSNControl register
  106. see Software Requirement 11.4 item 2. */
  107. DoC_Delay(doc, 2);
  108. return ret;
  109. }
  110. /* DoC_Command: Send a flash command to the flash chip through the CDSN Slow IO register to
  111. bypass the internal pipeline. Each of 4 delay cycles (read from the NOP register) is
  112. required after writing to CDSN Control register, see Software Requirement 11.4 item 3. */
  113. static int DoC_Command(struct DiskOnChip *doc, unsigned char command,
  114. unsigned char xtraflags)
  115. {
  116. void __iomem *docptr = doc->virtadr;
  117. if (DoC_is_2000(doc))
  118. xtraflags |= CDSN_CTRL_FLASH_IO;
  119. /* Assert the CLE (Command Latch Enable) line to the flash chip */
  120. WriteDOC(xtraflags | CDSN_CTRL_CLE | CDSN_CTRL_CE, docptr, CDSNControl);
  121. DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */
  122. if (DoC_is_Millennium(doc))
  123. WriteDOC(command, docptr, CDSNSlowIO);
  124. /* Send the command */
  125. WriteDOC_(command, docptr, doc->ioreg);
  126. if (DoC_is_Millennium(doc))
  127. WriteDOC(command, docptr, WritePipeTerm);
  128. /* Lower the CLE line */
  129. WriteDOC(xtraflags | CDSN_CTRL_CE, docptr, CDSNControl);
  130. DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */
  131. /* Wait for the chip to respond - Software requirement 11.4.1 (extended for any command) */
  132. return DoC_WaitReady(doc);
  133. }
  134. /* DoC_Address: Set the current address for the flash chip through the CDSN Slow IO register to
  135. bypass the internal pipeline. Each of 4 delay cycles (read from the NOP register) is
  136. required after writing to CDSN Control register, see Software Requirement 11.4 item 3. */
  137. static int DoC_Address(struct DiskOnChip *doc, int numbytes, unsigned long ofs,
  138. unsigned char xtraflags1, unsigned char xtraflags2)
  139. {
  140. int i;
  141. void __iomem *docptr = doc->virtadr;
  142. if (DoC_is_2000(doc))
  143. xtraflags1 |= CDSN_CTRL_FLASH_IO;
  144. /* Assert the ALE (Address Latch Enable) line to the flash chip */
  145. WriteDOC(xtraflags1 | CDSN_CTRL_ALE | CDSN_CTRL_CE, docptr, CDSNControl);
  146. DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */
  147. /* Send the address */
  148. /* Devices with 256-byte page are addressed as:
  149. Column (bits 0-7), Page (bits 8-15, 16-23, 24-31)
  150. * there is no device on the market with page256
  151. and more than 24 bits.
  152. Devices with 512-byte page are addressed as:
  153. Column (bits 0-7), Page (bits 9-16, 17-24, 25-31)
  154. * 25-31 is sent only if the chip support it.
  155. * bit 8 changes the read command to be sent
  156. (NAND_CMD_READ0 or NAND_CMD_READ1).
  157. */
  158. if (numbytes == ADDR_COLUMN || numbytes == ADDR_COLUMN_PAGE) {
  159. if (DoC_is_Millennium(doc))
  160. WriteDOC(ofs & 0xff, docptr, CDSNSlowIO);
  161. WriteDOC_(ofs & 0xff, docptr, doc->ioreg);
  162. }
  163. if (doc->page256) {
  164. ofs = ofs >> 8;
  165. } else {
  166. ofs = ofs >> 9;
  167. }
  168. if (numbytes == ADDR_PAGE || numbytes == ADDR_COLUMN_PAGE) {
  169. for (i = 0; i < doc->pageadrlen; i++, ofs = ofs >> 8) {
  170. if (DoC_is_Millennium(doc))
  171. WriteDOC(ofs & 0xff, docptr, CDSNSlowIO);
  172. WriteDOC_(ofs & 0xff, docptr, doc->ioreg);
  173. }
  174. }
  175. if (DoC_is_Millennium(doc))
  176. WriteDOC(ofs & 0xff, docptr, WritePipeTerm);
  177. DoC_Delay(doc, 2); /* Needed for some slow flash chips. mf. */
  178. /* FIXME: The SlowIO's for millennium could be replaced by
  179. a single WritePipeTerm here. mf. */
  180. /* Lower the ALE line */
  181. WriteDOC(xtraflags1 | xtraflags2 | CDSN_CTRL_CE, docptr,
  182. CDSNControl);
  183. DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */
  184. /* Wait for the chip to respond - Software requirement 11.4.1 */
  185. return DoC_WaitReady(doc);
  186. }
  187. /* Read a buffer from DoC, taking care of Millennium odditys */
  188. static void DoC_ReadBuf(struct DiskOnChip *doc, u_char * buf, int len)
  189. {
  190. volatile int dummy;
  191. int modulus = 0xffff;
  192. void __iomem *docptr = doc->virtadr;
  193. int i;
  194. if (len <= 0)
  195. return;
  196. if (DoC_is_Millennium(doc)) {
  197. /* Read the data via the internal pipeline through CDSN IO register,
  198. see Pipelined Read Operations 11.3 */
  199. dummy = ReadDOC(docptr, ReadPipeInit);
  200. /* Millennium should use the LastDataRead register - Pipeline Reads */
  201. len--;
  202. /* This is needed for correctly ECC calculation */
  203. modulus = 0xff;
  204. }
  205. for (i = 0; i < len; i++)
  206. buf[i] = ReadDOC_(docptr, doc->ioreg + (i & modulus));
  207. if (DoC_is_Millennium(doc)) {
  208. buf[i] = ReadDOC(docptr, LastDataRead);
  209. }
  210. }
  211. /* Write a buffer to DoC, taking care of Millennium odditys */
  212. static void DoC_WriteBuf(struct DiskOnChip *doc, const u_char * buf, int len)
  213. {
  214. void __iomem *docptr = doc->virtadr;
  215. int i;
  216. if (len <= 0)
  217. return;
  218. for (i = 0; i < len; i++)
  219. WriteDOC_(buf[i], docptr, doc->ioreg + i);
  220. if (DoC_is_Millennium(doc)) {
  221. WriteDOC(0x00, docptr, WritePipeTerm);
  222. }
  223. }
  224. /* DoC_SelectChip: Select a given flash chip within the current floor */
  225. static inline int DoC_SelectChip(struct DiskOnChip *doc, int chip)
  226. {
  227. void __iomem *docptr = doc->virtadr;
  228. /* Software requirement 11.4.4 before writing DeviceSelect */
  229. /* Deassert the CE line to eliminate glitches on the FCE# outputs */
  230. WriteDOC(CDSN_CTRL_WP, docptr, CDSNControl);
  231. DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */
  232. /* Select the individual flash chip requested */
  233. WriteDOC(chip, docptr, CDSNDeviceSelect);
  234. DoC_Delay(doc, 4);
  235. /* Reassert the CE line */
  236. WriteDOC(CDSN_CTRL_CE | CDSN_CTRL_FLASH_IO | CDSN_CTRL_WP, docptr,
  237. CDSNControl);
  238. DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */
  239. /* Wait for it to be ready */
  240. return DoC_WaitReady(doc);
  241. }
  242. /* DoC_SelectFloor: Select a given floor (bank of flash chips) */
  243. static inline int DoC_SelectFloor(struct DiskOnChip *doc, int floor)
  244. {
  245. void __iomem *docptr = doc->virtadr;
  246. /* Select the floor (bank) of chips required */
  247. WriteDOC(floor, docptr, FloorSelect);
  248. /* Wait for the chip to be ready */
  249. return DoC_WaitReady(doc);
  250. }
  251. /* DoC_IdentChip: Identify a given NAND chip given {floor,chip} */
  252. static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
  253. {
  254. int mfr, id, i, j;
  255. volatile char dummy;
  256. /* Page in the required floor/chip */
  257. DoC_SelectFloor(doc, floor);
  258. DoC_SelectChip(doc, chip);
  259. /* Reset the chip */
  260. if (DoC_Command(doc, NAND_CMD_RESET, CDSN_CTRL_WP)) {
  261. DEBUG(MTD_DEBUG_LEVEL2,
  262. "DoC_Command (reset) for %d,%d returned true\n",
  263. floor, chip);
  264. return 0;
  265. }
  266. /* Read the NAND chip ID: 1. Send ReadID command */
  267. if (DoC_Command(doc, NAND_CMD_READID, CDSN_CTRL_WP)) {
  268. DEBUG(MTD_DEBUG_LEVEL2,
  269. "DoC_Command (ReadID) for %d,%d returned true\n",
  270. floor, chip);
  271. return 0;
  272. }
  273. /* Read the NAND chip ID: 2. Send address byte zero */
  274. DoC_Address(doc, ADDR_COLUMN, 0, CDSN_CTRL_WP, 0);
  275. /* Read the manufacturer and device id codes from the device */
  276. if (DoC_is_Millennium(doc)) {
  277. DoC_Delay(doc, 2);
  278. dummy = ReadDOC(doc->virtadr, ReadPipeInit);
  279. mfr = ReadDOC(doc->virtadr, LastDataRead);
  280. DoC_Delay(doc, 2);
  281. dummy = ReadDOC(doc->virtadr, ReadPipeInit);
  282. id = ReadDOC(doc->virtadr, LastDataRead);
  283. } else {
  284. /* CDSN Slow IO register see Software Req 11.4 item 5. */
  285. dummy = ReadDOC(doc->virtadr, CDSNSlowIO);
  286. DoC_Delay(doc, 2);
  287. mfr = ReadDOC_(doc->virtadr, doc->ioreg);
  288. /* CDSN Slow IO register see Software Req 11.4 item 5. */
  289. dummy = ReadDOC(doc->virtadr, CDSNSlowIO);
  290. DoC_Delay(doc, 2);
  291. id = ReadDOC_(doc->virtadr, doc->ioreg);
  292. }
  293. /* No response - return failure */
  294. if (mfr == 0xff || mfr == 0)
  295. return 0;
  296. /* Check it's the same as the first chip we identified.
  297. * M-Systems say that any given DiskOnChip device should only
  298. * contain _one_ type of flash part, although that's not a
  299. * hardware restriction. */
  300. if (doc->mfr) {
  301. if (doc->mfr == mfr && doc->id == id)
  302. return 1; /* This is another the same the first */
  303. else
  304. printk(KERN_WARNING
  305. "Flash chip at floor %d, chip %d is different:\n",
  306. floor, chip);
  307. }
  308. /* Print and store the manufacturer and ID codes. */
  309. for (i = 0; nand_flash_ids[i].name != NULL; i++) {
  310. if (id == nand_flash_ids[i].id) {
  311. /* Try to identify manufacturer */
  312. for (j = 0; nand_manuf_ids[j].id != 0x0; j++) {
  313. if (nand_manuf_ids[j].id == mfr)
  314. break;
  315. }
  316. printk(KERN_INFO
  317. "Flash chip found: Manufacturer ID: %2.2X, "
  318. "Chip ID: %2.2X (%s:%s)\n", mfr, id,
  319. nand_manuf_ids[j].name, nand_flash_ids[i].name);
  320. if (!doc->mfr) {
  321. doc->mfr = mfr;
  322. doc->id = id;
  323. doc->chipshift =
  324. ffs((nand_flash_ids[i].chipsize << 20)) - 1;
  325. doc->page256 = (nand_flash_ids[i].pagesize == 256) ? 1 : 0;
  326. doc->pageadrlen = doc->chipshift > 25 ? 3 : 2;
  327. doc->erasesize =
  328. nand_flash_ids[i].erasesize;
  329. return 1;
  330. }
  331. return 0;
  332. }
  333. }
  334. /* We haven't fully identified the chip. Print as much as we know. */
  335. printk(KERN_WARNING "Unknown flash chip found: %2.2X %2.2X\n",
  336. id, mfr);
  337. printk(KERN_WARNING "Please report to dwmw2@infradead.org\n");
  338. return 0;
  339. }
  340. /* DoC_ScanChips: Find all NAND chips present in a DiskOnChip, and identify them */
  341. static void DoC_ScanChips(struct DiskOnChip *this, int maxchips)
  342. {
  343. int floor, chip;
  344. int numchips[MAX_FLOORS];
  345. int ret = 1;
  346. this->numchips = 0;
  347. this->mfr = 0;
  348. this->id = 0;
  349. /* For each floor, find the number of valid chips it contains */
  350. for (floor = 0; floor < MAX_FLOORS; floor++) {
  351. ret = 1;
  352. numchips[floor] = 0;
  353. for (chip = 0; chip < maxchips && ret != 0; chip++) {
  354. ret = DoC_IdentChip(this, floor, chip);
  355. if (ret) {
  356. numchips[floor]++;
  357. this->numchips++;
  358. }
  359. }
  360. }
  361. /* If there are none at all that we recognise, bail */
  362. if (!this->numchips) {
  363. printk(KERN_NOTICE "No flash chips recognised.\n");
  364. return;
  365. }
  366. /* Allocate an array to hold the information for each chip */
  367. this->chips = kmalloc(sizeof(struct Nand) * this->numchips, GFP_KERNEL);
  368. if (!this->chips) {
  369. printk(KERN_NOTICE "No memory for allocating chip info structures\n");
  370. return;
  371. }
  372. ret = 0;
  373. /* Fill out the chip array with {floor, chipno} for each
  374. * detected chip in the device. */
  375. for (floor = 0; floor < MAX_FLOORS; floor++) {
  376. for (chip = 0; chip < numchips[floor]; chip++) {
  377. this->chips[ret].floor = floor;
  378. this->chips[ret].chip = chip;
  379. this->chips[ret].curadr = 0;
  380. this->chips[ret].curmode = 0x50;
  381. ret++;
  382. }
  383. }
  384. /* Calculate and print the total size of the device */
  385. this->totlen = this->numchips * (1 << this->chipshift);
  386. printk(KERN_INFO "%d flash chips found. Total DiskOnChip size: %ld MiB\n",
  387. this->numchips, this->totlen >> 20);
  388. }
  389. static int DoC2k_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2)
  390. {
  391. int tmp1, tmp2, retval;
  392. if (doc1->physadr == doc2->physadr)
  393. return 1;
  394. /* Use the alias resolution register which was set aside for this
  395. * purpose. If it's value is the same on both chips, they might
  396. * be the same chip, and we write to one and check for a change in
  397. * the other. It's unclear if this register is usuable in the
  398. * DoC 2000 (it's in the Millennium docs), but it seems to work. */
  399. tmp1 = ReadDOC(doc1->virtadr, AliasResolution);
  400. tmp2 = ReadDOC(doc2->virtadr, AliasResolution);
  401. if (tmp1 != tmp2)
  402. return 0;
  403. WriteDOC((tmp1 + 1) % 0xff, doc1->virtadr, AliasResolution);
  404. tmp2 = ReadDOC(doc2->virtadr, AliasResolution);
  405. if (tmp2 == (tmp1 + 1) % 0xff)
  406. retval = 1;
  407. else
  408. retval = 0;
  409. /* Restore register contents. May not be necessary, but do it just to
  410. * be safe. */
  411. WriteDOC(tmp1, doc1->virtadr, AliasResolution);
  412. return retval;
  413. }
  414. /* This routine is found from the docprobe code by symbol_get(),
  415. * which will bump the use count of this module. */
  416. void DoC2k_init(struct mtd_info *mtd)
  417. {
  418. struct DiskOnChip *this = mtd->priv;
  419. struct DiskOnChip *old = NULL;
  420. int maxchips;
  421. /* We must avoid being called twice for the same device. */
  422. if (doc2klist)
  423. old = doc2klist->priv;
  424. while (old) {
  425. if (DoC2k_is_alias(old, this)) {
  426. printk(KERN_NOTICE
  427. "Ignoring DiskOnChip 2000 at 0x%lX - already configured\n",
  428. this->physadr);
  429. iounmap(this->virtadr);
  430. kfree(mtd);
  431. return;
  432. }
  433. if (old->nextdoc)
  434. old = old->nextdoc->priv;
  435. else
  436. old = NULL;
  437. }
  438. switch (this->ChipID) {
  439. case DOC_ChipID_Doc2kTSOP:
  440. mtd->name = "DiskOnChip 2000 TSOP";
  441. this->ioreg = DoC_Mil_CDSN_IO;
  442. /* Pretend it's a Millennium */
  443. this->ChipID = DOC_ChipID_DocMil;
  444. maxchips = MAX_CHIPS;
  445. break;
  446. case DOC_ChipID_Doc2k:
  447. mtd->name = "DiskOnChip 2000";
  448. this->ioreg = DoC_2k_CDSN_IO;
  449. maxchips = MAX_CHIPS;
  450. break;
  451. case DOC_ChipID_DocMil:
  452. mtd->name = "DiskOnChip Millennium";
  453. this->ioreg = DoC_Mil_CDSN_IO;
  454. maxchips = MAX_CHIPS_MIL;
  455. break;
  456. default:
  457. printk("Unknown ChipID 0x%02x\n", this->ChipID);
  458. kfree(mtd);
  459. iounmap(this->virtadr);
  460. return;
  461. }
  462. printk(KERN_NOTICE "%s found at address 0x%lX\n", mtd->name,
  463. this->physadr);
  464. mtd->type = MTD_NANDFLASH;
  465. mtd->flags = MTD_CAP_NANDFLASH;
  466. mtd->ecctype = MTD_ECC_RS_DiskOnChip;
  467. mtd->size = 0;
  468. mtd->erasesize = 0;
  469. mtd->writesize = 512;
  470. mtd->oobsize = 16;
  471. mtd->owner = THIS_MODULE;
  472. mtd->erase = doc_erase;
  473. mtd->point = NULL;
  474. mtd->unpoint = NULL;
  475. mtd->read = doc_read;
  476. mtd->write = doc_write;
  477. mtd->read_oob = doc_read_oob;
  478. mtd->write_oob = doc_write_oob;
  479. mtd->sync = NULL;
  480. this->totlen = 0;
  481. this->numchips = 0;
  482. this->curfloor = -1;
  483. this->curchip = -1;
  484. mutex_init(&this->lock);
  485. /* Ident all the chips present. */
  486. DoC_ScanChips(this, maxchips);
  487. if (!this->totlen) {
  488. kfree(mtd);
  489. iounmap(this->virtadr);
  490. } else {
  491. this->nextdoc = doc2klist;
  492. doc2klist = mtd;
  493. mtd->size = this->totlen;
  494. mtd->erasesize = this->erasesize;
  495. add_mtd_device(mtd);
  496. return;
  497. }
  498. }
  499. EXPORT_SYMBOL_GPL(DoC2k_init);
  500. static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
  501. size_t * retlen, u_char * buf)
  502. {
  503. /* Just a special case of doc_read_ecc */
  504. return doc_read_ecc(mtd, from, len, retlen, buf, NULL, NULL);
  505. }
  506. static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
  507. size_t * retlen, u_char * buf, u_char * eccbuf, struct nand_oobinfo *oobsel)
  508. {
  509. struct DiskOnChip *this = mtd->priv;
  510. void __iomem *docptr = this->virtadr;
  511. struct Nand *mychip;
  512. unsigned char syndrome[6];
  513. volatile char dummy;
  514. int i, len256 = 0, ret=0;
  515. size_t left = len;
  516. /* Don't allow read past end of device */
  517. if (from >= this->totlen)
  518. return -EINVAL;
  519. mutex_lock(&this->lock);
  520. *retlen = 0;
  521. while (left) {
  522. len = left;
  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. /* The ECC will not be calculated correctly if less than 512 is read */
  527. if (len != 0x200 && eccbuf)
  528. printk(KERN_WARNING
  529. "ECC needs a full sector read (adr: %lx size %lx)\n",
  530. (long) from, (long) len);
  531. /* printk("DoC_Read (adr: %lx size %lx)\n", (long) from, (long) len); */
  532. /* Find the chip which is to be used and select it */
  533. mychip = &this->chips[from >> (this->chipshift)];
  534. if (this->curfloor != mychip->floor) {
  535. DoC_SelectFloor(this, mychip->floor);
  536. DoC_SelectChip(this, mychip->chip);
  537. } else if (this->curchip != mychip->chip) {
  538. DoC_SelectChip(this, mychip->chip);
  539. }
  540. this->curfloor = mychip->floor;
  541. this->curchip = mychip->chip;
  542. DoC_Command(this,
  543. (!this->page256
  544. && (from & 0x100)) ? NAND_CMD_READ1 : NAND_CMD_READ0,
  545. CDSN_CTRL_WP);
  546. DoC_Address(this, ADDR_COLUMN_PAGE, from, CDSN_CTRL_WP,
  547. CDSN_CTRL_ECC_IO);
  548. if (eccbuf) {
  549. /* Prime the ECC engine */
  550. WriteDOC(DOC_ECC_RESET, docptr, ECCConf);
  551. WriteDOC(DOC_ECC_EN, docptr, ECCConf);
  552. } else {
  553. /* disable the ECC engine */
  554. WriteDOC(DOC_ECC_RESET, docptr, ECCConf);
  555. WriteDOC(DOC_ECC_DIS, docptr, ECCConf);
  556. }
  557. /* treat crossing 256-byte sector for 2M x 8bits devices */
  558. if (this->page256 && from + len > (from | 0xff) + 1) {
  559. len256 = (from | 0xff) + 1 - from;
  560. DoC_ReadBuf(this, buf, len256);
  561. DoC_Command(this, NAND_CMD_READ0, CDSN_CTRL_WP);
  562. DoC_Address(this, ADDR_COLUMN_PAGE, from + len256,
  563. CDSN_CTRL_WP, CDSN_CTRL_ECC_IO);
  564. }
  565. DoC_ReadBuf(this, &buf[len256], len - len256);
  566. /* Let the caller know we completed it */
  567. *retlen += len;
  568. if (eccbuf) {
  569. /* Read the ECC data through the DiskOnChip ECC logic */
  570. /* Note: this will work even with 2M x 8bit devices as */
  571. /* they have 8 bytes of OOB per 256 page. mf. */
  572. DoC_ReadBuf(this, eccbuf, 6);
  573. /* Flush the pipeline */
  574. if (DoC_is_Millennium(this)) {
  575. dummy = ReadDOC(docptr, ECCConf);
  576. dummy = ReadDOC(docptr, ECCConf);
  577. i = ReadDOC(docptr, ECCConf);
  578. } else {
  579. dummy = ReadDOC(docptr, 2k_ECCStatus);
  580. dummy = ReadDOC(docptr, 2k_ECCStatus);
  581. i = ReadDOC(docptr, 2k_ECCStatus);
  582. }
  583. /* Check the ECC Status */
  584. if (i & 0x80) {
  585. int nb_errors;
  586. /* There was an ECC error */
  587. #ifdef ECC_DEBUG
  588. printk(KERN_ERR "DiskOnChip ECC Error: Read at %lx\n", (long)from);
  589. #endif
  590. /* Read the ECC syndrom through the DiskOnChip ECC logic.
  591. These syndrome will be all ZERO when there is no error */
  592. for (i = 0; i < 6; i++) {
  593. syndrome[i] =
  594. ReadDOC(docptr, ECCSyndrome0 + i);
  595. }
  596. nb_errors = doc_decode_ecc(buf, syndrome);
  597. #ifdef ECC_DEBUG
  598. printk(KERN_ERR "Errors corrected: %x\n", nb_errors);
  599. #endif
  600. if (nb_errors < 0) {
  601. /* We return error, but have actually done the read. Not that
  602. this can be told to user-space, via sys_read(), but at least
  603. MTD-aware stuff can know about it by checking *retlen */
  604. ret = -EIO;
  605. }
  606. }
  607. #ifdef PSYCHO_DEBUG
  608. printk(KERN_DEBUG "ECC DATA at %lxB: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
  609. (long)from, eccbuf[0], eccbuf[1], eccbuf[2],
  610. eccbuf[3], eccbuf[4], eccbuf[5]);
  611. #endif
  612. /* disable the ECC engine */
  613. WriteDOC(DOC_ECC_DIS, docptr , ECCConf);
  614. }
  615. /* according to 11.4.1, we need to wait for the busy line
  616. * drop if we read to the end of the page. */
  617. if(0 == ((from + len) & 0x1ff))
  618. {
  619. DoC_WaitReady(this);
  620. }
  621. from += len;
  622. left -= len;
  623. buf += len;
  624. }
  625. mutex_unlock(&this->lock);
  626. return ret;
  627. }
  628. static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
  629. size_t * retlen, const u_char * buf)
  630. {
  631. char eccbuf[6];
  632. return doc_write_ecc(mtd, to, len, retlen, buf, eccbuf, NULL);
  633. }
  634. static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
  635. size_t * retlen, const u_char * buf,
  636. u_char * eccbuf, struct nand_oobinfo *oobsel)
  637. {
  638. struct DiskOnChip *this = mtd->priv;
  639. int di; /* Yes, DI is a hangover from when I was disassembling the binary driver */
  640. void __iomem *docptr = this->virtadr;
  641. volatile char dummy;
  642. int len256 = 0;
  643. struct Nand *mychip;
  644. size_t left = len;
  645. int status;
  646. /* Don't allow write past end of device */
  647. if (to >= this->totlen)
  648. return -EINVAL;
  649. mutex_lock(&this->lock);
  650. *retlen = 0;
  651. while (left) {
  652. len = left;
  653. /* Don't allow a single write to cross a 512-byte block boundary */
  654. if (to + len > ((to | 0x1ff) + 1))
  655. len = ((to | 0x1ff) + 1) - to;
  656. /* The ECC will not be calculated correctly if less than 512 is written */
  657. /* DBB-
  658. if (len != 0x200 && eccbuf)
  659. printk(KERN_WARNING
  660. "ECC needs a full sector write (adr: %lx size %lx)\n",
  661. (long) to, (long) len);
  662. -DBB */
  663. /* printk("DoC_Write (adr: %lx size %lx)\n", (long) to, (long) len); */
  664. /* Find the chip which is to be used and select it */
  665. mychip = &this->chips[to >> (this->chipshift)];
  666. if (this->curfloor != mychip->floor) {
  667. DoC_SelectFloor(this, mychip->floor);
  668. DoC_SelectChip(this, mychip->chip);
  669. } else if (this->curchip != mychip->chip) {
  670. DoC_SelectChip(this, mychip->chip);
  671. }
  672. this->curfloor = mychip->floor;
  673. this->curchip = mychip->chip;
  674. /* Set device to main plane of flash */
  675. DoC_Command(this, NAND_CMD_RESET, CDSN_CTRL_WP);
  676. DoC_Command(this,
  677. (!this->page256
  678. && (to & 0x100)) ? NAND_CMD_READ1 : NAND_CMD_READ0,
  679. CDSN_CTRL_WP);
  680. DoC_Command(this, NAND_CMD_SEQIN, 0);
  681. DoC_Address(this, ADDR_COLUMN_PAGE, to, 0, CDSN_CTRL_ECC_IO);
  682. if (eccbuf) {
  683. /* Prime the ECC engine */
  684. WriteDOC(DOC_ECC_RESET, docptr, ECCConf);
  685. WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, ECCConf);
  686. } else {
  687. /* disable the ECC engine */
  688. WriteDOC(DOC_ECC_RESET, docptr, ECCConf);
  689. WriteDOC(DOC_ECC_DIS, docptr, ECCConf);
  690. }
  691. /* treat crossing 256-byte sector for 2M x 8bits devices */
  692. if (this->page256 && to + len > (to | 0xff) + 1) {
  693. len256 = (to | 0xff) + 1 - to;
  694. DoC_WriteBuf(this, buf, len256);
  695. DoC_Command(this, NAND_CMD_PAGEPROG, 0);
  696. DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP);
  697. /* There's an implicit DoC_WaitReady() in DoC_Command */
  698. dummy = ReadDOC(docptr, CDSNSlowIO);
  699. DoC_Delay(this, 2);
  700. if (ReadDOC_(docptr, this->ioreg) & 1) {
  701. printk(KERN_ERR "Error programming flash\n");
  702. /* Error in programming */
  703. *retlen = 0;
  704. mutex_unlock(&this->lock);
  705. return -EIO;
  706. }
  707. DoC_Command(this, NAND_CMD_SEQIN, 0);
  708. DoC_Address(this, ADDR_COLUMN_PAGE, to + len256, 0,
  709. CDSN_CTRL_ECC_IO);
  710. }
  711. DoC_WriteBuf(this, &buf[len256], len - len256);
  712. if (eccbuf) {
  713. WriteDOC(CDSN_CTRL_ECC_IO | CDSN_CTRL_CE, docptr,
  714. CDSNControl);
  715. if (DoC_is_Millennium(this)) {
  716. WriteDOC(0, docptr, NOP);
  717. WriteDOC(0, docptr, NOP);
  718. WriteDOC(0, docptr, NOP);
  719. } else {
  720. WriteDOC_(0, docptr, this->ioreg);
  721. WriteDOC_(0, docptr, this->ioreg);
  722. WriteDOC_(0, docptr, this->ioreg);
  723. }
  724. WriteDOC(CDSN_CTRL_ECC_IO | CDSN_CTRL_FLASH_IO | CDSN_CTRL_CE, docptr,
  725. CDSNControl);
  726. /* Read the ECC data through the DiskOnChip ECC logic */
  727. for (di = 0; di < 6; di++) {
  728. eccbuf[di] = ReadDOC(docptr, ECCSyndrome0 + di);
  729. }
  730. /* Reset the ECC engine */
  731. WriteDOC(DOC_ECC_DIS, docptr, ECCConf);
  732. #ifdef PSYCHO_DEBUG
  733. printk
  734. ("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
  735. (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],
  736. eccbuf[4], eccbuf[5]);
  737. #endif
  738. }
  739. DoC_Command(this, NAND_CMD_PAGEPROG, 0);
  740. DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP);
  741. /* There's an implicit DoC_WaitReady() in DoC_Command */
  742. if (DoC_is_Millennium(this)) {
  743. ReadDOC(docptr, ReadPipeInit);
  744. status = ReadDOC(docptr, LastDataRead);
  745. } else {
  746. dummy = ReadDOC(docptr, CDSNSlowIO);
  747. DoC_Delay(this, 2);
  748. status = ReadDOC_(docptr, this->ioreg);
  749. }
  750. if (status & 1) {
  751. printk(KERN_ERR "Error programming flash\n");
  752. /* Error in programming */
  753. *retlen = 0;
  754. mutex_unlock(&this->lock);
  755. return -EIO;
  756. }
  757. /* Let the caller know we completed it */
  758. *retlen += len;
  759. if (eccbuf) {
  760. unsigned char x[8];
  761. size_t dummy;
  762. int ret;
  763. /* Write the ECC data to flash */
  764. for (di=0; di<6; di++)
  765. x[di] = eccbuf[di];
  766. x[6]=0x55;
  767. x[7]=0x55;
  768. ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x);
  769. if (ret) {
  770. mutex_unlock(&this->lock);
  771. return ret;
  772. }
  773. }
  774. to += len;
  775. left -= len;
  776. buf += len;
  777. }
  778. mutex_unlock(&this->lock);
  779. return 0;
  780. }
  781. static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
  782. size_t * retlen, u_char * buf)
  783. {
  784. struct DiskOnChip *this = mtd->priv;
  785. int len256 = 0, ret;
  786. struct Nand *mychip;
  787. mutex_lock(&this->lock);
  788. mychip = &this->chips[ofs >> this->chipshift];
  789. if (this->curfloor != mychip->floor) {
  790. DoC_SelectFloor(this, mychip->floor);
  791. DoC_SelectChip(this, mychip->chip);
  792. } else if (this->curchip != mychip->chip) {
  793. DoC_SelectChip(this, mychip->chip);
  794. }
  795. this->curfloor = mychip->floor;
  796. this->curchip = mychip->chip;
  797. /* update address for 2M x 8bit devices. OOB starts on the second */
  798. /* page to maintain compatibility with doc_read_ecc. */
  799. if (this->page256) {
  800. if (!(ofs & 0x8))
  801. ofs += 0x100;
  802. else
  803. ofs -= 0x8;
  804. }
  805. DoC_Command(this, NAND_CMD_READOOB, CDSN_CTRL_WP);
  806. DoC_Address(this, ADDR_COLUMN_PAGE, ofs, CDSN_CTRL_WP, 0);
  807. /* treat crossing 8-byte OOB data for 2M x 8bit devices */
  808. /* Note: datasheet says it should automaticaly wrap to the */
  809. /* next OOB block, but it didn't work here. mf. */
  810. if (this->page256 && ofs + len > (ofs | 0x7) + 1) {
  811. len256 = (ofs | 0x7) + 1 - ofs;
  812. DoC_ReadBuf(this, buf, len256);
  813. DoC_Command(this, NAND_CMD_READOOB, CDSN_CTRL_WP);
  814. DoC_Address(this, ADDR_COLUMN_PAGE, ofs & (~0x1ff),
  815. CDSN_CTRL_WP, 0);
  816. }
  817. DoC_ReadBuf(this, &buf[len256], len - len256);
  818. *retlen = len;
  819. /* Reading the full OOB data drops us off of the end of the page,
  820. * causing the flash device to go into busy mode, so we need
  821. * to wait until ready 11.4.1 and Toshiba TC58256FT docs */
  822. ret = DoC_WaitReady(this);
  823. mutex_unlock(&this->lock);
  824. return ret;
  825. }
  826. static int doc_write_oob_nolock(struct mtd_info *mtd, loff_t ofs, size_t len,
  827. size_t * retlen, const u_char * buf)
  828. {
  829. struct DiskOnChip *this = mtd->priv;
  830. int len256 = 0;
  831. void __iomem *docptr = this->virtadr;
  832. struct Nand *mychip = &this->chips[ofs >> this->chipshift];
  833. volatile int dummy;
  834. int status;
  835. // printk("doc_write_oob(%lx, %d): %2.2X %2.2X %2.2X %2.2X ... %2.2X %2.2X .. %2.2X %2.2X\n",(long)ofs, len,
  836. // buf[0], buf[1], buf[2], buf[3], buf[8], buf[9], buf[14],buf[15]);
  837. /* Find the chip which is to be used and select it */
  838. if (this->curfloor != mychip->floor) {
  839. DoC_SelectFloor(this, mychip->floor);
  840. DoC_SelectChip(this, mychip->chip);
  841. } else if (this->curchip != mychip->chip) {
  842. DoC_SelectChip(this, mychip->chip);
  843. }
  844. this->curfloor = mychip->floor;
  845. this->curchip = mychip->chip;
  846. /* disable the ECC engine */
  847. WriteDOC (DOC_ECC_RESET, docptr, ECCConf);
  848. WriteDOC (DOC_ECC_DIS, docptr, ECCConf);
  849. /* Reset the chip, see Software Requirement 11.4 item 1. */
  850. DoC_Command(this, NAND_CMD_RESET, CDSN_CTRL_WP);
  851. /* issue the Read2 command to set the pointer to the Spare Data Area. */
  852. DoC_Command(this, NAND_CMD_READOOB, CDSN_CTRL_WP);
  853. /* update address for 2M x 8bit devices. OOB starts on the second */
  854. /* page to maintain compatibility with doc_read_ecc. */
  855. if (this->page256) {
  856. if (!(ofs & 0x8))
  857. ofs += 0x100;
  858. else
  859. ofs -= 0x8;
  860. }
  861. /* issue the Serial Data In command to initial the Page Program process */
  862. DoC_Command(this, NAND_CMD_SEQIN, 0);
  863. DoC_Address(this, ADDR_COLUMN_PAGE, ofs, 0, 0);
  864. /* treat crossing 8-byte OOB data for 2M x 8bit devices */
  865. /* Note: datasheet says it should automaticaly wrap to the */
  866. /* next OOB block, but it didn't work here. mf. */
  867. if (this->page256 && ofs + len > (ofs | 0x7) + 1) {
  868. len256 = (ofs | 0x7) + 1 - ofs;
  869. DoC_WriteBuf(this, buf, len256);
  870. DoC_Command(this, NAND_CMD_PAGEPROG, 0);
  871. DoC_Command(this, NAND_CMD_STATUS, 0);
  872. /* DoC_WaitReady() is implicit in DoC_Command */
  873. if (DoC_is_Millennium(this)) {
  874. ReadDOC(docptr, ReadPipeInit);
  875. status = ReadDOC(docptr, LastDataRead);
  876. } else {
  877. dummy = ReadDOC(docptr, CDSNSlowIO);
  878. DoC_Delay(this, 2);
  879. status = ReadDOC_(docptr, this->ioreg);
  880. }
  881. if (status & 1) {
  882. printk(KERN_ERR "Error programming oob data\n");
  883. /* There was an error */
  884. *retlen = 0;
  885. return -EIO;
  886. }
  887. DoC_Command(this, NAND_CMD_SEQIN, 0);
  888. DoC_Address(this, ADDR_COLUMN_PAGE, ofs & (~0x1ff), 0, 0);
  889. }
  890. DoC_WriteBuf(this, &buf[len256], len - len256);
  891. DoC_Command(this, NAND_CMD_PAGEPROG, 0);
  892. DoC_Command(this, NAND_CMD_STATUS, 0);
  893. /* DoC_WaitReady() is implicit in DoC_Command */
  894. if (DoC_is_Millennium(this)) {
  895. ReadDOC(docptr, ReadPipeInit);
  896. status = ReadDOC(docptr, LastDataRead);
  897. } else {
  898. dummy = ReadDOC(docptr, CDSNSlowIO);
  899. DoC_Delay(this, 2);
  900. status = ReadDOC_(docptr, this->ioreg);
  901. }
  902. if (status & 1) {
  903. printk(KERN_ERR "Error programming oob data\n");
  904. /* There was an error */
  905. *retlen = 0;
  906. return -EIO;
  907. }
  908. *retlen = len;
  909. return 0;
  910. }
  911. static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
  912. size_t * retlen, const u_char * buf)
  913. {
  914. struct DiskOnChip *this = mtd->priv;
  915. int ret;
  916. mutex_lock(&this->lock);
  917. ret = doc_write_oob_nolock(mtd, ofs, len, retlen, buf);
  918. mutex_unlock(&this->lock);
  919. return ret;
  920. }
  921. static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
  922. {
  923. struct DiskOnChip *this = mtd->priv;
  924. __u32 ofs = instr->addr;
  925. __u32 len = instr->len;
  926. volatile int dummy;
  927. void __iomem *docptr = this->virtadr;
  928. struct Nand *mychip;
  929. int status;
  930. mutex_lock(&this->lock);
  931. if (ofs & (mtd->erasesize-1) || len & (mtd->erasesize-1)) {
  932. mutex_unlock(&this->lock);
  933. return -EINVAL;
  934. }
  935. instr->state = MTD_ERASING;
  936. /* FIXME: Do this in the background. Use timers or schedule_task() */
  937. while(len) {
  938. mychip = &this->chips[ofs >> this->chipshift];
  939. if (this->curfloor != mychip->floor) {
  940. DoC_SelectFloor(this, mychip->floor);
  941. DoC_SelectChip(this, mychip->chip);
  942. } else if (this->curchip != mychip->chip) {
  943. DoC_SelectChip(this, mychip->chip);
  944. }
  945. this->curfloor = mychip->floor;
  946. this->curchip = mychip->chip;
  947. DoC_Command(this, NAND_CMD_ERASE1, 0);
  948. DoC_Address(this, ADDR_PAGE, ofs, 0, 0);
  949. DoC_Command(this, NAND_CMD_ERASE2, 0);
  950. DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP);
  951. if (DoC_is_Millennium(this)) {
  952. ReadDOC(docptr, ReadPipeInit);
  953. status = ReadDOC(docptr, LastDataRead);
  954. } else {
  955. dummy = ReadDOC(docptr, CDSNSlowIO);
  956. DoC_Delay(this, 2);
  957. status = ReadDOC_(docptr, this->ioreg);
  958. }
  959. if (status & 1) {
  960. printk(KERN_ERR "Error erasing at 0x%x\n", ofs);
  961. /* There was an error */
  962. instr->state = MTD_ERASE_FAILED;
  963. goto callback;
  964. }
  965. ofs += mtd->erasesize;
  966. len -= mtd->erasesize;
  967. }
  968. instr->state = MTD_ERASE_DONE;
  969. callback:
  970. mtd_erase_callback(instr);
  971. mutex_unlock(&this->lock);
  972. return 0;
  973. }
  974. /****************************************************************************
  975. *
  976. * Module stuff
  977. *
  978. ****************************************************************************/
  979. static void __exit cleanup_doc2000(void)
  980. {
  981. struct mtd_info *mtd;
  982. struct DiskOnChip *this;
  983. while ((mtd = doc2klist)) {
  984. this = mtd->priv;
  985. doc2klist = this->nextdoc;
  986. del_mtd_device(mtd);
  987. iounmap(this->virtadr);
  988. kfree(this->chips);
  989. kfree(mtd);
  990. }
  991. }
  992. module_exit(cleanup_doc2000);
  993. MODULE_LICENSE("GPL");
  994. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org> et al.");
  995. MODULE_DESCRIPTION("MTD driver for DiskOnChip 2000 and Millennium");