omap2.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. /*
  2. * Copyright © 2004 Texas Instruments, Jian Zhang <jzhang@ti.com>
  3. * Copyright © 2004 Micron Technology Inc.
  4. * Copyright © 2004 David Brownell
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/platform_device.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/delay.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/jiffies.h>
  15. #include <linux/sched.h>
  16. #include <linux/mtd/mtd.h>
  17. #include <linux/mtd/nand.h>
  18. #include <linux/mtd/partitions.h>
  19. #include <linux/io.h>
  20. #include <linux/slab.h>
  21. #include <plat/dma.h>
  22. #include <plat/gpmc.h>
  23. #include <plat/nand.h>
  24. #define DRIVER_NAME "omap2-nand"
  25. #define OMAP_NAND_TIMEOUT_MS 5000
  26. #define NAND_Ecc_P1e (1 << 0)
  27. #define NAND_Ecc_P2e (1 << 1)
  28. #define NAND_Ecc_P4e (1 << 2)
  29. #define NAND_Ecc_P8e (1 << 3)
  30. #define NAND_Ecc_P16e (1 << 4)
  31. #define NAND_Ecc_P32e (1 << 5)
  32. #define NAND_Ecc_P64e (1 << 6)
  33. #define NAND_Ecc_P128e (1 << 7)
  34. #define NAND_Ecc_P256e (1 << 8)
  35. #define NAND_Ecc_P512e (1 << 9)
  36. #define NAND_Ecc_P1024e (1 << 10)
  37. #define NAND_Ecc_P2048e (1 << 11)
  38. #define NAND_Ecc_P1o (1 << 16)
  39. #define NAND_Ecc_P2o (1 << 17)
  40. #define NAND_Ecc_P4o (1 << 18)
  41. #define NAND_Ecc_P8o (1 << 19)
  42. #define NAND_Ecc_P16o (1 << 20)
  43. #define NAND_Ecc_P32o (1 << 21)
  44. #define NAND_Ecc_P64o (1 << 22)
  45. #define NAND_Ecc_P128o (1 << 23)
  46. #define NAND_Ecc_P256o (1 << 24)
  47. #define NAND_Ecc_P512o (1 << 25)
  48. #define NAND_Ecc_P1024o (1 << 26)
  49. #define NAND_Ecc_P2048o (1 << 27)
  50. #define TF(value) (value ? 1 : 0)
  51. #define P2048e(a) (TF(a & NAND_Ecc_P2048e) << 0)
  52. #define P2048o(a) (TF(a & NAND_Ecc_P2048o) << 1)
  53. #define P1e(a) (TF(a & NAND_Ecc_P1e) << 2)
  54. #define P1o(a) (TF(a & NAND_Ecc_P1o) << 3)
  55. #define P2e(a) (TF(a & NAND_Ecc_P2e) << 4)
  56. #define P2o(a) (TF(a & NAND_Ecc_P2o) << 5)
  57. #define P4e(a) (TF(a & NAND_Ecc_P4e) << 6)
  58. #define P4o(a) (TF(a & NAND_Ecc_P4o) << 7)
  59. #define P8e(a) (TF(a & NAND_Ecc_P8e) << 0)
  60. #define P8o(a) (TF(a & NAND_Ecc_P8o) << 1)
  61. #define P16e(a) (TF(a & NAND_Ecc_P16e) << 2)
  62. #define P16o(a) (TF(a & NAND_Ecc_P16o) << 3)
  63. #define P32e(a) (TF(a & NAND_Ecc_P32e) << 4)
  64. #define P32o(a) (TF(a & NAND_Ecc_P32o) << 5)
  65. #define P64e(a) (TF(a & NAND_Ecc_P64e) << 6)
  66. #define P64o(a) (TF(a & NAND_Ecc_P64o) << 7)
  67. #define P128e(a) (TF(a & NAND_Ecc_P128e) << 0)
  68. #define P128o(a) (TF(a & NAND_Ecc_P128o) << 1)
  69. #define P256e(a) (TF(a & NAND_Ecc_P256e) << 2)
  70. #define P256o(a) (TF(a & NAND_Ecc_P256o) << 3)
  71. #define P512e(a) (TF(a & NAND_Ecc_P512e) << 4)
  72. #define P512o(a) (TF(a & NAND_Ecc_P512o) << 5)
  73. #define P1024e(a) (TF(a & NAND_Ecc_P1024e) << 6)
  74. #define P1024o(a) (TF(a & NAND_Ecc_P1024o) << 7)
  75. #define P8e_s(a) (TF(a & NAND_Ecc_P8e) << 0)
  76. #define P8o_s(a) (TF(a & NAND_Ecc_P8o) << 1)
  77. #define P16e_s(a) (TF(a & NAND_Ecc_P16e) << 2)
  78. #define P16o_s(a) (TF(a & NAND_Ecc_P16o) << 3)
  79. #define P1e_s(a) (TF(a & NAND_Ecc_P1e) << 4)
  80. #define P1o_s(a) (TF(a & NAND_Ecc_P1o) << 5)
  81. #define P2e_s(a) (TF(a & NAND_Ecc_P2e) << 6)
  82. #define P2o_s(a) (TF(a & NAND_Ecc_P2o) << 7)
  83. #define P4e_s(a) (TF(a & NAND_Ecc_P4e) << 0)
  84. #define P4o_s(a) (TF(a & NAND_Ecc_P4o) << 1)
  85. /* oob info generated runtime depending on ecc algorithm and layout selected */
  86. static struct nand_ecclayout omap_oobinfo;
  87. /* Define some generic bad / good block scan pattern which are used
  88. * while scanning a device for factory marked good / bad blocks
  89. */
  90. static uint8_t scan_ff_pattern[] = { 0xff };
  91. static struct nand_bbt_descr bb_descrip_flashbased = {
  92. .options = NAND_BBT_SCANEMPTY | NAND_BBT_SCANALLPAGES,
  93. .offs = 0,
  94. .len = 1,
  95. .pattern = scan_ff_pattern,
  96. };
  97. struct omap_nand_info {
  98. struct nand_hw_control controller;
  99. struct omap_nand_platform_data *pdata;
  100. struct mtd_info mtd;
  101. struct nand_chip nand;
  102. struct platform_device *pdev;
  103. int gpmc_cs;
  104. unsigned long phys_base;
  105. struct completion comp;
  106. int dma_ch;
  107. int gpmc_irq;
  108. enum {
  109. OMAP_NAND_IO_READ = 0, /* read */
  110. OMAP_NAND_IO_WRITE, /* write */
  111. } iomode;
  112. u_char *buf;
  113. int buf_len;
  114. };
  115. /**
  116. * omap_hwcontrol - hardware specific access to control-lines
  117. * @mtd: MTD device structure
  118. * @cmd: command to device
  119. * @ctrl:
  120. * NAND_NCE: bit 0 -> don't care
  121. * NAND_CLE: bit 1 -> Command Latch
  122. * NAND_ALE: bit 2 -> Address Latch
  123. *
  124. * NOTE: boards may use different bits for these!!
  125. */
  126. static void omap_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  127. {
  128. struct omap_nand_info *info = container_of(mtd,
  129. struct omap_nand_info, mtd);
  130. if (cmd != NAND_CMD_NONE) {
  131. if (ctrl & NAND_CLE)
  132. gpmc_nand_write(info->gpmc_cs, GPMC_NAND_COMMAND, cmd);
  133. else if (ctrl & NAND_ALE)
  134. gpmc_nand_write(info->gpmc_cs, GPMC_NAND_ADDRESS, cmd);
  135. else /* NAND_NCE */
  136. gpmc_nand_write(info->gpmc_cs, GPMC_NAND_DATA, cmd);
  137. }
  138. }
  139. /**
  140. * omap_read_buf8 - read data from NAND controller into buffer
  141. * @mtd: MTD device structure
  142. * @buf: buffer to store date
  143. * @len: number of bytes to read
  144. */
  145. static void omap_read_buf8(struct mtd_info *mtd, u_char *buf, int len)
  146. {
  147. struct nand_chip *nand = mtd->priv;
  148. ioread8_rep(nand->IO_ADDR_R, buf, len);
  149. }
  150. /**
  151. * omap_write_buf8 - write buffer to NAND controller
  152. * @mtd: MTD device structure
  153. * @buf: data buffer
  154. * @len: number of bytes to write
  155. */
  156. static void omap_write_buf8(struct mtd_info *mtd, const u_char *buf, int len)
  157. {
  158. struct omap_nand_info *info = container_of(mtd,
  159. struct omap_nand_info, mtd);
  160. u_char *p = (u_char *)buf;
  161. u32 status = 0;
  162. while (len--) {
  163. iowrite8(*p++, info->nand.IO_ADDR_W);
  164. /* wait until buffer is available for write */
  165. do {
  166. status = gpmc_read_status(GPMC_STATUS_BUFFER);
  167. } while (!status);
  168. }
  169. }
  170. /**
  171. * omap_read_buf16 - read data from NAND controller into buffer
  172. * @mtd: MTD device structure
  173. * @buf: buffer to store date
  174. * @len: number of bytes to read
  175. */
  176. static void omap_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
  177. {
  178. struct nand_chip *nand = mtd->priv;
  179. ioread16_rep(nand->IO_ADDR_R, buf, len / 2);
  180. }
  181. /**
  182. * omap_write_buf16 - write buffer to NAND controller
  183. * @mtd: MTD device structure
  184. * @buf: data buffer
  185. * @len: number of bytes to write
  186. */
  187. static void omap_write_buf16(struct mtd_info *mtd, const u_char * buf, int len)
  188. {
  189. struct omap_nand_info *info = container_of(mtd,
  190. struct omap_nand_info, mtd);
  191. u16 *p = (u16 *) buf;
  192. u32 status = 0;
  193. /* FIXME try bursts of writesw() or DMA ... */
  194. len >>= 1;
  195. while (len--) {
  196. iowrite16(*p++, info->nand.IO_ADDR_W);
  197. /* wait until buffer is available for write */
  198. do {
  199. status = gpmc_read_status(GPMC_STATUS_BUFFER);
  200. } while (!status);
  201. }
  202. }
  203. /**
  204. * omap_read_buf_pref - read data from NAND controller into buffer
  205. * @mtd: MTD device structure
  206. * @buf: buffer to store date
  207. * @len: number of bytes to read
  208. */
  209. static void omap_read_buf_pref(struct mtd_info *mtd, u_char *buf, int len)
  210. {
  211. struct omap_nand_info *info = container_of(mtd,
  212. struct omap_nand_info, mtd);
  213. uint32_t r_count = 0;
  214. int ret = 0;
  215. u32 *p = (u32 *)buf;
  216. /* take care of subpage reads */
  217. if (len % 4) {
  218. if (info->nand.options & NAND_BUSWIDTH_16)
  219. omap_read_buf16(mtd, buf, len % 4);
  220. else
  221. omap_read_buf8(mtd, buf, len % 4);
  222. p = (u32 *) (buf + len % 4);
  223. len -= len % 4;
  224. }
  225. /* configure and start prefetch transfer */
  226. ret = gpmc_prefetch_enable(info->gpmc_cs,
  227. PREFETCH_FIFOTHRESHOLD_MAX, 0x0, len, 0x0);
  228. if (ret) {
  229. /* PFPW engine is busy, use cpu copy method */
  230. if (info->nand.options & NAND_BUSWIDTH_16)
  231. omap_read_buf16(mtd, (u_char *)p, len);
  232. else
  233. omap_read_buf8(mtd, (u_char *)p, len);
  234. } else {
  235. do {
  236. r_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
  237. r_count = r_count >> 2;
  238. ioread32_rep(info->nand.IO_ADDR_R, p, r_count);
  239. p += r_count;
  240. len -= r_count << 2;
  241. } while (len);
  242. /* disable and stop the PFPW engine */
  243. gpmc_prefetch_reset(info->gpmc_cs);
  244. }
  245. }
  246. /**
  247. * omap_write_buf_pref - write buffer to NAND controller
  248. * @mtd: MTD device structure
  249. * @buf: data buffer
  250. * @len: number of bytes to write
  251. */
  252. static void omap_write_buf_pref(struct mtd_info *mtd,
  253. const u_char *buf, int len)
  254. {
  255. struct omap_nand_info *info = container_of(mtd,
  256. struct omap_nand_info, mtd);
  257. uint32_t w_count = 0;
  258. int i = 0, ret = 0;
  259. u16 *p = (u16 *)buf;
  260. unsigned long tim, limit;
  261. /* take care of subpage writes */
  262. if (len % 2 != 0) {
  263. writeb(*buf, info->nand.IO_ADDR_W);
  264. p = (u16 *)(buf + 1);
  265. len--;
  266. }
  267. /* configure and start prefetch transfer */
  268. ret = gpmc_prefetch_enable(info->gpmc_cs,
  269. PREFETCH_FIFOTHRESHOLD_MAX, 0x0, len, 0x1);
  270. if (ret) {
  271. /* PFPW engine is busy, use cpu copy method */
  272. if (info->nand.options & NAND_BUSWIDTH_16)
  273. omap_write_buf16(mtd, (u_char *)p, len);
  274. else
  275. omap_write_buf8(mtd, (u_char *)p, len);
  276. } else {
  277. while (len) {
  278. w_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
  279. w_count = w_count >> 1;
  280. for (i = 0; (i < w_count) && len; i++, len -= 2)
  281. iowrite16(*p++, info->nand.IO_ADDR_W);
  282. }
  283. /* wait for data to flushed-out before reset the prefetch */
  284. tim = 0;
  285. limit = (loops_per_jiffy *
  286. msecs_to_jiffies(OMAP_NAND_TIMEOUT_MS));
  287. while (gpmc_read_status(GPMC_PREFETCH_COUNT) && (tim++ < limit))
  288. cpu_relax();
  289. /* disable and stop the PFPW engine */
  290. gpmc_prefetch_reset(info->gpmc_cs);
  291. }
  292. }
  293. /*
  294. * omap_nand_dma_cb: callback on the completion of dma transfer
  295. * @lch: logical channel
  296. * @ch_satuts: channel status
  297. * @data: pointer to completion data structure
  298. */
  299. static void omap_nand_dma_cb(int lch, u16 ch_status, void *data)
  300. {
  301. complete((struct completion *) data);
  302. }
  303. /*
  304. * omap_nand_dma_transfer: configer and start dma transfer
  305. * @mtd: MTD device structure
  306. * @addr: virtual address in RAM of source/destination
  307. * @len: number of data bytes to be transferred
  308. * @is_write: flag for read/write operation
  309. */
  310. static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
  311. unsigned int len, int is_write)
  312. {
  313. struct omap_nand_info *info = container_of(mtd,
  314. struct omap_nand_info, mtd);
  315. enum dma_data_direction dir = is_write ? DMA_TO_DEVICE :
  316. DMA_FROM_DEVICE;
  317. dma_addr_t dma_addr;
  318. int ret;
  319. unsigned long tim, limit;
  320. /* The fifo depth is 64 bytes max.
  321. * But configure the FIFO-threahold to 32 to get a sync at each frame
  322. * and frame length is 32 bytes.
  323. */
  324. int buf_len = len >> 6;
  325. if (addr >= high_memory) {
  326. struct page *p1;
  327. if (((size_t)addr & PAGE_MASK) !=
  328. ((size_t)(addr + len - 1) & PAGE_MASK))
  329. goto out_copy;
  330. p1 = vmalloc_to_page(addr);
  331. if (!p1)
  332. goto out_copy;
  333. addr = page_address(p1) + ((size_t)addr & ~PAGE_MASK);
  334. }
  335. dma_addr = dma_map_single(&info->pdev->dev, addr, len, dir);
  336. if (dma_mapping_error(&info->pdev->dev, dma_addr)) {
  337. dev_err(&info->pdev->dev,
  338. "Couldn't DMA map a %d byte buffer\n", len);
  339. goto out_copy;
  340. }
  341. if (is_write) {
  342. omap_set_dma_dest_params(info->dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
  343. info->phys_base, 0, 0);
  344. omap_set_dma_src_params(info->dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
  345. dma_addr, 0, 0);
  346. omap_set_dma_transfer_params(info->dma_ch, OMAP_DMA_DATA_TYPE_S32,
  347. 0x10, buf_len, OMAP_DMA_SYNC_FRAME,
  348. OMAP24XX_DMA_GPMC, OMAP_DMA_DST_SYNC);
  349. } else {
  350. omap_set_dma_src_params(info->dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
  351. info->phys_base, 0, 0);
  352. omap_set_dma_dest_params(info->dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
  353. dma_addr, 0, 0);
  354. omap_set_dma_transfer_params(info->dma_ch, OMAP_DMA_DATA_TYPE_S32,
  355. 0x10, buf_len, OMAP_DMA_SYNC_FRAME,
  356. OMAP24XX_DMA_GPMC, OMAP_DMA_SRC_SYNC);
  357. }
  358. /* configure and start prefetch transfer */
  359. ret = gpmc_prefetch_enable(info->gpmc_cs,
  360. PREFETCH_FIFOTHRESHOLD_MAX, 0x1, len, is_write);
  361. if (ret)
  362. /* PFPW engine is busy, use cpu copy method */
  363. goto out_copy;
  364. init_completion(&info->comp);
  365. omap_start_dma(info->dma_ch);
  366. /* setup and start DMA using dma_addr */
  367. wait_for_completion(&info->comp);
  368. tim = 0;
  369. limit = (loops_per_jiffy * msecs_to_jiffies(OMAP_NAND_TIMEOUT_MS));
  370. while (gpmc_read_status(GPMC_PREFETCH_COUNT) && (tim++ < limit))
  371. cpu_relax();
  372. /* disable and stop the PFPW engine */
  373. gpmc_prefetch_reset(info->gpmc_cs);
  374. dma_unmap_single(&info->pdev->dev, dma_addr, len, dir);
  375. return 0;
  376. out_copy:
  377. if (info->nand.options & NAND_BUSWIDTH_16)
  378. is_write == 0 ? omap_read_buf16(mtd, (u_char *) addr, len)
  379. : omap_write_buf16(mtd, (u_char *) addr, len);
  380. else
  381. is_write == 0 ? omap_read_buf8(mtd, (u_char *) addr, len)
  382. : omap_write_buf8(mtd, (u_char *) addr, len);
  383. return 0;
  384. }
  385. /**
  386. * omap_read_buf_dma_pref - read data from NAND controller into buffer
  387. * @mtd: MTD device structure
  388. * @buf: buffer to store date
  389. * @len: number of bytes to read
  390. */
  391. static void omap_read_buf_dma_pref(struct mtd_info *mtd, u_char *buf, int len)
  392. {
  393. if (len <= mtd->oobsize)
  394. omap_read_buf_pref(mtd, buf, len);
  395. else
  396. /* start transfer in DMA mode */
  397. omap_nand_dma_transfer(mtd, buf, len, 0x0);
  398. }
  399. /**
  400. * omap_write_buf_dma_pref - write buffer to NAND controller
  401. * @mtd: MTD device structure
  402. * @buf: data buffer
  403. * @len: number of bytes to write
  404. */
  405. static void omap_write_buf_dma_pref(struct mtd_info *mtd,
  406. const u_char *buf, int len)
  407. {
  408. if (len <= mtd->oobsize)
  409. omap_write_buf_pref(mtd, buf, len);
  410. else
  411. /* start transfer in DMA mode */
  412. omap_nand_dma_transfer(mtd, (u_char *) buf, len, 0x1);
  413. }
  414. /*
  415. * omap_nand_irq - GMPC irq handler
  416. * @this_irq: gpmc irq number
  417. * @dev: omap_nand_info structure pointer is passed here
  418. */
  419. static irqreturn_t omap_nand_irq(int this_irq, void *dev)
  420. {
  421. struct omap_nand_info *info = (struct omap_nand_info *) dev;
  422. u32 bytes;
  423. u32 irq_stat;
  424. irq_stat = gpmc_read_status(GPMC_GET_IRQ_STATUS);
  425. bytes = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
  426. bytes = bytes & 0xFFFC; /* io in multiple of 4 bytes */
  427. if (info->iomode == OMAP_NAND_IO_WRITE) { /* checks for write io */
  428. if (irq_stat & 0x2)
  429. goto done;
  430. if (info->buf_len && (info->buf_len < bytes))
  431. bytes = info->buf_len;
  432. else if (!info->buf_len)
  433. bytes = 0;
  434. iowrite32_rep(info->nand.IO_ADDR_W,
  435. (u32 *)info->buf, bytes >> 2);
  436. info->buf = info->buf + bytes;
  437. info->buf_len -= bytes;
  438. } else {
  439. ioread32_rep(info->nand.IO_ADDR_R,
  440. (u32 *)info->buf, bytes >> 2);
  441. info->buf = info->buf + bytes;
  442. if (irq_stat & 0x2)
  443. goto done;
  444. }
  445. gpmc_cs_configure(info->gpmc_cs, GPMC_SET_IRQ_STATUS, irq_stat);
  446. return IRQ_HANDLED;
  447. done:
  448. complete(&info->comp);
  449. /* disable irq */
  450. gpmc_cs_configure(info->gpmc_cs, GPMC_ENABLE_IRQ, 0);
  451. /* clear status */
  452. gpmc_cs_configure(info->gpmc_cs, GPMC_SET_IRQ_STATUS, irq_stat);
  453. return IRQ_HANDLED;
  454. }
  455. /*
  456. * omap_read_buf_irq_pref - read data from NAND controller into buffer
  457. * @mtd: MTD device structure
  458. * @buf: buffer to store date
  459. * @len: number of bytes to read
  460. */
  461. static void omap_read_buf_irq_pref(struct mtd_info *mtd, u_char *buf, int len)
  462. {
  463. struct omap_nand_info *info = container_of(mtd,
  464. struct omap_nand_info, mtd);
  465. int ret = 0;
  466. if (len <= mtd->oobsize) {
  467. omap_read_buf_pref(mtd, buf, len);
  468. return;
  469. }
  470. info->iomode = OMAP_NAND_IO_READ;
  471. info->buf = buf;
  472. init_completion(&info->comp);
  473. /* configure and start prefetch transfer */
  474. ret = gpmc_prefetch_enable(info->gpmc_cs,
  475. PREFETCH_FIFOTHRESHOLD_MAX/2, 0x0, len, 0x0);
  476. if (ret)
  477. /* PFPW engine is busy, use cpu copy method */
  478. goto out_copy;
  479. info->buf_len = len;
  480. /* enable irq */
  481. gpmc_cs_configure(info->gpmc_cs, GPMC_ENABLE_IRQ,
  482. (GPMC_IRQ_FIFOEVENTENABLE | GPMC_IRQ_COUNT_EVENT));
  483. /* waiting for read to complete */
  484. wait_for_completion(&info->comp);
  485. /* disable and stop the PFPW engine */
  486. gpmc_prefetch_reset(info->gpmc_cs);
  487. return;
  488. out_copy:
  489. if (info->nand.options & NAND_BUSWIDTH_16)
  490. omap_read_buf16(mtd, buf, len);
  491. else
  492. omap_read_buf8(mtd, buf, len);
  493. }
  494. /*
  495. * omap_write_buf_irq_pref - write buffer to NAND controller
  496. * @mtd: MTD device structure
  497. * @buf: data buffer
  498. * @len: number of bytes to write
  499. */
  500. static void omap_write_buf_irq_pref(struct mtd_info *mtd,
  501. const u_char *buf, int len)
  502. {
  503. struct omap_nand_info *info = container_of(mtd,
  504. struct omap_nand_info, mtd);
  505. int ret = 0;
  506. unsigned long tim, limit;
  507. if (len <= mtd->oobsize) {
  508. omap_write_buf_pref(mtd, buf, len);
  509. return;
  510. }
  511. info->iomode = OMAP_NAND_IO_WRITE;
  512. info->buf = (u_char *) buf;
  513. init_completion(&info->comp);
  514. /* configure and start prefetch transfer : size=24 */
  515. ret = gpmc_prefetch_enable(info->gpmc_cs,
  516. (PREFETCH_FIFOTHRESHOLD_MAX * 3) / 8, 0x0, len, 0x1);
  517. if (ret)
  518. /* PFPW engine is busy, use cpu copy method */
  519. goto out_copy;
  520. info->buf_len = len;
  521. /* enable irq */
  522. gpmc_cs_configure(info->gpmc_cs, GPMC_ENABLE_IRQ,
  523. (GPMC_IRQ_FIFOEVENTENABLE | GPMC_IRQ_COUNT_EVENT));
  524. /* waiting for write to complete */
  525. wait_for_completion(&info->comp);
  526. /* wait for data to flushed-out before reset the prefetch */
  527. tim = 0;
  528. limit = (loops_per_jiffy * msecs_to_jiffies(OMAP_NAND_TIMEOUT_MS));
  529. while (gpmc_read_status(GPMC_PREFETCH_COUNT) && (tim++ < limit))
  530. cpu_relax();
  531. /* disable and stop the PFPW engine */
  532. gpmc_prefetch_reset(info->gpmc_cs);
  533. return;
  534. out_copy:
  535. if (info->nand.options & NAND_BUSWIDTH_16)
  536. omap_write_buf16(mtd, buf, len);
  537. else
  538. omap_write_buf8(mtd, buf, len);
  539. }
  540. /**
  541. * omap_verify_buf - Verify chip data against buffer
  542. * @mtd: MTD device structure
  543. * @buf: buffer containing the data to compare
  544. * @len: number of bytes to compare
  545. */
  546. static int omap_verify_buf(struct mtd_info *mtd, const u_char * buf, int len)
  547. {
  548. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  549. mtd);
  550. u16 *p = (u16 *) buf;
  551. len >>= 1;
  552. while (len--) {
  553. if (*p++ != cpu_to_le16(readw(info->nand.IO_ADDR_R)))
  554. return -EFAULT;
  555. }
  556. return 0;
  557. }
  558. /**
  559. * gen_true_ecc - This function will generate true ECC value
  560. * @ecc_buf: buffer to store ecc code
  561. *
  562. * This generated true ECC value can be used when correcting
  563. * data read from NAND flash memory core
  564. */
  565. static void gen_true_ecc(u8 *ecc_buf)
  566. {
  567. u32 tmp = ecc_buf[0] | (ecc_buf[1] << 16) |
  568. ((ecc_buf[2] & 0xF0) << 20) | ((ecc_buf[2] & 0x0F) << 8);
  569. ecc_buf[0] = ~(P64o(tmp) | P64e(tmp) | P32o(tmp) | P32e(tmp) |
  570. P16o(tmp) | P16e(tmp) | P8o(tmp) | P8e(tmp));
  571. ecc_buf[1] = ~(P1024o(tmp) | P1024e(tmp) | P512o(tmp) | P512e(tmp) |
  572. P256o(tmp) | P256e(tmp) | P128o(tmp) | P128e(tmp));
  573. ecc_buf[2] = ~(P4o(tmp) | P4e(tmp) | P2o(tmp) | P2e(tmp) | P1o(tmp) |
  574. P1e(tmp) | P2048o(tmp) | P2048e(tmp));
  575. }
  576. /**
  577. * omap_compare_ecc - Detect (2 bits) and correct (1 bit) error in data
  578. * @ecc_data1: ecc code from nand spare area
  579. * @ecc_data2: ecc code from hardware register obtained from hardware ecc
  580. * @page_data: page data
  581. *
  582. * This function compares two ECC's and indicates if there is an error.
  583. * If the error can be corrected it will be corrected to the buffer.
  584. * If there is no error, %0 is returned. If there is an error but it
  585. * was corrected, %1 is returned. Otherwise, %-1 is returned.
  586. */
  587. static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
  588. u8 *ecc_data2, /* read from register */
  589. u8 *page_data)
  590. {
  591. uint i;
  592. u8 tmp0_bit[8], tmp1_bit[8], tmp2_bit[8];
  593. u8 comp0_bit[8], comp1_bit[8], comp2_bit[8];
  594. u8 ecc_bit[24];
  595. u8 ecc_sum = 0;
  596. u8 find_bit = 0;
  597. uint find_byte = 0;
  598. int isEccFF;
  599. isEccFF = ((*(u32 *)ecc_data1 & 0xFFFFFF) == 0xFFFFFF);
  600. gen_true_ecc(ecc_data1);
  601. gen_true_ecc(ecc_data2);
  602. for (i = 0; i <= 2; i++) {
  603. *(ecc_data1 + i) = ~(*(ecc_data1 + i));
  604. *(ecc_data2 + i) = ~(*(ecc_data2 + i));
  605. }
  606. for (i = 0; i < 8; i++) {
  607. tmp0_bit[i] = *ecc_data1 % 2;
  608. *ecc_data1 = *ecc_data1 / 2;
  609. }
  610. for (i = 0; i < 8; i++) {
  611. tmp1_bit[i] = *(ecc_data1 + 1) % 2;
  612. *(ecc_data1 + 1) = *(ecc_data1 + 1) / 2;
  613. }
  614. for (i = 0; i < 8; i++) {
  615. tmp2_bit[i] = *(ecc_data1 + 2) % 2;
  616. *(ecc_data1 + 2) = *(ecc_data1 + 2) / 2;
  617. }
  618. for (i = 0; i < 8; i++) {
  619. comp0_bit[i] = *ecc_data2 % 2;
  620. *ecc_data2 = *ecc_data2 / 2;
  621. }
  622. for (i = 0; i < 8; i++) {
  623. comp1_bit[i] = *(ecc_data2 + 1) % 2;
  624. *(ecc_data2 + 1) = *(ecc_data2 + 1) / 2;
  625. }
  626. for (i = 0; i < 8; i++) {
  627. comp2_bit[i] = *(ecc_data2 + 2) % 2;
  628. *(ecc_data2 + 2) = *(ecc_data2 + 2) / 2;
  629. }
  630. for (i = 0; i < 6; i++)
  631. ecc_bit[i] = tmp2_bit[i + 2] ^ comp2_bit[i + 2];
  632. for (i = 0; i < 8; i++)
  633. ecc_bit[i + 6] = tmp0_bit[i] ^ comp0_bit[i];
  634. for (i = 0; i < 8; i++)
  635. ecc_bit[i + 14] = tmp1_bit[i] ^ comp1_bit[i];
  636. ecc_bit[22] = tmp2_bit[0] ^ comp2_bit[0];
  637. ecc_bit[23] = tmp2_bit[1] ^ comp2_bit[1];
  638. for (i = 0; i < 24; i++)
  639. ecc_sum += ecc_bit[i];
  640. switch (ecc_sum) {
  641. case 0:
  642. /* Not reached because this function is not called if
  643. * ECC values are equal
  644. */
  645. return 0;
  646. case 1:
  647. /* Uncorrectable error */
  648. pr_debug("ECC UNCORRECTED_ERROR 1\n");
  649. return -1;
  650. case 11:
  651. /* UN-Correctable error */
  652. pr_debug("ECC UNCORRECTED_ERROR B\n");
  653. return -1;
  654. case 12:
  655. /* Correctable error */
  656. find_byte = (ecc_bit[23] << 8) +
  657. (ecc_bit[21] << 7) +
  658. (ecc_bit[19] << 6) +
  659. (ecc_bit[17] << 5) +
  660. (ecc_bit[15] << 4) +
  661. (ecc_bit[13] << 3) +
  662. (ecc_bit[11] << 2) +
  663. (ecc_bit[9] << 1) +
  664. ecc_bit[7];
  665. find_bit = (ecc_bit[5] << 2) + (ecc_bit[3] << 1) + ecc_bit[1];
  666. pr_debug("Correcting single bit ECC error at offset: "
  667. "%d, bit: %d\n", find_byte, find_bit);
  668. page_data[find_byte] ^= (1 << find_bit);
  669. return 1;
  670. default:
  671. if (isEccFF) {
  672. if (ecc_data2[0] == 0 &&
  673. ecc_data2[1] == 0 &&
  674. ecc_data2[2] == 0)
  675. return 0;
  676. }
  677. pr_debug("UNCORRECTED_ERROR default\n");
  678. return -1;
  679. }
  680. }
  681. /**
  682. * omap_correct_data - Compares the ECC read with HW generated ECC
  683. * @mtd: MTD device structure
  684. * @dat: page data
  685. * @read_ecc: ecc read from nand flash
  686. * @calc_ecc: ecc read from HW ECC registers
  687. *
  688. * Compares the ecc read from nand spare area with ECC registers values
  689. * and if ECC's mismatched, it will call 'omap_compare_ecc' for error
  690. * detection and correction. If there are no errors, %0 is returned. If
  691. * there were errors and all of the errors were corrected, the number of
  692. * corrected errors is returned. If uncorrectable errors exist, %-1 is
  693. * returned.
  694. */
  695. static int omap_correct_data(struct mtd_info *mtd, u_char *dat,
  696. u_char *read_ecc, u_char *calc_ecc)
  697. {
  698. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  699. mtd);
  700. int blockCnt = 0, i = 0, ret = 0;
  701. int stat = 0;
  702. /* Ex NAND_ECC_HW12_2048 */
  703. if ((info->nand.ecc.mode == NAND_ECC_HW) &&
  704. (info->nand.ecc.size == 2048))
  705. blockCnt = 4;
  706. else
  707. blockCnt = 1;
  708. for (i = 0; i < blockCnt; i++) {
  709. if (memcmp(read_ecc, calc_ecc, 3) != 0) {
  710. ret = omap_compare_ecc(read_ecc, calc_ecc, dat);
  711. if (ret < 0)
  712. return ret;
  713. /* keep track of the number of corrected errors */
  714. stat += ret;
  715. }
  716. read_ecc += 3;
  717. calc_ecc += 3;
  718. dat += 512;
  719. }
  720. return stat;
  721. }
  722. /**
  723. * omap_calcuate_ecc - Generate non-inverted ECC bytes.
  724. * @mtd: MTD device structure
  725. * @dat: The pointer to data on which ecc is computed
  726. * @ecc_code: The ecc_code buffer
  727. *
  728. * Using noninverted ECC can be considered ugly since writing a blank
  729. * page ie. padding will clear the ECC bytes. This is no problem as long
  730. * nobody is trying to write data on the seemingly unused page. Reading
  731. * an erased page will produce an ECC mismatch between generated and read
  732. * ECC bytes that has to be dealt with separately.
  733. */
  734. static int omap_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
  735. u_char *ecc_code)
  736. {
  737. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  738. mtd);
  739. return gpmc_calculate_ecc(info->gpmc_cs, dat, ecc_code);
  740. }
  741. /**
  742. * omap_enable_hwecc - This function enables the hardware ecc functionality
  743. * @mtd: MTD device structure
  744. * @mode: Read/Write mode
  745. */
  746. static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
  747. {
  748. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  749. mtd);
  750. struct nand_chip *chip = mtd->priv;
  751. unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
  752. gpmc_enable_hwecc(info->gpmc_cs, mode, dev_width, info->nand.ecc.size);
  753. }
  754. /**
  755. * omap_wait - wait until the command is done
  756. * @mtd: MTD device structure
  757. * @chip: NAND Chip structure
  758. *
  759. * Wait function is called during Program and erase operations and
  760. * the way it is called from MTD layer, we should wait till the NAND
  761. * chip is ready after the programming/erase operation has completed.
  762. *
  763. * Erase can take up to 400ms and program up to 20ms according to
  764. * general NAND and SmartMedia specs
  765. */
  766. static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
  767. {
  768. struct nand_chip *this = mtd->priv;
  769. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  770. mtd);
  771. unsigned long timeo = jiffies;
  772. int status = NAND_STATUS_FAIL, state = this->state;
  773. if (state == FL_ERASING)
  774. timeo += (HZ * 400) / 1000;
  775. else
  776. timeo += (HZ * 20) / 1000;
  777. gpmc_nand_write(info->gpmc_cs,
  778. GPMC_NAND_COMMAND, (NAND_CMD_STATUS & 0xFF));
  779. while (time_before(jiffies, timeo)) {
  780. status = gpmc_nand_read(info->gpmc_cs, GPMC_NAND_DATA);
  781. if (status & NAND_STATUS_READY)
  782. break;
  783. cond_resched();
  784. }
  785. return status;
  786. }
  787. /**
  788. * omap_dev_ready - calls the platform specific dev_ready function
  789. * @mtd: MTD device structure
  790. */
  791. static int omap_dev_ready(struct mtd_info *mtd)
  792. {
  793. unsigned int val = 0;
  794. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  795. mtd);
  796. val = gpmc_read_status(GPMC_GET_IRQ_STATUS);
  797. if ((val & 0x100) == 0x100) {
  798. /* Clear IRQ Interrupt */
  799. val |= 0x100;
  800. val &= ~(0x0);
  801. gpmc_cs_configure(info->gpmc_cs, GPMC_SET_IRQ_STATUS, val);
  802. } else {
  803. unsigned int cnt = 0;
  804. while (cnt++ < 0x1FF) {
  805. if ((val & 0x100) == 0x100)
  806. return 0;
  807. val = gpmc_read_status(GPMC_GET_IRQ_STATUS);
  808. }
  809. }
  810. return 1;
  811. }
  812. static int __devinit omap_nand_probe(struct platform_device *pdev)
  813. {
  814. struct omap_nand_info *info;
  815. struct omap_nand_platform_data *pdata;
  816. int err;
  817. int i, offset;
  818. pdata = pdev->dev.platform_data;
  819. if (pdata == NULL) {
  820. dev_err(&pdev->dev, "platform data missing\n");
  821. return -ENODEV;
  822. }
  823. info = kzalloc(sizeof(struct omap_nand_info), GFP_KERNEL);
  824. if (!info)
  825. return -ENOMEM;
  826. platform_set_drvdata(pdev, info);
  827. spin_lock_init(&info->controller.lock);
  828. init_waitqueue_head(&info->controller.wq);
  829. info->pdev = pdev;
  830. info->gpmc_cs = pdata->cs;
  831. info->phys_base = pdata->phys_base;
  832. info->mtd.priv = &info->nand;
  833. info->mtd.name = dev_name(&pdev->dev);
  834. info->mtd.owner = THIS_MODULE;
  835. info->nand.options = pdata->devsize;
  836. info->nand.options |= NAND_SKIP_BBTSCAN;
  837. /* NAND write protect off */
  838. gpmc_cs_configure(info->gpmc_cs, GPMC_CONFIG_WP, 0);
  839. if (!request_mem_region(info->phys_base, NAND_IO_SIZE,
  840. pdev->dev.driver->name)) {
  841. err = -EBUSY;
  842. goto out_free_info;
  843. }
  844. info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE);
  845. if (!info->nand.IO_ADDR_R) {
  846. err = -ENOMEM;
  847. goto out_release_mem_region;
  848. }
  849. info->nand.controller = &info->controller;
  850. info->nand.IO_ADDR_W = info->nand.IO_ADDR_R;
  851. info->nand.cmd_ctrl = omap_hwcontrol;
  852. /*
  853. * If RDY/BSY line is connected to OMAP then use the omap ready
  854. * funcrtion and the generic nand_wait function which reads the status
  855. * register after monitoring the RDY/BSY line.Otherwise use a standard
  856. * chip delay which is slightly more than tR (AC Timing) of the NAND
  857. * device and read status register until you get a failure or success
  858. */
  859. if (pdata->dev_ready) {
  860. info->nand.dev_ready = omap_dev_ready;
  861. info->nand.chip_delay = 0;
  862. } else {
  863. info->nand.waitfunc = omap_wait;
  864. info->nand.chip_delay = 50;
  865. }
  866. switch (pdata->xfer_type) {
  867. case NAND_OMAP_PREFETCH_POLLED:
  868. info->nand.read_buf = omap_read_buf_pref;
  869. info->nand.write_buf = omap_write_buf_pref;
  870. break;
  871. case NAND_OMAP_POLLED:
  872. if (info->nand.options & NAND_BUSWIDTH_16) {
  873. info->nand.read_buf = omap_read_buf16;
  874. info->nand.write_buf = omap_write_buf16;
  875. } else {
  876. info->nand.read_buf = omap_read_buf8;
  877. info->nand.write_buf = omap_write_buf8;
  878. }
  879. break;
  880. case NAND_OMAP_PREFETCH_DMA:
  881. err = omap_request_dma(OMAP24XX_DMA_GPMC, "NAND",
  882. omap_nand_dma_cb, &info->comp, &info->dma_ch);
  883. if (err < 0) {
  884. info->dma_ch = -1;
  885. dev_err(&pdev->dev, "DMA request failed!\n");
  886. goto out_release_mem_region;
  887. } else {
  888. omap_set_dma_dest_burst_mode(info->dma_ch,
  889. OMAP_DMA_DATA_BURST_16);
  890. omap_set_dma_src_burst_mode(info->dma_ch,
  891. OMAP_DMA_DATA_BURST_16);
  892. info->nand.read_buf = omap_read_buf_dma_pref;
  893. info->nand.write_buf = omap_write_buf_dma_pref;
  894. }
  895. break;
  896. case NAND_OMAP_PREFETCH_IRQ:
  897. err = request_irq(pdata->gpmc_irq,
  898. omap_nand_irq, IRQF_SHARED, "gpmc-nand", info);
  899. if (err) {
  900. dev_err(&pdev->dev, "requesting irq(%d) error:%d",
  901. pdata->gpmc_irq, err);
  902. goto out_release_mem_region;
  903. } else {
  904. info->gpmc_irq = pdata->gpmc_irq;
  905. info->nand.read_buf = omap_read_buf_irq_pref;
  906. info->nand.write_buf = omap_write_buf_irq_pref;
  907. }
  908. break;
  909. default:
  910. dev_err(&pdev->dev,
  911. "xfer_type(%d) not supported!\n", pdata->xfer_type);
  912. err = -EINVAL;
  913. goto out_release_mem_region;
  914. }
  915. info->nand.verify_buf = omap_verify_buf;
  916. /* selsect the ecc type */
  917. if (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_DEFAULT)
  918. info->nand.ecc.mode = NAND_ECC_SOFT;
  919. else if ((pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW) ||
  920. (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW_ROMCODE)) {
  921. info->nand.ecc.bytes = 3;
  922. info->nand.ecc.size = 512;
  923. info->nand.ecc.calculate = omap_calculate_ecc;
  924. info->nand.ecc.hwctl = omap_enable_hwecc;
  925. info->nand.ecc.correct = omap_correct_data;
  926. info->nand.ecc.mode = NAND_ECC_HW;
  927. }
  928. /* DIP switches on some boards change between 8 and 16 bit
  929. * bus widths for flash. Try the other width if the first try fails.
  930. */
  931. if (nand_scan_ident(&info->mtd, 1, NULL)) {
  932. info->nand.options ^= NAND_BUSWIDTH_16;
  933. if (nand_scan_ident(&info->mtd, 1, NULL)) {
  934. err = -ENXIO;
  935. goto out_release_mem_region;
  936. }
  937. }
  938. /* rom code layout */
  939. if (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW_ROMCODE) {
  940. if (info->nand.options & NAND_BUSWIDTH_16)
  941. offset = 2;
  942. else {
  943. offset = 1;
  944. info->nand.badblock_pattern = &bb_descrip_flashbased;
  945. }
  946. omap_oobinfo.eccbytes = 3 * (info->mtd.oobsize/16);
  947. for (i = 0; i < omap_oobinfo.eccbytes; i++)
  948. omap_oobinfo.eccpos[i] = i+offset;
  949. omap_oobinfo.oobfree->offset = offset + omap_oobinfo.eccbytes;
  950. omap_oobinfo.oobfree->length = info->mtd.oobsize -
  951. (offset + omap_oobinfo.eccbytes);
  952. info->nand.ecc.layout = &omap_oobinfo;
  953. }
  954. /* second phase scan */
  955. if (nand_scan_tail(&info->mtd)) {
  956. err = -ENXIO;
  957. goto out_release_mem_region;
  958. }
  959. mtd_device_parse_register(&info->mtd, NULL, 0,
  960. pdata->parts, pdata->nr_parts);
  961. platform_set_drvdata(pdev, &info->mtd);
  962. return 0;
  963. out_release_mem_region:
  964. release_mem_region(info->phys_base, NAND_IO_SIZE);
  965. out_free_info:
  966. kfree(info);
  967. return err;
  968. }
  969. static int omap_nand_remove(struct platform_device *pdev)
  970. {
  971. struct mtd_info *mtd = platform_get_drvdata(pdev);
  972. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  973. mtd);
  974. platform_set_drvdata(pdev, NULL);
  975. if (info->dma_ch != -1)
  976. omap_free_dma(info->dma_ch);
  977. if (info->gpmc_irq)
  978. free_irq(info->gpmc_irq, info);
  979. /* Release NAND device, its internal structures and partitions */
  980. nand_release(&info->mtd);
  981. iounmap(info->nand.IO_ADDR_R);
  982. kfree(&info->mtd);
  983. return 0;
  984. }
  985. static struct platform_driver omap_nand_driver = {
  986. .probe = omap_nand_probe,
  987. .remove = omap_nand_remove,
  988. .driver = {
  989. .name = DRIVER_NAME,
  990. .owner = THIS_MODULE,
  991. },
  992. };
  993. static int __init omap_nand_init(void)
  994. {
  995. pr_info("%s driver initializing\n", DRIVER_NAME);
  996. return platform_driver_register(&omap_nand_driver);
  997. }
  998. static void __exit omap_nand_exit(void)
  999. {
  1000. platform_driver_unregister(&omap_nand_driver);
  1001. }
  1002. module_init(omap_nand_init);
  1003. module_exit(omap_nand_exit);
  1004. MODULE_ALIAS("platform:" DRIVER_NAME);
  1005. MODULE_LICENSE("GPL");
  1006. MODULE_DESCRIPTION("Glue layer for NAND flash on TI OMAP boards");