fsmc_nand.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  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. goto disable_clk;
  936. }
  937. host->write_dma_chan = dma_request_channel(mask, filter, NULL);
  938. if (!host->write_dma_chan) {
  939. dev_err(&pdev->dev, "Unable to get write dma channel\n");
  940. goto release_dma_read_chan;
  941. }
  942. }
  943. if (host->dev_timings)
  944. fsmc_nand_setup(host, host->dev_timings);
  945. else
  946. nand->setup_data_interface = fsmc_setup_data_interface;
  947. if (AMBA_REV_BITS(host->pid) >= 8) {
  948. nand->ecc.read_page = fsmc_read_page_hwecc;
  949. nand->ecc.calculate = fsmc_read_hwecc_ecc4;
  950. nand->ecc.correct = fsmc_bch8_correct_data;
  951. nand->ecc.bytes = 13;
  952. nand->ecc.strength = 8;
  953. }
  954. /*
  955. * Scan to find existence of the device
  956. */
  957. nand->dummy_controller.ops = &fsmc_nand_controller_ops;
  958. ret = nand_scan(mtd, 1);
  959. if (ret)
  960. goto release_dma_write_chan;
  961. mtd->name = "nand";
  962. ret = mtd_device_register(mtd, NULL, 0);
  963. if (ret)
  964. goto cleanup_nand;
  965. platform_set_drvdata(pdev, host);
  966. dev_info(&pdev->dev, "FSMC NAND driver registration successful\n");
  967. return 0;
  968. cleanup_nand:
  969. nand_cleanup(nand);
  970. release_dma_write_chan:
  971. if (host->mode == USE_DMA_ACCESS)
  972. dma_release_channel(host->write_dma_chan);
  973. release_dma_read_chan:
  974. if (host->mode == USE_DMA_ACCESS)
  975. dma_release_channel(host->read_dma_chan);
  976. disable_clk:
  977. clk_disable_unprepare(host->clk);
  978. return ret;
  979. }
  980. /*
  981. * Clean up routine
  982. */
  983. static int fsmc_nand_remove(struct platform_device *pdev)
  984. {
  985. struct fsmc_nand_data *host = platform_get_drvdata(pdev);
  986. if (host) {
  987. nand_release(nand_to_mtd(&host->nand));
  988. if (host->mode == USE_DMA_ACCESS) {
  989. dma_release_channel(host->write_dma_chan);
  990. dma_release_channel(host->read_dma_chan);
  991. }
  992. clk_disable_unprepare(host->clk);
  993. }
  994. return 0;
  995. }
  996. #ifdef CONFIG_PM_SLEEP
  997. static int fsmc_nand_suspend(struct device *dev)
  998. {
  999. struct fsmc_nand_data *host = dev_get_drvdata(dev);
  1000. if (host)
  1001. clk_disable_unprepare(host->clk);
  1002. return 0;
  1003. }
  1004. static int fsmc_nand_resume(struct device *dev)
  1005. {
  1006. struct fsmc_nand_data *host = dev_get_drvdata(dev);
  1007. if (host) {
  1008. clk_prepare_enable(host->clk);
  1009. if (host->dev_timings)
  1010. fsmc_nand_setup(host, host->dev_timings);
  1011. }
  1012. return 0;
  1013. }
  1014. #endif
  1015. static SIMPLE_DEV_PM_OPS(fsmc_nand_pm_ops, fsmc_nand_suspend, fsmc_nand_resume);
  1016. static const struct of_device_id fsmc_nand_id_table[] = {
  1017. { .compatible = "st,spear600-fsmc-nand" },
  1018. { .compatible = "stericsson,fsmc-nand" },
  1019. {}
  1020. };
  1021. MODULE_DEVICE_TABLE(of, fsmc_nand_id_table);
  1022. static struct platform_driver fsmc_nand_driver = {
  1023. .remove = fsmc_nand_remove,
  1024. .driver = {
  1025. .name = "fsmc-nand",
  1026. .of_match_table = fsmc_nand_id_table,
  1027. .pm = &fsmc_nand_pm_ops,
  1028. },
  1029. };
  1030. module_platform_driver_probe(fsmc_nand_driver, fsmc_nand_probe);
  1031. MODULE_LICENSE("GPL");
  1032. MODULE_AUTHOR("Vipin Kumar <vipin.kumar@st.com>, Ashish Priyadarshi");
  1033. MODULE_DESCRIPTION("NAND driver for SPEAr Platforms");