omap2.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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. * If there is no error, %0 is returned. If there is an error but it
  591. * was corrected, %1 is returned. Otherwise, %-1 is returned.
  592. */
  593. static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
  594. u8 *ecc_data2, /* read from register */
  595. u8 *page_data)
  596. {
  597. uint i;
  598. u8 tmp0_bit[8], tmp1_bit[8], tmp2_bit[8];
  599. u8 comp0_bit[8], comp1_bit[8], comp2_bit[8];
  600. u8 ecc_bit[24];
  601. u8 ecc_sum = 0;
  602. u8 find_bit = 0;
  603. uint find_byte = 0;
  604. int isEccFF;
  605. isEccFF = ((*(u32 *)ecc_data1 & 0xFFFFFF) == 0xFFFFFF);
  606. gen_true_ecc(ecc_data1);
  607. gen_true_ecc(ecc_data2);
  608. for (i = 0; i <= 2; i++) {
  609. *(ecc_data1 + i) = ~(*(ecc_data1 + i));
  610. *(ecc_data2 + i) = ~(*(ecc_data2 + i));
  611. }
  612. for (i = 0; i < 8; i++) {
  613. tmp0_bit[i] = *ecc_data1 % 2;
  614. *ecc_data1 = *ecc_data1 / 2;
  615. }
  616. for (i = 0; i < 8; i++) {
  617. tmp1_bit[i] = *(ecc_data1 + 1) % 2;
  618. *(ecc_data1 + 1) = *(ecc_data1 + 1) / 2;
  619. }
  620. for (i = 0; i < 8; i++) {
  621. tmp2_bit[i] = *(ecc_data1 + 2) % 2;
  622. *(ecc_data1 + 2) = *(ecc_data1 + 2) / 2;
  623. }
  624. for (i = 0; i < 8; i++) {
  625. comp0_bit[i] = *ecc_data2 % 2;
  626. *ecc_data2 = *ecc_data2 / 2;
  627. }
  628. for (i = 0; i < 8; i++) {
  629. comp1_bit[i] = *(ecc_data2 + 1) % 2;
  630. *(ecc_data2 + 1) = *(ecc_data2 + 1) / 2;
  631. }
  632. for (i = 0; i < 8; i++) {
  633. comp2_bit[i] = *(ecc_data2 + 2) % 2;
  634. *(ecc_data2 + 2) = *(ecc_data2 + 2) / 2;
  635. }
  636. for (i = 0; i < 6; i++)
  637. ecc_bit[i] = tmp2_bit[i + 2] ^ comp2_bit[i + 2];
  638. for (i = 0; i < 8; i++)
  639. ecc_bit[i + 6] = tmp0_bit[i] ^ comp0_bit[i];
  640. for (i = 0; i < 8; i++)
  641. ecc_bit[i + 14] = tmp1_bit[i] ^ comp1_bit[i];
  642. ecc_bit[22] = tmp2_bit[0] ^ comp2_bit[0];
  643. ecc_bit[23] = tmp2_bit[1] ^ comp2_bit[1];
  644. for (i = 0; i < 24; i++)
  645. ecc_sum += ecc_bit[i];
  646. switch (ecc_sum) {
  647. case 0:
  648. /* Not reached because this function is not called if
  649. * ECC values are equal
  650. */
  651. return 0;
  652. case 1:
  653. /* Uncorrectable error */
  654. DEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR 1\n");
  655. return -1;
  656. case 11:
  657. /* UN-Correctable error */
  658. DEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR B\n");
  659. return -1;
  660. case 12:
  661. /* Correctable error */
  662. find_byte = (ecc_bit[23] << 8) +
  663. (ecc_bit[21] << 7) +
  664. (ecc_bit[19] << 6) +
  665. (ecc_bit[17] << 5) +
  666. (ecc_bit[15] << 4) +
  667. (ecc_bit[13] << 3) +
  668. (ecc_bit[11] << 2) +
  669. (ecc_bit[9] << 1) +
  670. ecc_bit[7];
  671. find_bit = (ecc_bit[5] << 2) + (ecc_bit[3] << 1) + ecc_bit[1];
  672. DEBUG(MTD_DEBUG_LEVEL0, "Correcting single bit ECC error at "
  673. "offset: %d, bit: %d\n", find_byte, find_bit);
  674. page_data[find_byte] ^= (1 << find_bit);
  675. return 1;
  676. default:
  677. if (isEccFF) {
  678. if (ecc_data2[0] == 0 &&
  679. ecc_data2[1] == 0 &&
  680. ecc_data2[2] == 0)
  681. return 0;
  682. }
  683. DEBUG(MTD_DEBUG_LEVEL0, "UNCORRECTED_ERROR default\n");
  684. return -1;
  685. }
  686. }
  687. /**
  688. * omap_correct_data - Compares the ECC read with HW generated ECC
  689. * @mtd: MTD device structure
  690. * @dat: page data
  691. * @read_ecc: ecc read from nand flash
  692. * @calc_ecc: ecc read from HW ECC registers
  693. *
  694. * Compares the ecc read from nand spare area with ECC registers values
  695. * and if ECC's mismatched, it will call 'omap_compare_ecc' for error
  696. * detection and correction. If there are no errors, %0 is returned. If
  697. * there were errors and all of the errors were corrected, the number of
  698. * corrected errors is returned. If uncorrectable errors exist, %-1 is
  699. * returned.
  700. */
  701. static int omap_correct_data(struct mtd_info *mtd, u_char *dat,
  702. u_char *read_ecc, u_char *calc_ecc)
  703. {
  704. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  705. mtd);
  706. int blockCnt = 0, i = 0, ret = 0;
  707. int stat = 0;
  708. /* Ex NAND_ECC_HW12_2048 */
  709. if ((info->nand.ecc.mode == NAND_ECC_HW) &&
  710. (info->nand.ecc.size == 2048))
  711. blockCnt = 4;
  712. else
  713. blockCnt = 1;
  714. for (i = 0; i < blockCnt; i++) {
  715. if (memcmp(read_ecc, calc_ecc, 3) != 0) {
  716. ret = omap_compare_ecc(read_ecc, calc_ecc, dat);
  717. if (ret < 0)
  718. return ret;
  719. /* keep track of the number of corrected errors */
  720. stat += ret;
  721. }
  722. read_ecc += 3;
  723. calc_ecc += 3;
  724. dat += 512;
  725. }
  726. return stat;
  727. }
  728. /**
  729. * omap_calcuate_ecc - Generate non-inverted ECC bytes.
  730. * @mtd: MTD device structure
  731. * @dat: The pointer to data on which ecc is computed
  732. * @ecc_code: The ecc_code buffer
  733. *
  734. * Using noninverted ECC can be considered ugly since writing a blank
  735. * page ie. padding will clear the ECC bytes. This is no problem as long
  736. * nobody is trying to write data on the seemingly unused page. Reading
  737. * an erased page will produce an ECC mismatch between generated and read
  738. * ECC bytes that has to be dealt with separately.
  739. */
  740. static int omap_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
  741. u_char *ecc_code)
  742. {
  743. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  744. mtd);
  745. return gpmc_calculate_ecc(info->gpmc_cs, dat, ecc_code);
  746. }
  747. /**
  748. * omap_enable_hwecc - This function enables the hardware ecc functionality
  749. * @mtd: MTD device structure
  750. * @mode: Read/Write mode
  751. */
  752. static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
  753. {
  754. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  755. mtd);
  756. struct nand_chip *chip = mtd->priv;
  757. unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
  758. gpmc_enable_hwecc(info->gpmc_cs, mode, dev_width, info->nand.ecc.size);
  759. }
  760. /**
  761. * omap_wait - wait until the command is done
  762. * @mtd: MTD device structure
  763. * @chip: NAND Chip structure
  764. *
  765. * Wait function is called during Program and erase operations and
  766. * the way it is called from MTD layer, we should wait till the NAND
  767. * chip is ready after the programming/erase operation has completed.
  768. *
  769. * Erase can take up to 400ms and program up to 20ms according to
  770. * general NAND and SmartMedia specs
  771. */
  772. static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
  773. {
  774. struct nand_chip *this = mtd->priv;
  775. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  776. mtd);
  777. unsigned long timeo = jiffies;
  778. int status = NAND_STATUS_FAIL, state = this->state;
  779. if (state == FL_ERASING)
  780. timeo += (HZ * 400) / 1000;
  781. else
  782. timeo += (HZ * 20) / 1000;
  783. gpmc_nand_write(info->gpmc_cs,
  784. GPMC_NAND_COMMAND, (NAND_CMD_STATUS & 0xFF));
  785. while (time_before(jiffies, timeo)) {
  786. status = gpmc_nand_read(info->gpmc_cs, GPMC_NAND_DATA);
  787. if (status & NAND_STATUS_READY)
  788. break;
  789. cond_resched();
  790. }
  791. return status;
  792. }
  793. /**
  794. * omap_dev_ready - calls the platform specific dev_ready function
  795. * @mtd: MTD device structure
  796. */
  797. static int omap_dev_ready(struct mtd_info *mtd)
  798. {
  799. unsigned int val = 0;
  800. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  801. mtd);
  802. val = gpmc_read_status(GPMC_GET_IRQ_STATUS);
  803. if ((val & 0x100) == 0x100) {
  804. /* Clear IRQ Interrupt */
  805. val |= 0x100;
  806. val &= ~(0x0);
  807. gpmc_cs_configure(info->gpmc_cs, GPMC_SET_IRQ_STATUS, val);
  808. } else {
  809. unsigned int cnt = 0;
  810. while (cnt++ < 0x1FF) {
  811. if ((val & 0x100) == 0x100)
  812. return 0;
  813. val = gpmc_read_status(GPMC_GET_IRQ_STATUS);
  814. }
  815. }
  816. return 1;
  817. }
  818. static int __devinit omap_nand_probe(struct platform_device *pdev)
  819. {
  820. struct omap_nand_info *info;
  821. struct omap_nand_platform_data *pdata;
  822. int err;
  823. int i, offset;
  824. pdata = pdev->dev.platform_data;
  825. if (pdata == NULL) {
  826. dev_err(&pdev->dev, "platform data missing\n");
  827. return -ENODEV;
  828. }
  829. info = kzalloc(sizeof(struct omap_nand_info), GFP_KERNEL);
  830. if (!info)
  831. return -ENOMEM;
  832. platform_set_drvdata(pdev, info);
  833. spin_lock_init(&info->controller.lock);
  834. init_waitqueue_head(&info->controller.wq);
  835. info->pdev = pdev;
  836. info->gpmc_cs = pdata->cs;
  837. info->phys_base = pdata->phys_base;
  838. info->mtd.priv = &info->nand;
  839. info->mtd.name = dev_name(&pdev->dev);
  840. info->mtd.owner = THIS_MODULE;
  841. info->nand.options = pdata->devsize;
  842. info->nand.options |= NAND_SKIP_BBTSCAN;
  843. /* NAND write protect off */
  844. gpmc_cs_configure(info->gpmc_cs, GPMC_CONFIG_WP, 0);
  845. if (!request_mem_region(info->phys_base, NAND_IO_SIZE,
  846. pdev->dev.driver->name)) {
  847. err = -EBUSY;
  848. goto out_free_info;
  849. }
  850. info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE);
  851. if (!info->nand.IO_ADDR_R) {
  852. err = -ENOMEM;
  853. goto out_release_mem_region;
  854. }
  855. info->nand.controller = &info->controller;
  856. info->nand.IO_ADDR_W = info->nand.IO_ADDR_R;
  857. info->nand.cmd_ctrl = omap_hwcontrol;
  858. /*
  859. * If RDY/BSY line is connected to OMAP then use the omap ready
  860. * funcrtion and the generic nand_wait function which reads the status
  861. * register after monitoring the RDY/BSY line.Otherwise use a standard
  862. * chip delay which is slightly more than tR (AC Timing) of the NAND
  863. * device and read status register until you get a failure or success
  864. */
  865. if (pdata->dev_ready) {
  866. info->nand.dev_ready = omap_dev_ready;
  867. info->nand.chip_delay = 0;
  868. } else {
  869. info->nand.waitfunc = omap_wait;
  870. info->nand.chip_delay = 50;
  871. }
  872. switch (pdata->xfer_type) {
  873. case NAND_OMAP_PREFETCH_POLLED:
  874. info->nand.read_buf = omap_read_buf_pref;
  875. info->nand.write_buf = omap_write_buf_pref;
  876. break;
  877. case NAND_OMAP_POLLED:
  878. if (info->nand.options & NAND_BUSWIDTH_16) {
  879. info->nand.read_buf = omap_read_buf16;
  880. info->nand.write_buf = omap_write_buf16;
  881. } else {
  882. info->nand.read_buf = omap_read_buf8;
  883. info->nand.write_buf = omap_write_buf8;
  884. }
  885. break;
  886. case NAND_OMAP_PREFETCH_DMA:
  887. err = omap_request_dma(OMAP24XX_DMA_GPMC, "NAND",
  888. omap_nand_dma_cb, &info->comp, &info->dma_ch);
  889. if (err < 0) {
  890. info->dma_ch = -1;
  891. dev_err(&pdev->dev, "DMA request failed!\n");
  892. goto out_release_mem_region;
  893. } else {
  894. omap_set_dma_dest_burst_mode(info->dma_ch,
  895. OMAP_DMA_DATA_BURST_16);
  896. omap_set_dma_src_burst_mode(info->dma_ch,
  897. OMAP_DMA_DATA_BURST_16);
  898. info->nand.read_buf = omap_read_buf_dma_pref;
  899. info->nand.write_buf = omap_write_buf_dma_pref;
  900. }
  901. break;
  902. case NAND_OMAP_PREFETCH_IRQ:
  903. err = request_irq(pdata->gpmc_irq,
  904. omap_nand_irq, IRQF_SHARED, "gpmc-nand", info);
  905. if (err) {
  906. dev_err(&pdev->dev, "requesting irq(%d) error:%d",
  907. pdata->gpmc_irq, err);
  908. goto out_release_mem_region;
  909. } else {
  910. info->gpmc_irq = pdata->gpmc_irq;
  911. info->nand.read_buf = omap_read_buf_irq_pref;
  912. info->nand.write_buf = omap_write_buf_irq_pref;
  913. }
  914. break;
  915. default:
  916. dev_err(&pdev->dev,
  917. "xfer_type(%d) not supported!\n", pdata->xfer_type);
  918. err = -EINVAL;
  919. goto out_release_mem_region;
  920. }
  921. info->nand.verify_buf = omap_verify_buf;
  922. /* selsect the ecc type */
  923. if (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_DEFAULT)
  924. info->nand.ecc.mode = NAND_ECC_SOFT;
  925. else if ((pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW) ||
  926. (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW_ROMCODE)) {
  927. info->nand.ecc.bytes = 3;
  928. info->nand.ecc.size = 512;
  929. info->nand.ecc.calculate = omap_calculate_ecc;
  930. info->nand.ecc.hwctl = omap_enable_hwecc;
  931. info->nand.ecc.correct = omap_correct_data;
  932. info->nand.ecc.mode = NAND_ECC_HW;
  933. }
  934. /* DIP switches on some boards change between 8 and 16 bit
  935. * bus widths for flash. Try the other width if the first try fails.
  936. */
  937. if (nand_scan(&info->mtd, 1)) {
  938. info->nand.options ^= NAND_BUSWIDTH_16;
  939. if (nand_scan(&info->mtd, 1)) {
  940. err = -ENXIO;
  941. goto out_release_mem_region;
  942. }
  943. }
  944. /* rom code layout */
  945. if (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW_ROMCODE) {
  946. if (info->nand.options & NAND_BUSWIDTH_16)
  947. offset = 2;
  948. else {
  949. offset = 1;
  950. info->nand.badblock_pattern = &bb_descrip_flashbased;
  951. }
  952. omap_oobinfo.eccbytes = 3 * (info->mtd.oobsize/16);
  953. for (i = 0; i < omap_oobinfo.eccbytes; i++)
  954. omap_oobinfo.eccpos[i] = i+offset;
  955. omap_oobinfo.oobfree->offset = offset + omap_oobinfo.eccbytes;
  956. omap_oobinfo.oobfree->length = info->mtd.oobsize -
  957. (offset + omap_oobinfo.eccbytes);
  958. info->nand.ecc.layout = &omap_oobinfo;
  959. }
  960. #ifdef CONFIG_MTD_PARTITIONS
  961. err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
  962. if (err > 0)
  963. add_mtd_partitions(&info->mtd, info->parts, err);
  964. else if (pdata->parts)
  965. add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts);
  966. else
  967. #endif
  968. add_mtd_device(&info->mtd);
  969. platform_set_drvdata(pdev, &info->mtd);
  970. return 0;
  971. out_release_mem_region:
  972. release_mem_region(info->phys_base, NAND_IO_SIZE);
  973. out_free_info:
  974. kfree(info);
  975. return err;
  976. }
  977. static int omap_nand_remove(struct platform_device *pdev)
  978. {
  979. struct mtd_info *mtd = platform_get_drvdata(pdev);
  980. struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
  981. mtd);
  982. platform_set_drvdata(pdev, NULL);
  983. if (info->dma_ch != -1)
  984. omap_free_dma(info->dma_ch);
  985. if (info->gpmc_irq)
  986. free_irq(info->gpmc_irq, info);
  987. /* Release NAND device, its internal structures and partitions */
  988. nand_release(&info->mtd);
  989. iounmap(info->nand.IO_ADDR_R);
  990. kfree(&info->mtd);
  991. return 0;
  992. }
  993. static struct platform_driver omap_nand_driver = {
  994. .probe = omap_nand_probe,
  995. .remove = omap_nand_remove,
  996. .driver = {
  997. .name = DRIVER_NAME,
  998. .owner = THIS_MODULE,
  999. },
  1000. };
  1001. static int __init omap_nand_init(void)
  1002. {
  1003. pr_info("%s driver initializing\n", DRIVER_NAME);
  1004. return platform_driver_register(&omap_nand_driver);
  1005. }
  1006. static void __exit omap_nand_exit(void)
  1007. {
  1008. platform_driver_unregister(&omap_nand_driver);
  1009. }
  1010. module_init(omap_nand_init);
  1011. module_exit(omap_nand_exit);
  1012. MODULE_ALIAS("platform:" DRIVER_NAME);
  1013. MODULE_LICENSE("GPL");
  1014. MODULE_DESCRIPTION("Glue layer for NAND flash on TI OMAP boards");