fsmc_nand.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  1. /*
  2. * ST Microelectronics
  3. * Flexible Static Memory Controller (FSMC)
  4. * Driver for NAND portions
  5. *
  6. * Copyright © 2010 ST Microelectronics
  7. * Vipin Kumar <vipin.kumar@st.com>
  8. * Ashish Priyadarshi
  9. *
  10. * Based on drivers/mtd/nand/nomadik_nand.c (removed in v3.8)
  11. * Copyright © 2007 STMicroelectronics Pvt. Ltd.
  12. * Copyright © 2009 Alessandro Rubini
  13. *
  14. * This file is licensed under the terms of the GNU General Public
  15. * License version 2. This program is licensed "as is" without any
  16. * warranty of any kind, whether express or implied.
  17. */
  18. #include <linux/clk.h>
  19. #include <linux/completion.h>
  20. #include <linux/dmaengine.h>
  21. #include <linux/dma-direction.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/err.h>
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/resource.h>
  27. #include <linux/sched.h>
  28. #include <linux/types.h>
  29. #include <linux/mtd/mtd.h>
  30. #include <linux/mtd/rawnand.h>
  31. #include <linux/mtd/nand_ecc.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/of.h>
  34. #include <linux/mtd/partitions.h>
  35. #include <linux/io.h>
  36. #include <linux/slab.h>
  37. #include <linux/amba/bus.h>
  38. #include <mtd/mtd-abi.h>
  39. /* fsmc controller registers for NOR flash */
  40. #define CTRL 0x0
  41. /* ctrl register definitions */
  42. #define BANK_ENABLE (1 << 0)
  43. #define MUXED (1 << 1)
  44. #define NOR_DEV (2 << 2)
  45. #define WIDTH_8 (0 << 4)
  46. #define WIDTH_16 (1 << 4)
  47. #define RSTPWRDWN (1 << 6)
  48. #define WPROT (1 << 7)
  49. #define WRT_ENABLE (1 << 12)
  50. #define WAIT_ENB (1 << 13)
  51. #define CTRL_TIM 0x4
  52. /* ctrl_tim register definitions */
  53. #define FSMC_NOR_BANK_SZ 0x8
  54. #define FSMC_NOR_REG_SIZE 0x40
  55. #define FSMC_NOR_REG(base, bank, reg) (base + \
  56. FSMC_NOR_BANK_SZ * (bank) + \
  57. reg)
  58. /* fsmc controller registers for NAND flash */
  59. #define FSMC_PC 0x00
  60. /* pc register definitions */
  61. #define FSMC_RESET (1 << 0)
  62. #define FSMC_WAITON (1 << 1)
  63. #define FSMC_ENABLE (1 << 2)
  64. #define FSMC_DEVTYPE_NAND (1 << 3)
  65. #define FSMC_DEVWID_8 (0 << 4)
  66. #define FSMC_DEVWID_16 (1 << 4)
  67. #define FSMC_ECCEN (1 << 6)
  68. #define FSMC_ECCPLEN_512 (0 << 7)
  69. #define FSMC_ECCPLEN_256 (1 << 7)
  70. #define FSMC_TCLR_1 (1)
  71. #define FSMC_TCLR_SHIFT (9)
  72. #define FSMC_TCLR_MASK (0xF)
  73. #define FSMC_TAR_1 (1)
  74. #define FSMC_TAR_SHIFT (13)
  75. #define FSMC_TAR_MASK (0xF)
  76. #define STS 0x04
  77. /* sts register definitions */
  78. #define FSMC_CODE_RDY (1 << 15)
  79. #define COMM 0x08
  80. /* comm register definitions */
  81. #define FSMC_TSET_0 0
  82. #define FSMC_TSET_SHIFT 0
  83. #define FSMC_TSET_MASK 0xFF
  84. #define FSMC_TWAIT_6 6
  85. #define FSMC_TWAIT_SHIFT 8
  86. #define FSMC_TWAIT_MASK 0xFF
  87. #define FSMC_THOLD_4 4
  88. #define FSMC_THOLD_SHIFT 16
  89. #define FSMC_THOLD_MASK 0xFF
  90. #define FSMC_THIZ_1 1
  91. #define FSMC_THIZ_SHIFT 24
  92. #define FSMC_THIZ_MASK 0xFF
  93. #define ATTRIB 0x0C
  94. #define IOATA 0x10
  95. #define ECC1 0x14
  96. #define ECC2 0x18
  97. #define ECC3 0x1C
  98. #define FSMC_NAND_BANK_SZ 0x20
  99. #define FSMC_BUSY_WAIT_TIMEOUT (1 * HZ)
  100. struct fsmc_nand_timings {
  101. uint8_t tclr;
  102. uint8_t tar;
  103. uint8_t thiz;
  104. uint8_t thold;
  105. uint8_t twait;
  106. uint8_t tset;
  107. };
  108. enum access_mode {
  109. USE_DMA_ACCESS = 1,
  110. USE_WORD_ACCESS,
  111. };
  112. /**
  113. * struct fsmc_nand_data - structure for FSMC NAND device state
  114. *
  115. * @pid: Part ID on the AMBA PrimeCell format
  116. * @mtd: MTD info for a NAND flash.
  117. * @nand: Chip related info for a NAND flash.
  118. * @partitions: Partition info for a NAND Flash.
  119. * @nr_partitions: Total number of partition of a NAND flash.
  120. *
  121. * @bank: Bank number for probed device.
  122. * @clk: Clock structure for FSMC.
  123. *
  124. * @read_dma_chan: DMA channel for read access
  125. * @write_dma_chan: DMA channel for write access to NAND
  126. * @dma_access_complete: Completion structure
  127. *
  128. * @data_pa: NAND Physical port for Data.
  129. * @data_va: NAND port for Data.
  130. * @cmd_va: NAND port for Command.
  131. * @addr_va: NAND port for Address.
  132. * @regs_va: Registers base address for a given bank.
  133. */
  134. struct fsmc_nand_data {
  135. u32 pid;
  136. struct nand_chip nand;
  137. unsigned int bank;
  138. struct device *dev;
  139. enum access_mode mode;
  140. struct clk *clk;
  141. /* DMA related objects */
  142. struct dma_chan *read_dma_chan;
  143. struct dma_chan *write_dma_chan;
  144. struct completion dma_access_complete;
  145. struct fsmc_nand_timings *dev_timings;
  146. dma_addr_t data_pa;
  147. void __iomem *data_va;
  148. void __iomem *cmd_va;
  149. void __iomem *addr_va;
  150. void __iomem *regs_va;
  151. };
  152. static int fsmc_ecc1_ooblayout_ecc(struct mtd_info *mtd, int section,
  153. struct mtd_oob_region *oobregion)
  154. {
  155. struct nand_chip *chip = mtd_to_nand(mtd);
  156. if (section >= chip->ecc.steps)
  157. return -ERANGE;
  158. oobregion->offset = (section * 16) + 2;
  159. oobregion->length = 3;
  160. return 0;
  161. }
  162. static int fsmc_ecc1_ooblayout_free(struct mtd_info *mtd, int section,
  163. struct mtd_oob_region *oobregion)
  164. {
  165. struct nand_chip *chip = mtd_to_nand(mtd);
  166. if (section >= chip->ecc.steps)
  167. return -ERANGE;
  168. oobregion->offset = (section * 16) + 8;
  169. if (section < chip->ecc.steps - 1)
  170. oobregion->length = 8;
  171. else
  172. oobregion->length = mtd->oobsize - oobregion->offset;
  173. return 0;
  174. }
  175. static const struct mtd_ooblayout_ops fsmc_ecc1_ooblayout_ops = {
  176. .ecc = fsmc_ecc1_ooblayout_ecc,
  177. .free = fsmc_ecc1_ooblayout_free,
  178. };
  179. /*
  180. * ECC placement definitions in oobfree type format.
  181. * There are 13 bytes of ecc for every 512 byte block and it has to be read
  182. * consecutively and immediately after the 512 byte data block for hardware to
  183. * generate the error bit offsets in 512 byte data.
  184. */
  185. static int fsmc_ecc4_ooblayout_ecc(struct mtd_info *mtd, int section,
  186. struct mtd_oob_region *oobregion)
  187. {
  188. struct nand_chip *chip = mtd_to_nand(mtd);
  189. if (section >= chip->ecc.steps)
  190. return -ERANGE;
  191. oobregion->length = chip->ecc.bytes;
  192. if (!section && mtd->writesize <= 512)
  193. oobregion->offset = 0;
  194. else
  195. oobregion->offset = (section * 16) + 2;
  196. return 0;
  197. }
  198. static int fsmc_ecc4_ooblayout_free(struct mtd_info *mtd, int section,
  199. struct mtd_oob_region *oobregion)
  200. {
  201. struct nand_chip *chip = mtd_to_nand(mtd);
  202. if (section >= chip->ecc.steps)
  203. return -ERANGE;
  204. oobregion->offset = (section * 16) + 15;
  205. if (section < chip->ecc.steps - 1)
  206. oobregion->length = 3;
  207. else
  208. oobregion->length = mtd->oobsize - oobregion->offset;
  209. return 0;
  210. }
  211. static const struct mtd_ooblayout_ops fsmc_ecc4_ooblayout_ops = {
  212. .ecc = fsmc_ecc4_ooblayout_ecc,
  213. .free = fsmc_ecc4_ooblayout_free,
  214. };
  215. static inline struct fsmc_nand_data *mtd_to_fsmc(struct mtd_info *mtd)
  216. {
  217. return container_of(mtd_to_nand(mtd), struct fsmc_nand_data, nand);
  218. }
  219. /*
  220. * fsmc_nand_setup - FSMC (Flexible Static Memory Controller) init routine
  221. *
  222. * This routine initializes timing parameters related to NAND memory access in
  223. * FSMC registers
  224. */
  225. static void fsmc_nand_setup(struct fsmc_nand_data *host,
  226. struct fsmc_nand_timings *tims)
  227. {
  228. uint32_t value = FSMC_DEVTYPE_NAND | FSMC_ENABLE | FSMC_WAITON;
  229. uint32_t tclr, tar, thiz, thold, twait, tset;
  230. tclr = (tims->tclr & FSMC_TCLR_MASK) << FSMC_TCLR_SHIFT;
  231. tar = (tims->tar & FSMC_TAR_MASK) << FSMC_TAR_SHIFT;
  232. thiz = (tims->thiz & FSMC_THIZ_MASK) << FSMC_THIZ_SHIFT;
  233. thold = (tims->thold & FSMC_THOLD_MASK) << FSMC_THOLD_SHIFT;
  234. twait = (tims->twait & FSMC_TWAIT_MASK) << FSMC_TWAIT_SHIFT;
  235. tset = (tims->tset & FSMC_TSET_MASK) << FSMC_TSET_SHIFT;
  236. if (host->nand.options & NAND_BUSWIDTH_16)
  237. writel_relaxed(value | FSMC_DEVWID_16,
  238. host->regs_va + FSMC_PC);
  239. else
  240. writel_relaxed(value | FSMC_DEVWID_8, host->regs_va + FSMC_PC);
  241. writel_relaxed(readl(host->regs_va + FSMC_PC) | tclr | tar,
  242. host->regs_va + FSMC_PC);
  243. writel_relaxed(thiz | thold | twait | tset, host->regs_va + COMM);
  244. writel_relaxed(thiz | thold | twait | tset, host->regs_va + ATTRIB);
  245. }
  246. static int fsmc_calc_timings(struct fsmc_nand_data *host,
  247. const struct nand_sdr_timings *sdrt,
  248. struct fsmc_nand_timings *tims)
  249. {
  250. unsigned long hclk = clk_get_rate(host->clk);
  251. unsigned long hclkn = NSEC_PER_SEC / hclk;
  252. uint32_t thiz, thold, twait, tset;
  253. if (sdrt->tRC_min < 30000)
  254. return -EOPNOTSUPP;
  255. tims->tar = DIV_ROUND_UP(sdrt->tAR_min / 1000, hclkn) - 1;
  256. if (tims->tar > FSMC_TAR_MASK)
  257. tims->tar = FSMC_TAR_MASK;
  258. tims->tclr = DIV_ROUND_UP(sdrt->tCLR_min / 1000, hclkn) - 1;
  259. if (tims->tclr > FSMC_TCLR_MASK)
  260. tims->tclr = FSMC_TCLR_MASK;
  261. thiz = sdrt->tCS_min - sdrt->tWP_min;
  262. tims->thiz = DIV_ROUND_UP(thiz / 1000, hclkn);
  263. thold = sdrt->tDH_min;
  264. if (thold < sdrt->tCH_min)
  265. thold = sdrt->tCH_min;
  266. if (thold < sdrt->tCLH_min)
  267. thold = sdrt->tCLH_min;
  268. if (thold < sdrt->tWH_min)
  269. thold = sdrt->tWH_min;
  270. if (thold < sdrt->tALH_min)
  271. thold = sdrt->tALH_min;
  272. if (thold < sdrt->tREH_min)
  273. thold = sdrt->tREH_min;
  274. tims->thold = DIV_ROUND_UP(thold / 1000, hclkn);
  275. if (tims->thold == 0)
  276. tims->thold = 1;
  277. else if (tims->thold > FSMC_THOLD_MASK)
  278. tims->thold = FSMC_THOLD_MASK;
  279. twait = max(sdrt->tRP_min, sdrt->tWP_min);
  280. tims->twait = DIV_ROUND_UP(twait / 1000, hclkn) - 1;
  281. if (tims->twait == 0)
  282. tims->twait = 1;
  283. else if (tims->twait > FSMC_TWAIT_MASK)
  284. tims->twait = FSMC_TWAIT_MASK;
  285. tset = max(sdrt->tCS_min - sdrt->tWP_min,
  286. sdrt->tCEA_max - sdrt->tREA_max);
  287. tims->tset = DIV_ROUND_UP(tset / 1000, hclkn) - 1;
  288. if (tims->tset == 0)
  289. tims->tset = 1;
  290. else if (tims->tset > FSMC_TSET_MASK)
  291. tims->tset = FSMC_TSET_MASK;
  292. return 0;
  293. }
  294. static int fsmc_setup_data_interface(struct mtd_info *mtd, int csline,
  295. const struct nand_data_interface *conf)
  296. {
  297. struct nand_chip *nand = mtd_to_nand(mtd);
  298. struct fsmc_nand_data *host = nand_get_controller_data(nand);
  299. struct fsmc_nand_timings tims;
  300. const struct nand_sdr_timings *sdrt;
  301. int ret;
  302. sdrt = nand_get_sdr_timings(conf);
  303. if (IS_ERR(sdrt))
  304. return PTR_ERR(sdrt);
  305. ret = fsmc_calc_timings(host, sdrt, &tims);
  306. if (ret)
  307. return ret;
  308. if (csline == NAND_DATA_IFACE_CHECK_ONLY)
  309. return 0;
  310. fsmc_nand_setup(host, &tims);
  311. return 0;
  312. }
  313. /*
  314. * fsmc_enable_hwecc - Enables Hardware ECC through FSMC registers
  315. */
  316. static void fsmc_enable_hwecc(struct mtd_info *mtd, int mode)
  317. {
  318. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  319. writel_relaxed(readl(host->regs_va + FSMC_PC) & ~FSMC_ECCPLEN_256,
  320. host->regs_va + FSMC_PC);
  321. writel_relaxed(readl(host->regs_va + FSMC_PC) & ~FSMC_ECCEN,
  322. host->regs_va + FSMC_PC);
  323. writel_relaxed(readl(host->regs_va + FSMC_PC) | FSMC_ECCEN,
  324. host->regs_va + FSMC_PC);
  325. }
  326. /*
  327. * fsmc_read_hwecc_ecc4 - Hardware ECC calculator for ecc4 option supported by
  328. * FSMC. ECC is 13 bytes for 512 bytes of data (supports error correction up to
  329. * max of 8-bits)
  330. */
  331. static int fsmc_read_hwecc_ecc4(struct mtd_info *mtd, const uint8_t *data,
  332. uint8_t *ecc)
  333. {
  334. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  335. uint32_t ecc_tmp;
  336. unsigned long deadline = jiffies + FSMC_BUSY_WAIT_TIMEOUT;
  337. do {
  338. if (readl_relaxed(host->regs_va + STS) & FSMC_CODE_RDY)
  339. break;
  340. else
  341. cond_resched();
  342. } while (!time_after_eq(jiffies, deadline));
  343. if (time_after_eq(jiffies, deadline)) {
  344. dev_err(host->dev, "calculate ecc timed out\n");
  345. return -ETIMEDOUT;
  346. }
  347. ecc_tmp = readl_relaxed(host->regs_va + ECC1);
  348. ecc[0] = (uint8_t) (ecc_tmp >> 0);
  349. ecc[1] = (uint8_t) (ecc_tmp >> 8);
  350. ecc[2] = (uint8_t) (ecc_tmp >> 16);
  351. ecc[3] = (uint8_t) (ecc_tmp >> 24);
  352. ecc_tmp = readl_relaxed(host->regs_va + ECC2);
  353. ecc[4] = (uint8_t) (ecc_tmp >> 0);
  354. ecc[5] = (uint8_t) (ecc_tmp >> 8);
  355. ecc[6] = (uint8_t) (ecc_tmp >> 16);
  356. ecc[7] = (uint8_t) (ecc_tmp >> 24);
  357. ecc_tmp = readl_relaxed(host->regs_va + ECC3);
  358. ecc[8] = (uint8_t) (ecc_tmp >> 0);
  359. ecc[9] = (uint8_t) (ecc_tmp >> 8);
  360. ecc[10] = (uint8_t) (ecc_tmp >> 16);
  361. ecc[11] = (uint8_t) (ecc_tmp >> 24);
  362. ecc_tmp = readl_relaxed(host->regs_va + STS);
  363. ecc[12] = (uint8_t) (ecc_tmp >> 16);
  364. return 0;
  365. }
  366. /*
  367. * fsmc_read_hwecc_ecc1 - Hardware ECC calculator for ecc1 option supported by
  368. * FSMC. ECC is 3 bytes for 512 bytes of data (supports error correction up to
  369. * max of 1-bit)
  370. */
  371. static int fsmc_read_hwecc_ecc1(struct mtd_info *mtd, const uint8_t *data,
  372. uint8_t *ecc)
  373. {
  374. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  375. uint32_t ecc_tmp;
  376. ecc_tmp = readl_relaxed(host->regs_va + ECC1);
  377. ecc[0] = (uint8_t) (ecc_tmp >> 0);
  378. ecc[1] = (uint8_t) (ecc_tmp >> 8);
  379. ecc[2] = (uint8_t) (ecc_tmp >> 16);
  380. return 0;
  381. }
  382. /* Count the number of 0's in buff upto a max of max_bits */
  383. static int count_written_bits(uint8_t *buff, int size, int max_bits)
  384. {
  385. int k, written_bits = 0;
  386. for (k = 0; k < size; k++) {
  387. written_bits += hweight8(~buff[k]);
  388. if (written_bits > max_bits)
  389. break;
  390. }
  391. return written_bits;
  392. }
  393. static void dma_complete(void *param)
  394. {
  395. struct fsmc_nand_data *host = param;
  396. complete(&host->dma_access_complete);
  397. }
  398. static int dma_xfer(struct fsmc_nand_data *host, void *buffer, int len,
  399. enum dma_data_direction direction)
  400. {
  401. struct dma_chan *chan;
  402. struct dma_device *dma_dev;
  403. struct dma_async_tx_descriptor *tx;
  404. dma_addr_t dma_dst, dma_src, dma_addr;
  405. dma_cookie_t cookie;
  406. unsigned long flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
  407. int ret;
  408. unsigned long time_left;
  409. if (direction == DMA_TO_DEVICE)
  410. chan = host->write_dma_chan;
  411. else if (direction == DMA_FROM_DEVICE)
  412. chan = host->read_dma_chan;
  413. else
  414. return -EINVAL;
  415. dma_dev = chan->device;
  416. dma_addr = dma_map_single(dma_dev->dev, buffer, len, direction);
  417. if (direction == DMA_TO_DEVICE) {
  418. dma_src = dma_addr;
  419. dma_dst = host->data_pa;
  420. } else {
  421. dma_src = host->data_pa;
  422. dma_dst = dma_addr;
  423. }
  424. tx = dma_dev->device_prep_dma_memcpy(chan, dma_dst, dma_src,
  425. len, flags);
  426. if (!tx) {
  427. dev_err(host->dev, "device_prep_dma_memcpy error\n");
  428. ret = -EIO;
  429. goto unmap_dma;
  430. }
  431. tx->callback = dma_complete;
  432. tx->callback_param = host;
  433. cookie = tx->tx_submit(tx);
  434. ret = dma_submit_error(cookie);
  435. if (ret) {
  436. dev_err(host->dev, "dma_submit_error %d\n", cookie);
  437. goto unmap_dma;
  438. }
  439. dma_async_issue_pending(chan);
  440. time_left =
  441. wait_for_completion_timeout(&host->dma_access_complete,
  442. msecs_to_jiffies(3000));
  443. if (time_left == 0) {
  444. dmaengine_terminate_all(chan);
  445. dev_err(host->dev, "wait_for_completion_timeout\n");
  446. ret = -ETIMEDOUT;
  447. goto unmap_dma;
  448. }
  449. ret = 0;
  450. unmap_dma:
  451. dma_unmap_single(dma_dev->dev, dma_addr, len, direction);
  452. return ret;
  453. }
  454. /*
  455. * fsmc_write_buf - write buffer to chip
  456. * @mtd: MTD device structure
  457. * @buf: data buffer
  458. * @len: number of bytes to write
  459. */
  460. static void fsmc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  461. {
  462. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  463. int i;
  464. if (IS_ALIGNED((uintptr_t)buf, sizeof(uint32_t)) &&
  465. IS_ALIGNED(len, sizeof(uint32_t))) {
  466. uint32_t *p = (uint32_t *)buf;
  467. len = len >> 2;
  468. for (i = 0; i < len; i++)
  469. writel_relaxed(p[i], host->data_va);
  470. } else {
  471. for (i = 0; i < len; i++)
  472. writeb_relaxed(buf[i], host->data_va);
  473. }
  474. }
  475. /*
  476. * fsmc_read_buf - read chip data into buffer
  477. * @mtd: MTD device structure
  478. * @buf: buffer to store date
  479. * @len: number of bytes to read
  480. */
  481. static void fsmc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  482. {
  483. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  484. int i;
  485. if (IS_ALIGNED((uintptr_t)buf, sizeof(uint32_t)) &&
  486. IS_ALIGNED(len, sizeof(uint32_t))) {
  487. uint32_t *p = (uint32_t *)buf;
  488. len = len >> 2;
  489. for (i = 0; i < len; i++)
  490. p[i] = readl_relaxed(host->data_va);
  491. } else {
  492. for (i = 0; i < len; i++)
  493. buf[i] = readb_relaxed(host->data_va);
  494. }
  495. }
  496. /*
  497. * fsmc_read_buf_dma - read chip data into buffer
  498. * @mtd: MTD device structure
  499. * @buf: buffer to store date
  500. * @len: number of bytes to read
  501. */
  502. static void fsmc_read_buf_dma(struct mtd_info *mtd, uint8_t *buf, int len)
  503. {
  504. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  505. dma_xfer(host, buf, len, DMA_FROM_DEVICE);
  506. }
  507. /*
  508. * fsmc_write_buf_dma - write buffer to chip
  509. * @mtd: MTD device structure
  510. * @buf: data buffer
  511. * @len: number of bytes to write
  512. */
  513. static void fsmc_write_buf_dma(struct mtd_info *mtd, const uint8_t *buf,
  514. int len)
  515. {
  516. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  517. dma_xfer(host, (void *)buf, len, DMA_TO_DEVICE);
  518. }
  519. /* fsmc_select_chip - assert or deassert nCE */
  520. static void fsmc_select_chip(struct mtd_info *mtd, int chipnr)
  521. {
  522. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  523. u32 pc;
  524. /* Support only one CS */
  525. if (chipnr > 0)
  526. return;
  527. pc = readl(host->regs_va + FSMC_PC);
  528. if (chipnr < 0)
  529. writel_relaxed(pc & ~FSMC_ENABLE, host->regs_va + FSMC_PC);
  530. else
  531. writel_relaxed(pc | FSMC_ENABLE, host->regs_va + FSMC_PC);
  532. /* nCE line must be asserted before starting any operation */
  533. mb();
  534. }
  535. /*
  536. * fsmc_exec_op - hook called by the core to execute NAND operations
  537. *
  538. * This controller is simple enough and thus does not need to use the parser
  539. * provided by the core, instead, handle every situation here.
  540. */
  541. static int fsmc_exec_op(struct nand_chip *chip, const struct nand_operation *op,
  542. bool check_only)
  543. {
  544. struct mtd_info *mtd = nand_to_mtd(chip);
  545. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  546. const struct nand_op_instr *instr = NULL;
  547. int ret = 0;
  548. unsigned int op_id;
  549. int i;
  550. pr_debug("Executing operation [%d instructions]:\n", op->ninstrs);
  551. for (op_id = 0; op_id < op->ninstrs; op_id++) {
  552. instr = &op->instrs[op_id];
  553. switch (instr->type) {
  554. case NAND_OP_CMD_INSTR:
  555. pr_debug(" ->CMD [0x%02x]\n",
  556. instr->ctx.cmd.opcode);
  557. writeb_relaxed(instr->ctx.cmd.opcode, host->cmd_va);
  558. break;
  559. case NAND_OP_ADDR_INSTR:
  560. pr_debug(" ->ADDR [%d cyc]",
  561. instr->ctx.addr.naddrs);
  562. for (i = 0; i < instr->ctx.addr.naddrs; i++)
  563. writeb_relaxed(instr->ctx.addr.addrs[i],
  564. host->addr_va);
  565. break;
  566. case NAND_OP_DATA_IN_INSTR:
  567. pr_debug(" ->DATA_IN [%d B%s]\n", instr->ctx.data.len,
  568. instr->ctx.data.force_8bit ?
  569. ", force 8-bit" : "");
  570. if (host->mode == USE_DMA_ACCESS)
  571. fsmc_read_buf_dma(mtd, instr->ctx.data.buf.in,
  572. instr->ctx.data.len);
  573. else
  574. fsmc_read_buf(mtd, instr->ctx.data.buf.in,
  575. instr->ctx.data.len);
  576. break;
  577. case NAND_OP_DATA_OUT_INSTR:
  578. pr_debug(" ->DATA_OUT [%d B%s]\n", instr->ctx.data.len,
  579. instr->ctx.data.force_8bit ?
  580. ", force 8-bit" : "");
  581. if (host->mode == USE_DMA_ACCESS)
  582. fsmc_write_buf_dma(mtd, instr->ctx.data.buf.out,
  583. instr->ctx.data.len);
  584. else
  585. fsmc_write_buf(mtd, instr->ctx.data.buf.out,
  586. instr->ctx.data.len);
  587. break;
  588. case NAND_OP_WAITRDY_INSTR:
  589. pr_debug(" ->WAITRDY [max %d ms]\n",
  590. instr->ctx.waitrdy.timeout_ms);
  591. ret = nand_soft_waitrdy(chip,
  592. instr->ctx.waitrdy.timeout_ms);
  593. break;
  594. }
  595. }
  596. return ret;
  597. }
  598. /*
  599. * fsmc_read_page_hwecc
  600. * @mtd: mtd info structure
  601. * @chip: nand chip info structure
  602. * @buf: buffer to store read data
  603. * @oob_required: caller expects OOB data read to chip->oob_poi
  604. * @page: page number to read
  605. *
  606. * This routine is needed for fsmc version 8 as reading from NAND chip has to be
  607. * performed in a strict sequence as follows:
  608. * data(512 byte) -> ecc(13 byte)
  609. * After this read, fsmc hardware generates and reports error data bits(up to a
  610. * max of 8 bits)
  611. */
  612. static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
  613. uint8_t *buf, int oob_required, int page)
  614. {
  615. int i, j, s, stat, eccsize = chip->ecc.size;
  616. int eccbytes = chip->ecc.bytes;
  617. int eccsteps = chip->ecc.steps;
  618. uint8_t *p = buf;
  619. uint8_t *ecc_calc = chip->ecc.calc_buf;
  620. uint8_t *ecc_code = chip->ecc.code_buf;
  621. int off, len, group = 0;
  622. /*
  623. * ecc_oob is intentionally taken as uint16_t. In 16bit devices, we
  624. * end up reading 14 bytes (7 words) from oob. The local array is
  625. * to maintain word alignment
  626. */
  627. uint16_t ecc_oob[7];
  628. uint8_t *oob = (uint8_t *)&ecc_oob[0];
  629. unsigned int max_bitflips = 0;
  630. for (i = 0, s = 0; s < eccsteps; s++, i += eccbytes, p += eccsize) {
  631. nand_read_page_op(chip, page, s * eccsize, NULL, 0);
  632. chip->ecc.hwctl(mtd, NAND_ECC_READ);
  633. nand_read_data_op(chip, p, eccsize, false);
  634. for (j = 0; j < eccbytes;) {
  635. struct mtd_oob_region oobregion;
  636. int ret;
  637. ret = mtd_ooblayout_ecc(mtd, group++, &oobregion);
  638. if (ret)
  639. return ret;
  640. off = oobregion.offset;
  641. len = oobregion.length;
  642. /*
  643. * length is intentionally kept a higher multiple of 2
  644. * to read at least 13 bytes even in case of 16 bit NAND
  645. * devices
  646. */
  647. if (chip->options & NAND_BUSWIDTH_16)
  648. len = roundup(len, 2);
  649. nand_read_oob_op(chip, page, off, oob + j, len);
  650. j += len;
  651. }
  652. memcpy(&ecc_code[i], oob, chip->ecc.bytes);
  653. chip->ecc.calculate(mtd, p, &ecc_calc[i]);
  654. stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
  655. if (stat < 0) {
  656. mtd->ecc_stats.failed++;
  657. } else {
  658. mtd->ecc_stats.corrected += stat;
  659. max_bitflips = max_t(unsigned int, max_bitflips, stat);
  660. }
  661. }
  662. return max_bitflips;
  663. }
  664. /*
  665. * fsmc_bch8_correct_data
  666. * @mtd: mtd info structure
  667. * @dat: buffer of read data
  668. * @read_ecc: ecc read from device spare area
  669. * @calc_ecc: ecc calculated from read data
  670. *
  671. * calc_ecc is a 104 bit information containing maximum of 8 error
  672. * offset informations of 13 bits each in 512 bytes of read data.
  673. */
  674. static int fsmc_bch8_correct_data(struct mtd_info *mtd, uint8_t *dat,
  675. uint8_t *read_ecc, uint8_t *calc_ecc)
  676. {
  677. struct nand_chip *chip = mtd_to_nand(mtd);
  678. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  679. uint32_t err_idx[8];
  680. uint32_t num_err, i;
  681. uint32_t ecc1, ecc2, ecc3, ecc4;
  682. num_err = (readl_relaxed(host->regs_va + STS) >> 10) & 0xF;
  683. /* no bit flipping */
  684. if (likely(num_err == 0))
  685. return 0;
  686. /* too many errors */
  687. if (unlikely(num_err > 8)) {
  688. /*
  689. * This is a temporary erase check. A newly erased page read
  690. * would result in an ecc error because the oob data is also
  691. * erased to FF and the calculated ecc for an FF data is not
  692. * FF..FF.
  693. * This is a workaround to skip performing correction in case
  694. * data is FF..FF
  695. *
  696. * Logic:
  697. * For every page, each bit written as 0 is counted until these
  698. * number of bits are greater than 8 (the maximum correction
  699. * capability of FSMC for each 512 + 13 bytes)
  700. */
  701. int bits_ecc = count_written_bits(read_ecc, chip->ecc.bytes, 8);
  702. int bits_data = count_written_bits(dat, chip->ecc.size, 8);
  703. if ((bits_ecc + bits_data) <= 8) {
  704. if (bits_data)
  705. memset(dat, 0xff, chip->ecc.size);
  706. return bits_data;
  707. }
  708. return -EBADMSG;
  709. }
  710. /*
  711. * ------------------- calc_ecc[] bit wise -----------|--13 bits--|
  712. * |---idx[7]--|--.....-----|---idx[2]--||---idx[1]--||---idx[0]--|
  713. *
  714. * calc_ecc is a 104 bit information containing maximum of 8 error
  715. * offset informations of 13 bits each. calc_ecc is copied into a
  716. * uint64_t array and error offset indexes are populated in err_idx
  717. * array
  718. */
  719. ecc1 = readl_relaxed(host->regs_va + ECC1);
  720. ecc2 = readl_relaxed(host->regs_va + ECC2);
  721. ecc3 = readl_relaxed(host->regs_va + ECC3);
  722. ecc4 = readl_relaxed(host->regs_va + STS);
  723. err_idx[0] = (ecc1 >> 0) & 0x1FFF;
  724. err_idx[1] = (ecc1 >> 13) & 0x1FFF;
  725. err_idx[2] = (((ecc2 >> 0) & 0x7F) << 6) | ((ecc1 >> 26) & 0x3F);
  726. err_idx[3] = (ecc2 >> 7) & 0x1FFF;
  727. err_idx[4] = (((ecc3 >> 0) & 0x1) << 12) | ((ecc2 >> 20) & 0xFFF);
  728. err_idx[5] = (ecc3 >> 1) & 0x1FFF;
  729. err_idx[6] = (ecc3 >> 14) & 0x1FFF;
  730. err_idx[7] = (((ecc4 >> 16) & 0xFF) << 5) | ((ecc3 >> 27) & 0x1F);
  731. i = 0;
  732. while (num_err--) {
  733. change_bit(0, (unsigned long *)&err_idx[i]);
  734. change_bit(1, (unsigned long *)&err_idx[i]);
  735. if (err_idx[i] < chip->ecc.size * 8) {
  736. change_bit(err_idx[i], (unsigned long *)dat);
  737. i++;
  738. }
  739. }
  740. return i;
  741. }
  742. static bool filter(struct dma_chan *chan, void *slave)
  743. {
  744. chan->private = slave;
  745. return true;
  746. }
  747. static int fsmc_nand_probe_config_dt(struct platform_device *pdev,
  748. struct fsmc_nand_data *host,
  749. struct nand_chip *nand)
  750. {
  751. struct device_node *np = pdev->dev.of_node;
  752. u32 val;
  753. int ret;
  754. nand->options = 0;
  755. if (!of_property_read_u32(np, "bank-width", &val)) {
  756. if (val == 2) {
  757. nand->options |= NAND_BUSWIDTH_16;
  758. } else if (val != 1) {
  759. dev_err(&pdev->dev, "invalid bank-width %u\n", val);
  760. return -EINVAL;
  761. }
  762. }
  763. if (of_get_property(np, "nand-skip-bbtscan", NULL))
  764. nand->options |= NAND_SKIP_BBTSCAN;
  765. host->dev_timings = devm_kzalloc(&pdev->dev,
  766. sizeof(*host->dev_timings), GFP_KERNEL);
  767. if (!host->dev_timings)
  768. return -ENOMEM;
  769. ret = of_property_read_u8_array(np, "timings", (u8 *)host->dev_timings,
  770. sizeof(*host->dev_timings));
  771. if (ret)
  772. host->dev_timings = NULL;
  773. /* Set default NAND bank to 0 */
  774. host->bank = 0;
  775. if (!of_property_read_u32(np, "bank", &val)) {
  776. if (val > 3) {
  777. dev_err(&pdev->dev, "invalid bank %u\n", val);
  778. return -EINVAL;
  779. }
  780. host->bank = val;
  781. }
  782. return 0;
  783. }
  784. static int fsmc_nand_attach_chip(struct nand_chip *nand)
  785. {
  786. struct mtd_info *mtd = nand_to_mtd(nand);
  787. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  788. if (AMBA_REV_BITS(host->pid) >= 8) {
  789. switch (mtd->oobsize) {
  790. case 16:
  791. case 64:
  792. case 128:
  793. case 224:
  794. case 256:
  795. break;
  796. default:
  797. dev_warn(host->dev,
  798. "No oob scheme defined for oobsize %d\n",
  799. mtd->oobsize);
  800. return -EINVAL;
  801. }
  802. mtd_set_ooblayout(mtd, &fsmc_ecc4_ooblayout_ops);
  803. return 0;
  804. }
  805. switch (nand->ecc.mode) {
  806. case NAND_ECC_HW:
  807. dev_info(host->dev, "Using 1-bit HW ECC scheme\n");
  808. nand->ecc.calculate = fsmc_read_hwecc_ecc1;
  809. nand->ecc.correct = nand_correct_data;
  810. nand->ecc.bytes = 3;
  811. nand->ecc.strength = 1;
  812. break;
  813. case NAND_ECC_SOFT:
  814. if (nand->ecc.algo == NAND_ECC_BCH) {
  815. dev_info(host->dev,
  816. "Using 4-bit SW BCH ECC scheme\n");
  817. break;
  818. }
  819. case NAND_ECC_ON_DIE:
  820. break;
  821. default:
  822. dev_err(host->dev, "Unsupported ECC mode!\n");
  823. return -ENOTSUPP;
  824. }
  825. /*
  826. * Don't set layout for BCH4 SW ECC. This will be
  827. * generated later in nand_bch_init() later.
  828. */
  829. if (nand->ecc.mode == NAND_ECC_HW) {
  830. switch (mtd->oobsize) {
  831. case 16:
  832. case 64:
  833. case 128:
  834. mtd_set_ooblayout(mtd,
  835. &fsmc_ecc1_ooblayout_ops);
  836. break;
  837. default:
  838. dev_warn(host->dev,
  839. "No oob scheme defined for oobsize %d\n",
  840. mtd->oobsize);
  841. return -EINVAL;
  842. }
  843. }
  844. return 0;
  845. }
  846. static const struct nand_controller_ops fsmc_nand_controller_ops = {
  847. .attach_chip = fsmc_nand_attach_chip,
  848. };
  849. /*
  850. * fsmc_nand_probe - Probe function
  851. * @pdev: platform device structure
  852. */
  853. static int __init fsmc_nand_probe(struct platform_device *pdev)
  854. {
  855. struct fsmc_nand_data *host;
  856. struct mtd_info *mtd;
  857. struct nand_chip *nand;
  858. struct resource *res;
  859. void __iomem *base;
  860. dma_cap_mask_t mask;
  861. int ret = 0;
  862. u32 pid;
  863. int i;
  864. /* Allocate memory for the device structure (and zero it) */
  865. host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
  866. if (!host)
  867. return -ENOMEM;
  868. nand = &host->nand;
  869. ret = fsmc_nand_probe_config_dt(pdev, host, nand);
  870. if (ret)
  871. return ret;
  872. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data");
  873. host->data_va = devm_ioremap_resource(&pdev->dev, res);
  874. if (IS_ERR(host->data_va))
  875. return PTR_ERR(host->data_va);
  876. host->data_pa = (dma_addr_t)res->start;
  877. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_addr");
  878. host->addr_va = devm_ioremap_resource(&pdev->dev, res);
  879. if (IS_ERR(host->addr_va))
  880. return PTR_ERR(host->addr_va);
  881. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_cmd");
  882. host->cmd_va = devm_ioremap_resource(&pdev->dev, res);
  883. if (IS_ERR(host->cmd_va))
  884. return PTR_ERR(host->cmd_va);
  885. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fsmc_regs");
  886. base = devm_ioremap_resource(&pdev->dev, res);
  887. if (IS_ERR(base))
  888. return PTR_ERR(base);
  889. host->regs_va = base + FSMC_NOR_REG_SIZE +
  890. (host->bank * FSMC_NAND_BANK_SZ);
  891. host->clk = devm_clk_get(&pdev->dev, NULL);
  892. if (IS_ERR(host->clk)) {
  893. dev_err(&pdev->dev, "failed to fetch block clock\n");
  894. return PTR_ERR(host->clk);
  895. }
  896. ret = clk_prepare_enable(host->clk);
  897. if (ret)
  898. return ret;
  899. /*
  900. * This device ID is actually a common AMBA ID as used on the
  901. * AMBA PrimeCell bus. However it is not a PrimeCell.
  902. */
  903. for (pid = 0, i = 0; i < 4; i++)
  904. pid |= (readl(base + resource_size(res) - 0x20 + 4 * i) & 255) << (i * 8);
  905. host->pid = pid;
  906. dev_info(&pdev->dev, "FSMC device partno %03x, manufacturer %02x, "
  907. "revision %02x, config %02x\n",
  908. AMBA_PART_BITS(pid), AMBA_MANF_BITS(pid),
  909. AMBA_REV_BITS(pid), AMBA_CONFIG_BITS(pid));
  910. host->dev = &pdev->dev;
  911. if (host->mode == USE_DMA_ACCESS)
  912. init_completion(&host->dma_access_complete);
  913. /* Link all private pointers */
  914. mtd = nand_to_mtd(&host->nand);
  915. nand_set_controller_data(nand, host);
  916. nand_set_flash_node(nand, pdev->dev.of_node);
  917. mtd->dev.parent = &pdev->dev;
  918. nand->exec_op = fsmc_exec_op;
  919. nand->select_chip = fsmc_select_chip;
  920. nand->chip_delay = 30;
  921. /*
  922. * Setup default ECC mode. nand_dt_init() called from nand_scan_ident()
  923. * can overwrite this value if the DT provides a different value.
  924. */
  925. nand->ecc.mode = NAND_ECC_HW;
  926. nand->ecc.hwctl = fsmc_enable_hwecc;
  927. nand->ecc.size = 512;
  928. nand->badblockbits = 7;
  929. if (host->mode == USE_DMA_ACCESS) {
  930. dma_cap_zero(mask);
  931. dma_cap_set(DMA_MEMCPY, mask);
  932. host->read_dma_chan = dma_request_channel(mask, filter, NULL);
  933. if (!host->read_dma_chan) {
  934. dev_err(&pdev->dev, "Unable to get read dma channel\n");
  935. ret = -ENODEV;
  936. goto disable_clk;
  937. }
  938. host->write_dma_chan = dma_request_channel(mask, filter, NULL);
  939. if (!host->write_dma_chan) {
  940. dev_err(&pdev->dev, "Unable to get write dma channel\n");
  941. ret = -ENODEV;
  942. goto release_dma_read_chan;
  943. }
  944. }
  945. if (host->dev_timings)
  946. fsmc_nand_setup(host, host->dev_timings);
  947. else
  948. nand->setup_data_interface = fsmc_setup_data_interface;
  949. if (AMBA_REV_BITS(host->pid) >= 8) {
  950. nand->ecc.read_page = fsmc_read_page_hwecc;
  951. nand->ecc.calculate = fsmc_read_hwecc_ecc4;
  952. nand->ecc.correct = fsmc_bch8_correct_data;
  953. nand->ecc.bytes = 13;
  954. nand->ecc.strength = 8;
  955. }
  956. /*
  957. * Scan to find existence of the device
  958. */
  959. nand->dummy_controller.ops = &fsmc_nand_controller_ops;
  960. ret = nand_scan(nand, 1);
  961. if (ret)
  962. goto release_dma_write_chan;
  963. mtd->name = "nand";
  964. ret = mtd_device_register(mtd, NULL, 0);
  965. if (ret)
  966. goto cleanup_nand;
  967. platform_set_drvdata(pdev, host);
  968. dev_info(&pdev->dev, "FSMC NAND driver registration successful\n");
  969. return 0;
  970. cleanup_nand:
  971. nand_cleanup(nand);
  972. release_dma_write_chan:
  973. if (host->mode == USE_DMA_ACCESS)
  974. dma_release_channel(host->write_dma_chan);
  975. release_dma_read_chan:
  976. if (host->mode == USE_DMA_ACCESS)
  977. dma_release_channel(host->read_dma_chan);
  978. disable_clk:
  979. clk_disable_unprepare(host->clk);
  980. return ret;
  981. }
  982. /*
  983. * Clean up routine
  984. */
  985. static int fsmc_nand_remove(struct platform_device *pdev)
  986. {
  987. struct fsmc_nand_data *host = platform_get_drvdata(pdev);
  988. if (host) {
  989. nand_release(&host->nand);
  990. if (host->mode == USE_DMA_ACCESS) {
  991. dma_release_channel(host->write_dma_chan);
  992. dma_release_channel(host->read_dma_chan);
  993. }
  994. clk_disable_unprepare(host->clk);
  995. }
  996. return 0;
  997. }
  998. #ifdef CONFIG_PM_SLEEP
  999. static int fsmc_nand_suspend(struct device *dev)
  1000. {
  1001. struct fsmc_nand_data *host = dev_get_drvdata(dev);
  1002. if (host)
  1003. clk_disable_unprepare(host->clk);
  1004. return 0;
  1005. }
  1006. static int fsmc_nand_resume(struct device *dev)
  1007. {
  1008. struct fsmc_nand_data *host = dev_get_drvdata(dev);
  1009. if (host) {
  1010. clk_prepare_enable(host->clk);
  1011. if (host->dev_timings)
  1012. fsmc_nand_setup(host, host->dev_timings);
  1013. }
  1014. return 0;
  1015. }
  1016. #endif
  1017. static SIMPLE_DEV_PM_OPS(fsmc_nand_pm_ops, fsmc_nand_suspend, fsmc_nand_resume);
  1018. static const struct of_device_id fsmc_nand_id_table[] = {
  1019. { .compatible = "st,spear600-fsmc-nand" },
  1020. { .compatible = "stericsson,fsmc-nand" },
  1021. {}
  1022. };
  1023. MODULE_DEVICE_TABLE(of, fsmc_nand_id_table);
  1024. static struct platform_driver fsmc_nand_driver = {
  1025. .remove = fsmc_nand_remove,
  1026. .driver = {
  1027. .name = "fsmc-nand",
  1028. .of_match_table = fsmc_nand_id_table,
  1029. .pm = &fsmc_nand_pm_ops,
  1030. },
  1031. };
  1032. module_platform_driver_probe(fsmc_nand_driver, fsmc_nand_probe);
  1033. MODULE_LICENSE("GPL");
  1034. MODULE_AUTHOR("Vipin Kumar <vipin.kumar@st.com>, Ashish Priyadarshi");
  1035. MODULE_DESCRIPTION("NAND driver for SPEAr Platforms");