pxa3xx_nand.c 30 KB

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