pxa3xx_nand.c 30 KB

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