doc2000.c 32 KB

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