pxa3xx_nand.c 30 KB

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