pxa3xx_nand.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*
  2. * drivers/mtd/nand/pxa3xx_nand.c
  3. *
  4. * Copyright © 2005 Intel Corporation
  5. * Copyright © 2006 Marvell International Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/delay.h>
  16. #include <linux/clk.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/irq.h>
  22. #include <asm/dma.h>
  23. #include <mach/pxa-regs.h>
  24. #include <mach/pxa3xx_nand.h>
  25. #define CHIP_DELAY_TIMEOUT (2 * HZ/10)
  26. /* registers and bit definitions */
  27. #define NDCR (0x00) /* Control register */
  28. #define NDTR0CS0 (0x04) /* Timing Parameter 0 for CS0 */
  29. #define NDTR1CS0 (0x0C) /* Timing Parameter 1 for CS0 */
  30. #define NDSR (0x14) /* Status Register */
  31. #define NDPCR (0x18) /* Page Count Register */
  32. #define NDBDR0 (0x1C) /* Bad Block Register 0 */
  33. #define NDBDR1 (0x20) /* Bad Block Register 1 */
  34. #define NDDB (0x40) /* Data Buffer */
  35. #define NDCB0 (0x48) /* Command Buffer0 */
  36. #define NDCB1 (0x4C) /* Command Buffer1 */
  37. #define NDCB2 (0x50) /* Command Buffer2 */
  38. #define NDCR_SPARE_EN (0x1 << 31)
  39. #define NDCR_ECC_EN (0x1 << 30)
  40. #define NDCR_DMA_EN (0x1 << 29)
  41. #define NDCR_ND_RUN (0x1 << 28)
  42. #define NDCR_DWIDTH_C (0x1 << 27)
  43. #define NDCR_DWIDTH_M (0x1 << 26)
  44. #define NDCR_PAGE_SZ (0x1 << 24)
  45. #define NDCR_NCSX (0x1 << 23)
  46. #define NDCR_ND_MODE (0x3 << 21)
  47. #define NDCR_NAND_MODE (0x0)
  48. #define NDCR_CLR_PG_CNT (0x1 << 20)
  49. #define NDCR_CLR_ECC (0x1 << 19)
  50. #define NDCR_RD_ID_CNT_MASK (0x7 << 16)
  51. #define NDCR_RD_ID_CNT(x) (((x) << 16) & NDCR_RD_ID_CNT_MASK)
  52. #define NDCR_RA_START (0x1 << 15)
  53. #define NDCR_PG_PER_BLK (0x1 << 14)
  54. #define NDCR_ND_ARB_EN (0x1 << 12)
  55. #define NDSR_MASK (0xfff)
  56. #define NDSR_RDY (0x1 << 11)
  57. #define NDSR_CS0_PAGED (0x1 << 10)
  58. #define NDSR_CS1_PAGED (0x1 << 9)
  59. #define NDSR_CS0_CMDD (0x1 << 8)
  60. #define NDSR_CS1_CMDD (0x1 << 7)
  61. #define NDSR_CS0_BBD (0x1 << 6)
  62. #define NDSR_CS1_BBD (0x1 << 5)
  63. #define NDSR_DBERR (0x1 << 4)
  64. #define NDSR_SBERR (0x1 << 3)
  65. #define NDSR_WRDREQ (0x1 << 2)
  66. #define NDSR_RDDREQ (0x1 << 1)
  67. #define NDSR_WRCMDREQ (0x1)
  68. #define NDCB0_AUTO_RS (0x1 << 25)
  69. #define NDCB0_CSEL (0x1 << 24)
  70. #define NDCB0_CMD_TYPE_MASK (0x7 << 21)
  71. #define NDCB0_CMD_TYPE(x) (((x) << 21) & NDCB0_CMD_TYPE_MASK)
  72. #define NDCB0_NC (0x1 << 20)
  73. #define NDCB0_DBC (0x1 << 19)
  74. #define NDCB0_ADDR_CYC_MASK (0x7 << 16)
  75. #define NDCB0_ADDR_CYC(x) (((x) << 16) & NDCB0_ADDR_CYC_MASK)
  76. #define NDCB0_CMD2_MASK (0xff << 8)
  77. #define NDCB0_CMD1_MASK (0xff)
  78. #define NDCB0_ADDR_CYC_SHIFT (16)
  79. /* dma-able I/O address for the NAND data and commands */
  80. #define NDCB0_DMA_ADDR (0x43100048)
  81. #define NDDB_DMA_ADDR (0x43100040)
  82. /* macros for registers read/write */
  83. #define nand_writel(info, off, val) \
  84. __raw_writel((val), (info)->mmio_base + (off))
  85. #define nand_readl(info, off) \
  86. __raw_readl((info)->mmio_base + (off))
  87. /* error code and state */
  88. enum {
  89. ERR_NONE = 0,
  90. ERR_DMABUSERR = -1,
  91. ERR_SENDCMD = -2,
  92. ERR_DBERR = -3,
  93. ERR_BBERR = -4,
  94. };
  95. enum {
  96. STATE_READY = 0,
  97. STATE_CMD_HANDLE,
  98. STATE_DMA_READING,
  99. STATE_DMA_WRITING,
  100. STATE_DMA_DONE,
  101. STATE_PIO_READING,
  102. STATE_PIO_WRITING,
  103. };
  104. struct pxa3xx_nand_info {
  105. struct nand_chip nand_chip;
  106. struct platform_device *pdev;
  107. struct pxa3xx_nand_flash *flash_info;
  108. struct clk *clk;
  109. void __iomem *mmio_base;
  110. unsigned int buf_start;
  111. unsigned int buf_count;
  112. /* DMA information */
  113. int drcmr_dat;
  114. int drcmr_cmd;
  115. unsigned char *data_buff;
  116. dma_addr_t data_buff_phys;
  117. size_t data_buff_size;
  118. int data_dma_ch;
  119. struct pxa_dma_desc *data_desc;
  120. dma_addr_t data_desc_addr;
  121. uint32_t reg_ndcr;
  122. /* saved column/page_addr during CMD_SEQIN */
  123. int seqin_column;
  124. int seqin_page_addr;
  125. /* relate to the command */
  126. unsigned int state;
  127. int use_ecc; /* use HW ECC ? */
  128. int use_dma; /* use DMA ? */
  129. size_t data_size; /* data size in FIFO */
  130. int retcode;
  131. struct completion cmd_complete;
  132. /* generated NDCBx register values */
  133. uint32_t ndcb0;
  134. uint32_t ndcb1;
  135. uint32_t ndcb2;
  136. };
  137. static int use_dma = 1;
  138. module_param(use_dma, bool, 0444);
  139. MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
  140. #ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
  141. static struct pxa3xx_nand_cmdset smallpage_cmdset = {
  142. .read1 = 0x0000,
  143. .read2 = 0x0050,
  144. .program = 0x1080,
  145. .read_status = 0x0070,
  146. .read_id = 0x0090,
  147. .erase = 0xD060,
  148. .reset = 0x00FF,
  149. .lock = 0x002A,
  150. .unlock = 0x2423,
  151. .lock_status = 0x007A,
  152. };
  153. static struct pxa3xx_nand_cmdset largepage_cmdset = {
  154. .read1 = 0x3000,
  155. .read2 = 0x0050,
  156. .program = 0x1080,
  157. .read_status = 0x0070,
  158. .read_id = 0x0090,
  159. .erase = 0xD060,
  160. .reset = 0x00FF,
  161. .lock = 0x002A,
  162. .unlock = 0x2423,
  163. .lock_status = 0x007A,
  164. };
  165. static struct pxa3xx_nand_timing samsung512MbX16_timing = {
  166. .tCH = 10,
  167. .tCS = 0,
  168. .tWH = 20,
  169. .tWP = 40,
  170. .tRH = 30,
  171. .tRP = 40,
  172. .tR = 11123,
  173. .tWHR = 110,
  174. .tAR = 10,
  175. };
  176. static struct pxa3xx_nand_flash samsung512MbX16 = {
  177. .timing = &samsung512MbX16_timing,
  178. .cmdset = &smallpage_cmdset,
  179. .page_per_block = 32,
  180. .page_size = 512,
  181. .flash_width = 16,
  182. .dfc_width = 16,
  183. .num_blocks = 4096,
  184. .chip_id = 0x46ec,
  185. };
  186. static struct pxa3xx_nand_timing micron_timing = {
  187. .tCH = 10,
  188. .tCS = 25,
  189. .tWH = 15,
  190. .tWP = 25,
  191. .tRH = 15,
  192. .tRP = 25,
  193. .tR = 25000,
  194. .tWHR = 60,
  195. .tAR = 10,
  196. };
  197. static struct pxa3xx_nand_flash micron1GbX8 = {
  198. .timing = &micron_timing,
  199. .cmdset = &largepage_cmdset,
  200. .page_per_block = 64,
  201. .page_size = 2048,
  202. .flash_width = 8,
  203. .dfc_width = 8,
  204. .num_blocks = 1024,
  205. .chip_id = 0xa12c,
  206. };
  207. static struct pxa3xx_nand_flash micron1GbX16 = {
  208. .timing = &micron_timing,
  209. .cmdset = &largepage_cmdset,
  210. .page_per_block = 64,
  211. .page_size = 2048,
  212. .flash_width = 16,
  213. .dfc_width = 16,
  214. .num_blocks = 1024,
  215. .chip_id = 0xb12c,
  216. };
  217. static struct pxa3xx_nand_timing stm2GbX16_timing = {
  218. .tCH = 10,
  219. .tCS = 35,
  220. .tWH = 15,
  221. .tWP = 25,
  222. .tRH = 15,
  223. .tRP = 25,
  224. .tR = 25000,
  225. .tWHR = 60,
  226. .tAR = 10,
  227. };
  228. static struct pxa3xx_nand_flash stm2GbX16 = {
  229. .timing = &stm2GbX16_timing,
  230. .page_per_block = 64,
  231. .page_size = 2048,
  232. .flash_width = 16,
  233. .dfc_width = 16,
  234. .num_blocks = 2048,
  235. .chip_id = 0xba20,
  236. };
  237. static struct pxa3xx_nand_flash *builtin_flash_types[] = {
  238. &samsung512MbX16,
  239. &micron1GbX8,
  240. &micron1GbX16,
  241. &stm2GbX16,
  242. };
  243. #endif /* CONFIG_MTD_NAND_PXA3xx_BUILTIN */
  244. #define NDTR0_tCH(c) (min((c), 7) << 19)
  245. #define NDTR0_tCS(c) (min((c), 7) << 16)
  246. #define NDTR0_tWH(c) (min((c), 7) << 11)
  247. #define NDTR0_tWP(c) (min((c), 7) << 8)
  248. #define NDTR0_tRH(c) (min((c), 7) << 3)
  249. #define NDTR0_tRP(c) (min((c), 7) << 0)
  250. #define NDTR1_tR(c) (min((c), 65535) << 16)
  251. #define NDTR1_tWHR(c) (min((c), 15) << 4)
  252. #define NDTR1_tAR(c) (min((c), 15) << 0)
  253. /* convert nano-seconds to nand flash controller clock cycles */
  254. #define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) + 1)
  255. static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
  256. struct pxa3xx_nand_timing *t)
  257. {
  258. unsigned long nand_clk = clk_get_rate(info->clk);
  259. uint32_t ndtr0, ndtr1;
  260. ndtr0 = NDTR0_tCH(ns2cycle(t->tCH, nand_clk)) |
  261. NDTR0_tCS(ns2cycle(t->tCS, nand_clk)) |
  262. NDTR0_tWH(ns2cycle(t->tWH, nand_clk)) |
  263. NDTR0_tWP(ns2cycle(t->tWP, nand_clk)) |
  264. NDTR0_tRH(ns2cycle(t->tRH, nand_clk)) |
  265. NDTR0_tRP(ns2cycle(t->tRP, nand_clk));
  266. ndtr1 = NDTR1_tR(ns2cycle(t->tR, nand_clk)) |
  267. NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) |
  268. NDTR1_tAR(ns2cycle(t->tAR, nand_clk));
  269. nand_writel(info, NDTR0CS0, ndtr0);
  270. nand_writel(info, NDTR1CS0, ndtr1);
  271. }
  272. #define WAIT_EVENT_TIMEOUT 10
  273. static int wait_for_event(struct pxa3xx_nand_info *info, uint32_t event)
  274. {
  275. int timeout = WAIT_EVENT_TIMEOUT;
  276. uint32_t ndsr;
  277. while (timeout--) {
  278. ndsr = nand_readl(info, NDSR) & NDSR_MASK;
  279. if (ndsr & event) {
  280. nand_writel(info, NDSR, ndsr);
  281. return 0;
  282. }
  283. udelay(10);
  284. }
  285. return -ETIMEDOUT;
  286. }
  287. static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info,
  288. uint16_t cmd, int column, int page_addr)
  289. {
  290. struct pxa3xx_nand_flash *f = info->flash_info;
  291. struct pxa3xx_nand_cmdset *cmdset = f->cmdset;
  292. /* calculate data size */
  293. switch (f->page_size) {
  294. case 2048:
  295. info->data_size = (info->use_ecc) ? 2088 : 2112;
  296. break;
  297. case 512:
  298. info->data_size = (info->use_ecc) ? 520 : 528;
  299. break;
  300. default:
  301. return -EINVAL;
  302. }
  303. /* generate values for NDCBx registers */
  304. info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
  305. info->ndcb1 = 0;
  306. info->ndcb2 = 0;
  307. info->ndcb0 |= NDCB0_ADDR_CYC(f->row_addr_cycles + f->col_addr_cycles);
  308. if (f->col_addr_cycles == 2) {
  309. /* large block, 2 cycles for column address
  310. * row address starts from 3rd cycle
  311. */
  312. info->ndcb1 |= (page_addr << 16) | (column & 0xffff);
  313. if (f->row_addr_cycles == 3)
  314. info->ndcb2 = (page_addr >> 16) & 0xff;
  315. } else
  316. /* small block, 1 cycles for column address
  317. * row address starts from 2nd cycle
  318. */
  319. info->ndcb1 = (page_addr << 8) | (column & 0xff);
  320. if (cmd == cmdset->program)
  321. info->ndcb0 |= NDCB0_CMD_TYPE(1) | NDCB0_AUTO_RS;
  322. return 0;
  323. }
  324. static int prepare_erase_cmd(struct pxa3xx_nand_info *info,
  325. uint16_t cmd, int page_addr)
  326. {
  327. info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
  328. info->ndcb0 |= NDCB0_CMD_TYPE(2) | NDCB0_AUTO_RS | NDCB0_ADDR_CYC(3);
  329. info->ndcb1 = page_addr;
  330. info->ndcb2 = 0;
  331. return 0;
  332. }
  333. static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd)
  334. {
  335. struct pxa3xx_nand_cmdset *cmdset = info->flash_info->cmdset;
  336. info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
  337. info->ndcb1 = 0;
  338. info->ndcb2 = 0;
  339. if (cmd == cmdset->read_id) {
  340. info->ndcb0 |= NDCB0_CMD_TYPE(3);
  341. info->data_size = 8;
  342. } else if (cmd == cmdset->read_status) {
  343. info->ndcb0 |= NDCB0_CMD_TYPE(4);
  344. info->data_size = 8;
  345. } else if (cmd == cmdset->reset || cmd == cmdset->lock ||
  346. cmd == cmdset->unlock) {
  347. info->ndcb0 |= NDCB0_CMD_TYPE(5);
  348. } else
  349. return -EINVAL;
  350. return 0;
  351. }
  352. static void enable_int(struct pxa3xx_nand_info *info, uint32_t int_mask)
  353. {
  354. uint32_t ndcr;
  355. ndcr = nand_readl(info, NDCR);
  356. nand_writel(info, NDCR, ndcr & ~int_mask);
  357. }
  358. static void disable_int(struct pxa3xx_nand_info *info, uint32_t int_mask)
  359. {
  360. uint32_t ndcr;
  361. ndcr = nand_readl(info, NDCR);
  362. nand_writel(info, NDCR, ndcr | int_mask);
  363. }
  364. /* NOTE: it is a must to set ND_RUN firstly, then write command buffer
  365. * otherwise, it does not work
  366. */
  367. static int write_cmd(struct pxa3xx_nand_info *info)
  368. {
  369. uint32_t ndcr;
  370. /* clear status bits and run */
  371. nand_writel(info, NDSR, NDSR_MASK);
  372. ndcr = info->reg_ndcr;
  373. ndcr |= info->use_ecc ? NDCR_ECC_EN : 0;
  374. ndcr |= info->use_dma ? NDCR_DMA_EN : 0;
  375. ndcr |= NDCR_ND_RUN;
  376. nand_writel(info, NDCR, ndcr);
  377. if (wait_for_event(info, NDSR_WRCMDREQ)) {
  378. printk(KERN_ERR "timed out writing command\n");
  379. return -ETIMEDOUT;
  380. }
  381. nand_writel(info, NDCB0, info->ndcb0);
  382. nand_writel(info, NDCB0, info->ndcb1);
  383. nand_writel(info, NDCB0, info->ndcb2);
  384. return 0;
  385. }
  386. static int handle_data_pio(struct pxa3xx_nand_info *info)
  387. {
  388. int ret, timeout = CHIP_DELAY_TIMEOUT;
  389. switch (info->state) {
  390. case STATE_PIO_WRITING:
  391. __raw_writesl(info->mmio_base + NDDB, info->data_buff,
  392. info->data_size << 2);
  393. enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
  394. ret = wait_for_completion_timeout(&info->cmd_complete, timeout);
  395. if (!ret) {
  396. printk(KERN_ERR "program command time out\n");
  397. return -1;
  398. }
  399. break;
  400. case STATE_PIO_READING:
  401. __raw_readsl(info->mmio_base + NDDB, info->data_buff,
  402. info->data_size << 2);
  403. break;
  404. default:
  405. printk(KERN_ERR "%s: invalid state %d\n", __func__,
  406. info->state);
  407. return -EINVAL;
  408. }
  409. info->state = STATE_READY;
  410. return 0;
  411. }
  412. static void start_data_dma(struct pxa3xx_nand_info *info, int dir_out)
  413. {
  414. struct pxa_dma_desc *desc = info->data_desc;
  415. int dma_len = ALIGN(info->data_size, 32);
  416. desc->ddadr = DDADR_STOP;
  417. desc->dcmd = DCMD_ENDIRQEN | DCMD_WIDTH4 | DCMD_BURST32 | dma_len;
  418. if (dir_out) {
  419. desc->dsadr = info->data_buff_phys;
  420. desc->dtadr = NDDB_DMA_ADDR;
  421. desc->dcmd |= DCMD_INCSRCADDR | DCMD_FLOWTRG;
  422. } else {
  423. desc->dtadr = info->data_buff_phys;
  424. desc->dsadr = NDDB_DMA_ADDR;
  425. desc->dcmd |= DCMD_INCTRGADDR | DCMD_FLOWSRC;
  426. }
  427. DRCMR(info->drcmr_dat) = DRCMR_MAPVLD | info->data_dma_ch;
  428. DDADR(info->data_dma_ch) = info->data_desc_addr;
  429. DCSR(info->data_dma_ch) |= DCSR_RUN;
  430. }
  431. static void pxa3xx_nand_data_dma_irq(int channel, void *data)
  432. {
  433. struct pxa3xx_nand_info *info = data;
  434. uint32_t dcsr;
  435. dcsr = DCSR(channel);
  436. DCSR(channel) = dcsr;
  437. if (dcsr & DCSR_BUSERR) {
  438. info->retcode = ERR_DMABUSERR;
  439. complete(&info->cmd_complete);
  440. }
  441. if (info->state == STATE_DMA_WRITING) {
  442. info->state = STATE_DMA_DONE;
  443. enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
  444. } else {
  445. info->state = STATE_READY;
  446. complete(&info->cmd_complete);
  447. }
  448. }
  449. static irqreturn_t pxa3xx_nand_irq(int irq, void *devid)
  450. {
  451. struct pxa3xx_nand_info *info = devid;
  452. unsigned int status;
  453. status = nand_readl(info, NDSR);
  454. if (status & (NDSR_RDDREQ | NDSR_DBERR)) {
  455. if (status & NDSR_DBERR)
  456. info->retcode = ERR_DBERR;
  457. disable_int(info, NDSR_RDDREQ | NDSR_DBERR);
  458. if (info->use_dma) {
  459. info->state = STATE_DMA_READING;
  460. start_data_dma(info, 0);
  461. } else {
  462. info->state = STATE_PIO_READING;
  463. complete(&info->cmd_complete);
  464. }
  465. } else if (status & NDSR_WRDREQ) {
  466. disable_int(info, NDSR_WRDREQ);
  467. if (info->use_dma) {
  468. info->state = STATE_DMA_WRITING;
  469. start_data_dma(info, 1);
  470. } else {
  471. info->state = STATE_PIO_WRITING;
  472. complete(&info->cmd_complete);
  473. }
  474. } else if (status & (NDSR_CS0_BBD | NDSR_CS0_CMDD)) {
  475. if (status & NDSR_CS0_BBD)
  476. info->retcode = ERR_BBERR;
  477. disable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
  478. info->state = STATE_READY;
  479. complete(&info->cmd_complete);
  480. }
  481. nand_writel(info, NDSR, status);
  482. return IRQ_HANDLED;
  483. }
  484. static int pxa3xx_nand_do_cmd(struct pxa3xx_nand_info *info, uint32_t event)
  485. {
  486. uint32_t ndcr;
  487. int ret, timeout = CHIP_DELAY_TIMEOUT;
  488. if (write_cmd(info)) {
  489. info->retcode = ERR_SENDCMD;
  490. goto fail_stop;
  491. }
  492. info->state = STATE_CMD_HANDLE;
  493. enable_int(info, event);
  494. ret = wait_for_completion_timeout(&info->cmd_complete, timeout);
  495. if (!ret) {
  496. printk(KERN_ERR "command execution timed out\n");
  497. info->retcode = ERR_SENDCMD;
  498. goto fail_stop;
  499. }
  500. if (info->use_dma == 0 && info->data_size > 0)
  501. if (handle_data_pio(info))
  502. goto fail_stop;
  503. return 0;
  504. fail_stop:
  505. ndcr = nand_readl(info, NDCR);
  506. nand_writel(info, NDCR, ndcr & ~NDCR_ND_RUN);
  507. udelay(10);
  508. return -ETIMEDOUT;
  509. }
  510. static int pxa3xx_nand_dev_ready(struct mtd_info *mtd)
  511. {
  512. struct pxa3xx_nand_info *info = mtd->priv;
  513. return (nand_readl(info, NDSR) & NDSR_RDY) ? 1 : 0;
  514. }
  515. static inline int is_buf_blank(uint8_t *buf, size_t len)
  516. {
  517. for (; len > 0; len--)
  518. if (*buf++ != 0xff)
  519. return 0;
  520. return 1;
  521. }
  522. static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
  523. int column, int page_addr)
  524. {
  525. struct pxa3xx_nand_info *info = mtd->priv;
  526. struct pxa3xx_nand_flash *flash_info = info->flash_info;
  527. struct pxa3xx_nand_cmdset *cmdset = flash_info->cmdset;
  528. int ret;
  529. info->use_dma = (use_dma) ? 1 : 0;
  530. info->use_ecc = 0;
  531. info->data_size = 0;
  532. info->state = STATE_READY;
  533. init_completion(&info->cmd_complete);
  534. switch (command) {
  535. case NAND_CMD_READOOB:
  536. /* disable HW ECC to get all the OOB data */
  537. info->buf_count = mtd->writesize + mtd->oobsize;
  538. info->buf_start = mtd->writesize + column;
  539. if (prepare_read_prog_cmd(info, cmdset->read1, column, page_addr))
  540. break;
  541. pxa3xx_nand_do_cmd(info, NDSR_RDDREQ | NDSR_DBERR);
  542. /* We only are OOB, so if the data has error, does not matter */
  543. if (info->retcode == ERR_DBERR)
  544. info->retcode = ERR_NONE;
  545. break;
  546. case NAND_CMD_READ0:
  547. info->use_ecc = 1;
  548. info->retcode = ERR_NONE;
  549. info->buf_start = column;
  550. info->buf_count = mtd->writesize + mtd->oobsize;
  551. memset(info->data_buff, 0xFF, info->buf_count);
  552. if (prepare_read_prog_cmd(info, cmdset->read1, column, page_addr))
  553. break;
  554. pxa3xx_nand_do_cmd(info, NDSR_RDDREQ | NDSR_DBERR);
  555. if (info->retcode == ERR_DBERR) {
  556. /* for blank page (all 0xff), HW will calculate its ECC as
  557. * 0, which is different from the ECC information within
  558. * OOB, ignore such double bit errors
  559. */
  560. if (is_buf_blank(info->data_buff, mtd->writesize))
  561. info->retcode = ERR_NONE;
  562. }
  563. break;
  564. case NAND_CMD_SEQIN:
  565. info->buf_start = column;
  566. info->buf_count = mtd->writesize + mtd->oobsize;
  567. memset(info->data_buff, 0xff, info->buf_count);
  568. /* save column/page_addr for next CMD_PAGEPROG */
  569. info->seqin_column = column;
  570. info->seqin_page_addr = page_addr;
  571. break;
  572. case NAND_CMD_PAGEPROG:
  573. info->use_ecc = (info->seqin_column >= mtd->writesize) ? 0 : 1;
  574. if (prepare_read_prog_cmd(info, cmdset->program,
  575. info->seqin_column, info->seqin_page_addr))
  576. break;
  577. pxa3xx_nand_do_cmd(info, NDSR_WRDREQ);
  578. break;
  579. case NAND_CMD_ERASE1:
  580. if (prepare_erase_cmd(info, cmdset->erase, page_addr))
  581. break;
  582. pxa3xx_nand_do_cmd(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
  583. break;
  584. case NAND_CMD_ERASE2:
  585. break;
  586. case NAND_CMD_READID:
  587. case NAND_CMD_STATUS:
  588. info->use_dma = 0; /* force PIO read */
  589. info->buf_start = 0;
  590. info->buf_count = (command == NAND_CMD_READID) ?
  591. flash_info->read_id_bytes : 1;
  592. if (prepare_other_cmd(info, (command == NAND_CMD_READID) ?
  593. cmdset->read_id : cmdset->read_status))
  594. break;
  595. pxa3xx_nand_do_cmd(info, NDSR_RDDREQ);
  596. break;
  597. case NAND_CMD_RESET:
  598. if (prepare_other_cmd(info, cmdset->reset))
  599. break;
  600. ret = pxa3xx_nand_do_cmd(info, NDSR_CS0_CMDD);
  601. if (ret == 0) {
  602. int timeout = 2;
  603. uint32_t ndcr;
  604. while (timeout--) {
  605. if (nand_readl(info, NDSR) & NDSR_RDY)
  606. break;
  607. msleep(10);
  608. }
  609. ndcr = nand_readl(info, NDCR);
  610. nand_writel(info, NDCR, ndcr & ~NDCR_ND_RUN);
  611. }
  612. break;
  613. default:
  614. printk(KERN_ERR "non-supported command.\n");
  615. break;
  616. }
  617. if (info->retcode == ERR_DBERR) {
  618. printk(KERN_ERR "double bit error @ page %08x\n", page_addr);
  619. info->retcode = ERR_NONE;
  620. }
  621. }
  622. static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd)
  623. {
  624. struct pxa3xx_nand_info *info = mtd->priv;
  625. char retval = 0xFF;
  626. if (info->buf_start < info->buf_count)
  627. /* Has just send a new command? */
  628. retval = info->data_buff[info->buf_start++];
  629. return retval;
  630. }
  631. static u16 pxa3xx_nand_read_word(struct mtd_info *mtd)
  632. {
  633. struct pxa3xx_nand_info *info = mtd->priv;
  634. u16 retval = 0xFFFF;
  635. if (!(info->buf_start & 0x01) && info->buf_start < info->buf_count) {
  636. retval = *((u16 *)(info->data_buff+info->buf_start));
  637. info->buf_start += 2;
  638. }
  639. return retval;
  640. }
  641. static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  642. {
  643. struct pxa3xx_nand_info *info = mtd->priv;
  644. int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
  645. memcpy(buf, info->data_buff + info->buf_start, real_len);
  646. info->buf_start += real_len;
  647. }
  648. static void pxa3xx_nand_write_buf(struct mtd_info *mtd,
  649. const uint8_t *buf, int len)
  650. {
  651. struct pxa3xx_nand_info *info = mtd->priv;
  652. int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
  653. memcpy(info->data_buff + info->buf_start, buf, real_len);
  654. info->buf_start += real_len;
  655. }
  656. static int pxa3xx_nand_verify_buf(struct mtd_info *mtd,
  657. const uint8_t *buf, int len)
  658. {
  659. return 0;
  660. }
  661. static void pxa3xx_nand_select_chip(struct mtd_info *mtd, int chip)
  662. {
  663. return;
  664. }
  665. static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this)
  666. {
  667. struct pxa3xx_nand_info *info = mtd->priv;
  668. /* pxa3xx_nand_send_command has waited for command complete */
  669. if (this->state == FL_WRITING || this->state == FL_ERASING) {
  670. if (info->retcode == ERR_NONE)
  671. return 0;
  672. else {
  673. /*
  674. * any error make it return 0x01 which will tell
  675. * the caller the erase and write fail
  676. */
  677. return 0x01;
  678. }
  679. }
  680. return 0;
  681. }
  682. static void pxa3xx_nand_ecc_hwctl(struct mtd_info *mtd, int mode)
  683. {
  684. return;
  685. }
  686. static int pxa3xx_nand_ecc_calculate(struct mtd_info *mtd,
  687. const uint8_t *dat, uint8_t *ecc_code)
  688. {
  689. return 0;
  690. }
  691. static int pxa3xx_nand_ecc_correct(struct mtd_info *mtd,
  692. uint8_t *dat, uint8_t *read_ecc, uint8_t *calc_ecc)
  693. {
  694. struct pxa3xx_nand_info *info = mtd->priv;
  695. /*
  696. * Any error include ERR_SEND_CMD, ERR_DBERR, ERR_BUSERR, we
  697. * consider it as a ecc error which will tell the caller the
  698. * read fail We have distinguish all the errors, but the
  699. * nand_read_ecc only check this function return value
  700. */
  701. if (info->retcode != ERR_NONE)
  702. return -1;
  703. return 0;
  704. }
  705. static int __readid(struct pxa3xx_nand_info *info, uint32_t *id)
  706. {
  707. struct pxa3xx_nand_flash *f = info->flash_info;
  708. struct pxa3xx_nand_cmdset *cmdset = f->cmdset;
  709. uint32_t ndcr;
  710. uint8_t id_buff[8];
  711. if (prepare_other_cmd(info, cmdset->read_id)) {
  712. printk(KERN_ERR "failed to prepare command\n");
  713. return -EINVAL;
  714. }
  715. /* Send command */
  716. if (write_cmd(info))
  717. goto fail_timeout;
  718. /* Wait for CMDDM(command done successfully) */
  719. if (wait_for_event(info, NDSR_RDDREQ))
  720. goto fail_timeout;
  721. __raw_readsl(info->mmio_base + NDDB, id_buff, 2);
  722. *id = id_buff[0] | (id_buff[1] << 8);
  723. return 0;
  724. fail_timeout:
  725. ndcr = nand_readl(info, NDCR);
  726. nand_writel(info, NDCR, ndcr & ~NDCR_ND_RUN);
  727. udelay(10);
  728. return -ETIMEDOUT;
  729. }
  730. static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
  731. struct pxa3xx_nand_flash *f)
  732. {
  733. struct platform_device *pdev = info->pdev;
  734. struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data;
  735. uint32_t ndcr = 0x00000FFF; /* disable all interrupts */
  736. if (f->page_size != 2048 && f->page_size != 512)
  737. return -EINVAL;
  738. if (f->flash_width != 16 && f->flash_width != 8)
  739. return -EINVAL;
  740. /* calculate flash information */
  741. f->oob_size = (f->page_size == 2048) ? 64 : 16;
  742. f->read_id_bytes = (f->page_size == 2048) ? 4 : 2;
  743. /* calculate addressing information */
  744. f->col_addr_cycles = (f->page_size == 2048) ? 2 : 1;
  745. if (f->num_blocks * f->page_per_block > 65536)
  746. f->row_addr_cycles = 3;
  747. else
  748. f->row_addr_cycles = 2;
  749. ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
  750. ndcr |= (f->col_addr_cycles == 2) ? NDCR_RA_START : 0;
  751. ndcr |= (f->page_per_block == 64) ? NDCR_PG_PER_BLK : 0;
  752. ndcr |= (f->page_size == 2048) ? NDCR_PAGE_SZ : 0;
  753. ndcr |= (f->flash_width == 16) ? NDCR_DWIDTH_M : 0;
  754. ndcr |= (f->dfc_width == 16) ? NDCR_DWIDTH_C : 0;
  755. ndcr |= NDCR_RD_ID_CNT(f->read_id_bytes);
  756. ndcr |= NDCR_SPARE_EN; /* enable spare by default */
  757. info->reg_ndcr = ndcr;
  758. pxa3xx_nand_set_timing(info, f->timing);
  759. info->flash_info = f;
  760. return 0;
  761. }
  762. static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
  763. const struct pxa3xx_nand_platform_data *pdata)
  764. {
  765. struct pxa3xx_nand_flash *f;
  766. uint32_t id;
  767. int i;
  768. for (i = 0; i<pdata->num_flash; ++i) {
  769. f = pdata->flash + i;
  770. if (pxa3xx_nand_config_flash(info, f))
  771. continue;
  772. if (__readid(info, &id))
  773. continue;
  774. if (id == f->chip_id)
  775. return 0;
  776. }
  777. #ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
  778. for (i = 0; i < ARRAY_SIZE(builtin_flash_types); i++) {
  779. f = builtin_flash_types[i];
  780. if (pxa3xx_nand_config_flash(info, f))
  781. continue;
  782. if (__readid(info, &id))
  783. continue;
  784. if (id == f->chip_id)
  785. return 0;
  786. }
  787. #endif
  788. return -ENODEV;
  789. }
  790. /* the maximum possible buffer size for large page with OOB data
  791. * is: 2048 + 64 = 2112 bytes, allocate a page here for both the
  792. * data buffer and the DMA descriptor
  793. */
  794. #define MAX_BUFF_SIZE PAGE_SIZE
  795. static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info)
  796. {
  797. struct platform_device *pdev = info->pdev;
  798. int data_desc_offset = MAX_BUFF_SIZE - sizeof(struct pxa_dma_desc);
  799. if (use_dma == 0) {
  800. info->data_buff = kmalloc(MAX_BUFF_SIZE, GFP_KERNEL);
  801. if (info->data_buff == NULL)
  802. return -ENOMEM;
  803. return 0;
  804. }
  805. info->data_buff = dma_alloc_coherent(&pdev->dev, MAX_BUFF_SIZE,
  806. &info->data_buff_phys, GFP_KERNEL);
  807. if (info->data_buff == NULL) {
  808. dev_err(&pdev->dev, "failed to allocate dma buffer\n");
  809. return -ENOMEM;
  810. }
  811. info->data_buff_size = MAX_BUFF_SIZE;
  812. info->data_desc = (void *)info->data_buff + data_desc_offset;
  813. info->data_desc_addr = info->data_buff_phys + data_desc_offset;
  814. info->data_dma_ch = pxa_request_dma("nand-data", DMA_PRIO_LOW,
  815. pxa3xx_nand_data_dma_irq, info);
  816. if (info->data_dma_ch < 0) {
  817. dev_err(&pdev->dev, "failed to request data dma\n");
  818. dma_free_coherent(&pdev->dev, info->data_buff_size,
  819. info->data_buff, info->data_buff_phys);
  820. return info->data_dma_ch;
  821. }
  822. return 0;
  823. }
  824. static struct nand_ecclayout hw_smallpage_ecclayout = {
  825. .eccbytes = 6,
  826. .eccpos = {8, 9, 10, 11, 12, 13 },
  827. .oobfree = { {2, 6} }
  828. };
  829. static struct nand_ecclayout hw_largepage_ecclayout = {
  830. .eccbytes = 24,
  831. .eccpos = {
  832. 40, 41, 42, 43, 44, 45, 46, 47,
  833. 48, 49, 50, 51, 52, 53, 54, 55,
  834. 56, 57, 58, 59, 60, 61, 62, 63},
  835. .oobfree = { {2, 38} }
  836. };
  837. static void pxa3xx_nand_init_mtd(struct mtd_info *mtd,
  838. struct pxa3xx_nand_info *info)
  839. {
  840. struct pxa3xx_nand_flash *f = info->flash_info;
  841. struct nand_chip *this = &info->nand_chip;
  842. this->options = (f->flash_width == 16) ? NAND_BUSWIDTH_16: 0;
  843. this->waitfunc = pxa3xx_nand_waitfunc;
  844. this->select_chip = pxa3xx_nand_select_chip;
  845. this->dev_ready = pxa3xx_nand_dev_ready;
  846. this->cmdfunc = pxa3xx_nand_cmdfunc;
  847. this->read_word = pxa3xx_nand_read_word;
  848. this->read_byte = pxa3xx_nand_read_byte;
  849. this->read_buf = pxa3xx_nand_read_buf;
  850. this->write_buf = pxa3xx_nand_write_buf;
  851. this->verify_buf = pxa3xx_nand_verify_buf;
  852. this->ecc.mode = NAND_ECC_HW;
  853. this->ecc.hwctl = pxa3xx_nand_ecc_hwctl;
  854. this->ecc.calculate = pxa3xx_nand_ecc_calculate;
  855. this->ecc.correct = pxa3xx_nand_ecc_correct;
  856. this->ecc.size = f->page_size;
  857. if (f->page_size == 2048)
  858. this->ecc.layout = &hw_largepage_ecclayout;
  859. else
  860. this->ecc.layout = &hw_smallpage_ecclayout;
  861. this->chip_delay = 25;
  862. }
  863. static int pxa3xx_nand_probe(struct platform_device *pdev)
  864. {
  865. struct pxa3xx_nand_platform_data *pdata;
  866. struct pxa3xx_nand_info *info;
  867. struct nand_chip *this;
  868. struct mtd_info *mtd;
  869. struct resource *r;
  870. int ret = 0, irq;
  871. pdata = pdev->dev.platform_data;
  872. if (!pdata) {
  873. dev_err(&pdev->dev, "no platform data defined\n");
  874. return -ENODEV;
  875. }
  876. mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct pxa3xx_nand_info),
  877. GFP_KERNEL);
  878. if (!mtd) {
  879. dev_err(&pdev->dev, "failed to allocate memory\n");
  880. return -ENOMEM;
  881. }
  882. info = (struct pxa3xx_nand_info *)(&mtd[1]);
  883. info->pdev = pdev;
  884. this = &info->nand_chip;
  885. mtd->priv = info;
  886. info->clk = clk_get(&pdev->dev, "NANDCLK");
  887. if (IS_ERR(info->clk)) {
  888. dev_err(&pdev->dev, "failed to get nand clock\n");
  889. ret = PTR_ERR(info->clk);
  890. goto fail_free_mtd;
  891. }
  892. clk_enable(info->clk);
  893. r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  894. if (r == NULL) {
  895. dev_err(&pdev->dev, "no resource defined for data DMA\n");
  896. ret = -ENXIO;
  897. goto fail_put_clk;
  898. }
  899. info->drcmr_dat = r->start;
  900. r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  901. if (r == NULL) {
  902. dev_err(&pdev->dev, "no resource defined for command DMA\n");
  903. ret = -ENXIO;
  904. goto fail_put_clk;
  905. }
  906. info->drcmr_cmd = r->start;
  907. irq = platform_get_irq(pdev, 0);
  908. if (irq < 0) {
  909. dev_err(&pdev->dev, "no IRQ resource defined\n");
  910. ret = -ENXIO;
  911. goto fail_put_clk;
  912. }
  913. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  914. if (r == NULL) {
  915. dev_err(&pdev->dev, "no IO memory resource defined\n");
  916. ret = -ENODEV;
  917. goto fail_put_clk;
  918. }
  919. r = request_mem_region(r->start, r->end - r->start + 1, pdev->name);
  920. if (r == NULL) {
  921. dev_err(&pdev->dev, "failed to request memory resource\n");
  922. ret = -EBUSY;
  923. goto fail_put_clk;
  924. }
  925. info->mmio_base = ioremap(r->start, r->end - r->start + 1);
  926. if (info->mmio_base == NULL) {
  927. dev_err(&pdev->dev, "ioremap() failed\n");
  928. ret = -ENODEV;
  929. goto fail_free_res;
  930. }
  931. ret = pxa3xx_nand_init_buff(info);
  932. if (ret)
  933. goto fail_free_io;
  934. ret = request_irq(IRQ_NAND, pxa3xx_nand_irq, IRQF_DISABLED,
  935. pdev->name, info);
  936. if (ret < 0) {
  937. dev_err(&pdev->dev, "failed to request IRQ\n");
  938. goto fail_free_buf;
  939. }
  940. ret = pxa3xx_nand_detect_flash(info, pdata);
  941. if (ret) {
  942. dev_err(&pdev->dev, "failed to detect flash\n");
  943. ret = -ENODEV;
  944. goto fail_free_irq;
  945. }
  946. pxa3xx_nand_init_mtd(mtd, info);
  947. platform_set_drvdata(pdev, mtd);
  948. if (nand_scan(mtd, 1)) {
  949. dev_err(&pdev->dev, "failed to scan nand\n");
  950. ret = -ENXIO;
  951. goto fail_free_irq;
  952. }
  953. return add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts);
  954. fail_free_irq:
  955. free_irq(IRQ_NAND, info);
  956. fail_free_buf:
  957. if (use_dma) {
  958. pxa_free_dma(info->data_dma_ch);
  959. dma_free_coherent(&pdev->dev, info->data_buff_size,
  960. info->data_buff, info->data_buff_phys);
  961. } else
  962. kfree(info->data_buff);
  963. fail_free_io:
  964. iounmap(info->mmio_base);
  965. fail_free_res:
  966. release_mem_region(r->start, r->end - r->start + 1);
  967. fail_put_clk:
  968. clk_disable(info->clk);
  969. clk_put(info->clk);
  970. fail_free_mtd:
  971. kfree(mtd);
  972. return ret;
  973. }
  974. static int pxa3xx_nand_remove(struct platform_device *pdev)
  975. {
  976. struct mtd_info *mtd = platform_get_drvdata(pdev);
  977. struct pxa3xx_nand_info *info = mtd->priv;
  978. platform_set_drvdata(pdev, NULL);
  979. del_mtd_device(mtd);
  980. del_mtd_partitions(mtd);
  981. free_irq(IRQ_NAND, info);
  982. if (use_dma) {
  983. pxa_free_dma(info->data_dma_ch);
  984. dma_free_writecombine(&pdev->dev, info->data_buff_size,
  985. info->data_buff, info->data_buff_phys);
  986. } else
  987. kfree(info->data_buff);
  988. kfree(mtd);
  989. return 0;
  990. }
  991. #ifdef CONFIG_PM
  992. static int pxa3xx_nand_suspend(struct platform_device *pdev, pm_message_t state)
  993. {
  994. struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev);
  995. struct pxa3xx_nand_info *info = mtd->priv;
  996. if (info->state != STATE_READY) {
  997. dev_err(&pdev->dev, "driver busy, state = %d\n", info->state);
  998. return -EAGAIN;
  999. }
  1000. return 0;
  1001. }
  1002. static int pxa3xx_nand_resume(struct platform_device *pdev)
  1003. {
  1004. struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev);
  1005. struct pxa3xx_nand_info *info = mtd->priv;
  1006. clk_enable(info->clk);
  1007. return pxa3xx_nand_config_flash(info, info->flash_info);
  1008. }
  1009. #else
  1010. #define pxa3xx_nand_suspend NULL
  1011. #define pxa3xx_nand_resume NULL
  1012. #endif
  1013. static struct platform_driver pxa3xx_nand_driver = {
  1014. .driver = {
  1015. .name = "pxa3xx-nand",
  1016. },
  1017. .probe = pxa3xx_nand_probe,
  1018. .remove = pxa3xx_nand_remove,
  1019. .suspend = pxa3xx_nand_suspend,
  1020. .resume = pxa3xx_nand_resume,
  1021. };
  1022. static int __init pxa3xx_nand_init(void)
  1023. {
  1024. return platform_driver_register(&pxa3xx_nand_driver);
  1025. }
  1026. module_init(pxa3xx_nand_init);
  1027. static void __exit pxa3xx_nand_exit(void)
  1028. {
  1029. platform_driver_unregister(&pxa3xx_nand_driver);
  1030. }
  1031. module_exit(pxa3xx_nand_exit);
  1032. MODULE_LICENSE("GPL");
  1033. MODULE_DESCRIPTION("PXA3xx NAND controller driver");