omap2.c 31 KB

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