fsmc_nand.c 31 KB

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