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