fsmc_nand.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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 nand_chip *nand, int csline,
  295. const struct nand_data_interface *conf)
  296. {
  297. struct fsmc_nand_data *host = nand_get_controller_data(nand);
  298. struct fsmc_nand_timings tims;
  299. const struct nand_sdr_timings *sdrt;
  300. int ret;
  301. sdrt = nand_get_sdr_timings(conf);
  302. if (IS_ERR(sdrt))
  303. return PTR_ERR(sdrt);
  304. ret = fsmc_calc_timings(host, sdrt, &tims);
  305. if (ret)
  306. return ret;
  307. if (csline == NAND_DATA_IFACE_CHECK_ONLY)
  308. return 0;
  309. fsmc_nand_setup(host, &tims);
  310. return 0;
  311. }
  312. /*
  313. * fsmc_enable_hwecc - Enables Hardware ECC through FSMC registers
  314. */
  315. static void fsmc_enable_hwecc(struct nand_chip *chip, int mode)
  316. {
  317. struct fsmc_nand_data *host = mtd_to_fsmc(nand_to_mtd(chip));
  318. writel_relaxed(readl(host->regs_va + FSMC_PC) & ~FSMC_ECCPLEN_256,
  319. host->regs_va + FSMC_PC);
  320. writel_relaxed(readl(host->regs_va + FSMC_PC) & ~FSMC_ECCEN,
  321. host->regs_va + FSMC_PC);
  322. writel_relaxed(readl(host->regs_va + FSMC_PC) | FSMC_ECCEN,
  323. host->regs_va + FSMC_PC);
  324. }
  325. /*
  326. * fsmc_read_hwecc_ecc4 - Hardware ECC calculator for ecc4 option supported by
  327. * FSMC. ECC is 13 bytes for 512 bytes of data (supports error correction up to
  328. * max of 8-bits)
  329. */
  330. static int fsmc_read_hwecc_ecc4(struct nand_chip *chip, const uint8_t *data,
  331. uint8_t *ecc)
  332. {
  333. struct fsmc_nand_data *host = mtd_to_fsmc(nand_to_mtd(chip));
  334. uint32_t ecc_tmp;
  335. unsigned long deadline = jiffies + FSMC_BUSY_WAIT_TIMEOUT;
  336. do {
  337. if (readl_relaxed(host->regs_va + STS) & FSMC_CODE_RDY)
  338. break;
  339. else
  340. cond_resched();
  341. } while (!time_after_eq(jiffies, deadline));
  342. if (time_after_eq(jiffies, deadline)) {
  343. dev_err(host->dev, "calculate ecc timed out\n");
  344. return -ETIMEDOUT;
  345. }
  346. ecc_tmp = readl_relaxed(host->regs_va + ECC1);
  347. ecc[0] = (uint8_t) (ecc_tmp >> 0);
  348. ecc[1] = (uint8_t) (ecc_tmp >> 8);
  349. ecc[2] = (uint8_t) (ecc_tmp >> 16);
  350. ecc[3] = (uint8_t) (ecc_tmp >> 24);
  351. ecc_tmp = readl_relaxed(host->regs_va + ECC2);
  352. ecc[4] = (uint8_t) (ecc_tmp >> 0);
  353. ecc[5] = (uint8_t) (ecc_tmp >> 8);
  354. ecc[6] = (uint8_t) (ecc_tmp >> 16);
  355. ecc[7] = (uint8_t) (ecc_tmp >> 24);
  356. ecc_tmp = readl_relaxed(host->regs_va + ECC3);
  357. ecc[8] = (uint8_t) (ecc_tmp >> 0);
  358. ecc[9] = (uint8_t) (ecc_tmp >> 8);
  359. ecc[10] = (uint8_t) (ecc_tmp >> 16);
  360. ecc[11] = (uint8_t) (ecc_tmp >> 24);
  361. ecc_tmp = readl_relaxed(host->regs_va + STS);
  362. ecc[12] = (uint8_t) (ecc_tmp >> 16);
  363. return 0;
  364. }
  365. /*
  366. * fsmc_read_hwecc_ecc1 - Hardware ECC calculator for ecc1 option supported by
  367. * FSMC. ECC is 3 bytes for 512 bytes of data (supports error correction up to
  368. * max of 1-bit)
  369. */
  370. static int fsmc_read_hwecc_ecc1(struct nand_chip *chip, const uint8_t *data,
  371. uint8_t *ecc)
  372. {
  373. struct fsmc_nand_data *host = mtd_to_fsmc(nand_to_mtd(chip));
  374. uint32_t ecc_tmp;
  375. ecc_tmp = readl_relaxed(host->regs_va + ECC1);
  376. ecc[0] = (uint8_t) (ecc_tmp >> 0);
  377. ecc[1] = (uint8_t) (ecc_tmp >> 8);
  378. ecc[2] = (uint8_t) (ecc_tmp >> 16);
  379. return 0;
  380. }
  381. /* Count the number of 0's in buff upto a max of max_bits */
  382. static int count_written_bits(uint8_t *buff, int size, int max_bits)
  383. {
  384. int k, written_bits = 0;
  385. for (k = 0; k < size; k++) {
  386. written_bits += hweight8(~buff[k]);
  387. if (written_bits > max_bits)
  388. break;
  389. }
  390. return written_bits;
  391. }
  392. static void dma_complete(void *param)
  393. {
  394. struct fsmc_nand_data *host = param;
  395. complete(&host->dma_access_complete);
  396. }
  397. static int dma_xfer(struct fsmc_nand_data *host, void *buffer, int len,
  398. enum dma_data_direction direction)
  399. {
  400. struct dma_chan *chan;
  401. struct dma_device *dma_dev;
  402. struct dma_async_tx_descriptor *tx;
  403. dma_addr_t dma_dst, dma_src, dma_addr;
  404. dma_cookie_t cookie;
  405. unsigned long flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
  406. int ret;
  407. unsigned long time_left;
  408. if (direction == DMA_TO_DEVICE)
  409. chan = host->write_dma_chan;
  410. else if (direction == DMA_FROM_DEVICE)
  411. chan = host->read_dma_chan;
  412. else
  413. return -EINVAL;
  414. dma_dev = chan->device;
  415. dma_addr = dma_map_single(dma_dev->dev, buffer, len, direction);
  416. if (direction == DMA_TO_DEVICE) {
  417. dma_src = dma_addr;
  418. dma_dst = host->data_pa;
  419. } else {
  420. dma_src = host->data_pa;
  421. dma_dst = dma_addr;
  422. }
  423. tx = dma_dev->device_prep_dma_memcpy(chan, dma_dst, dma_src,
  424. len, flags);
  425. if (!tx) {
  426. dev_err(host->dev, "device_prep_dma_memcpy error\n");
  427. ret = -EIO;
  428. goto unmap_dma;
  429. }
  430. tx->callback = dma_complete;
  431. tx->callback_param = host;
  432. cookie = tx->tx_submit(tx);
  433. ret = dma_submit_error(cookie);
  434. if (ret) {
  435. dev_err(host->dev, "dma_submit_error %d\n", cookie);
  436. goto unmap_dma;
  437. }
  438. dma_async_issue_pending(chan);
  439. time_left =
  440. wait_for_completion_timeout(&host->dma_access_complete,
  441. msecs_to_jiffies(3000));
  442. if (time_left == 0) {
  443. dmaengine_terminate_all(chan);
  444. dev_err(host->dev, "wait_for_completion_timeout\n");
  445. ret = -ETIMEDOUT;
  446. goto unmap_dma;
  447. }
  448. ret = 0;
  449. unmap_dma:
  450. dma_unmap_single(dma_dev->dev, dma_addr, len, direction);
  451. return ret;
  452. }
  453. /*
  454. * fsmc_write_buf - write buffer to chip
  455. * @mtd: MTD device structure
  456. * @buf: data buffer
  457. * @len: number of bytes to write
  458. */
  459. static void fsmc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  460. {
  461. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  462. int i;
  463. if (IS_ALIGNED((uintptr_t)buf, sizeof(uint32_t)) &&
  464. IS_ALIGNED(len, sizeof(uint32_t))) {
  465. uint32_t *p = (uint32_t *)buf;
  466. len = len >> 2;
  467. for (i = 0; i < len; i++)
  468. writel_relaxed(p[i], host->data_va);
  469. } else {
  470. for (i = 0; i < len; i++)
  471. writeb_relaxed(buf[i], host->data_va);
  472. }
  473. }
  474. /*
  475. * fsmc_read_buf - read chip data into buffer
  476. * @mtd: MTD device structure
  477. * @buf: buffer to store date
  478. * @len: number of bytes to read
  479. */
  480. static void fsmc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  481. {
  482. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  483. int i;
  484. if (IS_ALIGNED((uintptr_t)buf, sizeof(uint32_t)) &&
  485. IS_ALIGNED(len, sizeof(uint32_t))) {
  486. uint32_t *p = (uint32_t *)buf;
  487. len = len >> 2;
  488. for (i = 0; i < len; i++)
  489. p[i] = readl_relaxed(host->data_va);
  490. } else {
  491. for (i = 0; i < len; i++)
  492. buf[i] = readb_relaxed(host->data_va);
  493. }
  494. }
  495. /*
  496. * fsmc_read_buf_dma - read chip data into buffer
  497. * @mtd: MTD device structure
  498. * @buf: buffer to store date
  499. * @len: number of bytes to read
  500. */
  501. static void fsmc_read_buf_dma(struct mtd_info *mtd, uint8_t *buf, int len)
  502. {
  503. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  504. dma_xfer(host, buf, len, DMA_FROM_DEVICE);
  505. }
  506. /*
  507. * fsmc_write_buf_dma - write buffer to chip
  508. * @mtd: MTD device structure
  509. * @buf: data buffer
  510. * @len: number of bytes to write
  511. */
  512. static void fsmc_write_buf_dma(struct mtd_info *mtd, const uint8_t *buf,
  513. int len)
  514. {
  515. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  516. dma_xfer(host, (void *)buf, len, DMA_TO_DEVICE);
  517. }
  518. /* fsmc_select_chip - assert or deassert nCE */
  519. static void fsmc_select_chip(struct nand_chip *chip, int chipnr)
  520. {
  521. struct fsmc_nand_data *host = mtd_to_fsmc(nand_to_mtd(chip));
  522. u32 pc;
  523. /* Support only one CS */
  524. if (chipnr > 0)
  525. return;
  526. pc = readl(host->regs_va + FSMC_PC);
  527. if (chipnr < 0)
  528. writel_relaxed(pc & ~FSMC_ENABLE, host->regs_va + FSMC_PC);
  529. else
  530. writel_relaxed(pc | FSMC_ENABLE, host->regs_va + FSMC_PC);
  531. /* nCE line must be asserted before starting any operation */
  532. mb();
  533. }
  534. /*
  535. * fsmc_exec_op - hook called by the core to execute NAND operations
  536. *
  537. * This controller is simple enough and thus does not need to use the parser
  538. * provided by the core, instead, handle every situation here.
  539. */
  540. static int fsmc_exec_op(struct nand_chip *chip, const struct nand_operation *op,
  541. bool check_only)
  542. {
  543. struct mtd_info *mtd = nand_to_mtd(chip);
  544. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  545. const struct nand_op_instr *instr = NULL;
  546. int ret = 0;
  547. unsigned int op_id;
  548. int i;
  549. pr_debug("Executing operation [%d instructions]:\n", op->ninstrs);
  550. for (op_id = 0; op_id < op->ninstrs; op_id++) {
  551. instr = &op->instrs[op_id];
  552. switch (instr->type) {
  553. case NAND_OP_CMD_INSTR:
  554. pr_debug(" ->CMD [0x%02x]\n",
  555. instr->ctx.cmd.opcode);
  556. writeb_relaxed(instr->ctx.cmd.opcode, host->cmd_va);
  557. break;
  558. case NAND_OP_ADDR_INSTR:
  559. pr_debug(" ->ADDR [%d cyc]",
  560. instr->ctx.addr.naddrs);
  561. for (i = 0; i < instr->ctx.addr.naddrs; i++)
  562. writeb_relaxed(instr->ctx.addr.addrs[i],
  563. host->addr_va);
  564. break;
  565. case NAND_OP_DATA_IN_INSTR:
  566. pr_debug(" ->DATA_IN [%d B%s]\n", instr->ctx.data.len,
  567. instr->ctx.data.force_8bit ?
  568. ", force 8-bit" : "");
  569. if (host->mode == USE_DMA_ACCESS)
  570. fsmc_read_buf_dma(mtd, instr->ctx.data.buf.in,
  571. instr->ctx.data.len);
  572. else
  573. fsmc_read_buf(mtd, instr->ctx.data.buf.in,
  574. instr->ctx.data.len);
  575. break;
  576. case NAND_OP_DATA_OUT_INSTR:
  577. pr_debug(" ->DATA_OUT [%d B%s]\n", instr->ctx.data.len,
  578. instr->ctx.data.force_8bit ?
  579. ", force 8-bit" : "");
  580. if (host->mode == USE_DMA_ACCESS)
  581. fsmc_write_buf_dma(mtd, instr->ctx.data.buf.out,
  582. instr->ctx.data.len);
  583. else
  584. fsmc_write_buf(mtd, instr->ctx.data.buf.out,
  585. instr->ctx.data.len);
  586. break;
  587. case NAND_OP_WAITRDY_INSTR:
  588. pr_debug(" ->WAITRDY [max %d ms]\n",
  589. instr->ctx.waitrdy.timeout_ms);
  590. ret = nand_soft_waitrdy(chip,
  591. instr->ctx.waitrdy.timeout_ms);
  592. break;
  593. }
  594. }
  595. return ret;
  596. }
  597. /*
  598. * fsmc_read_page_hwecc
  599. * @chip: nand chip info structure
  600. * @buf: buffer to store read data
  601. * @oob_required: caller expects OOB data read to chip->oob_poi
  602. * @page: page number to read
  603. *
  604. * This routine is needed for fsmc version 8 as reading from NAND chip has to be
  605. * performed in a strict sequence as follows:
  606. * data(512 byte) -> ecc(13 byte)
  607. * After this read, fsmc hardware generates and reports error data bits(up to a
  608. * max of 8 bits)
  609. */
  610. static int fsmc_read_page_hwecc(struct nand_chip *chip, uint8_t *buf,
  611. int oob_required, int page)
  612. {
  613. struct mtd_info *mtd = nand_to_mtd(chip);
  614. int i, j, s, stat, eccsize = chip->ecc.size;
  615. int eccbytes = chip->ecc.bytes;
  616. int eccsteps = chip->ecc.steps;
  617. uint8_t *p = buf;
  618. uint8_t *ecc_calc = chip->ecc.calc_buf;
  619. uint8_t *ecc_code = chip->ecc.code_buf;
  620. int off, len, group = 0;
  621. /*
  622. * ecc_oob is intentionally taken as uint16_t. In 16bit devices, we
  623. * end up reading 14 bytes (7 words) from oob. The local array is
  624. * to maintain word alignment
  625. */
  626. uint16_t ecc_oob[7];
  627. uint8_t *oob = (uint8_t *)&ecc_oob[0];
  628. unsigned int max_bitflips = 0;
  629. for (i = 0, s = 0; s < eccsteps; s++, i += eccbytes, p += eccsize) {
  630. nand_read_page_op(chip, page, s * eccsize, NULL, 0);
  631. chip->ecc.hwctl(chip, NAND_ECC_READ);
  632. nand_read_data_op(chip, p, eccsize, false);
  633. for (j = 0; j < eccbytes;) {
  634. struct mtd_oob_region oobregion;
  635. int ret;
  636. ret = mtd_ooblayout_ecc(mtd, group++, &oobregion);
  637. if (ret)
  638. return ret;
  639. off = oobregion.offset;
  640. len = oobregion.length;
  641. /*
  642. * length is intentionally kept a higher multiple of 2
  643. * to read at least 13 bytes even in case of 16 bit NAND
  644. * devices
  645. */
  646. if (chip->options & NAND_BUSWIDTH_16)
  647. len = roundup(len, 2);
  648. nand_read_oob_op(chip, page, off, oob + j, len);
  649. j += len;
  650. }
  651. memcpy(&ecc_code[i], oob, chip->ecc.bytes);
  652. chip->ecc.calculate(chip, p, &ecc_calc[i]);
  653. stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]);
  654. if (stat < 0) {
  655. mtd->ecc_stats.failed++;
  656. } else {
  657. mtd->ecc_stats.corrected += stat;
  658. max_bitflips = max_t(unsigned int, max_bitflips, stat);
  659. }
  660. }
  661. return max_bitflips;
  662. }
  663. /*
  664. * fsmc_bch8_correct_data
  665. * @mtd: mtd info structure
  666. * @dat: buffer of read data
  667. * @read_ecc: ecc read from device spare area
  668. * @calc_ecc: ecc calculated from read data
  669. *
  670. * calc_ecc is a 104 bit information containing maximum of 8 error
  671. * offset informations of 13 bits each in 512 bytes of read data.
  672. */
  673. static int fsmc_bch8_correct_data(struct nand_chip *chip, uint8_t *dat,
  674. uint8_t *read_ecc, uint8_t *calc_ecc)
  675. {
  676. struct fsmc_nand_data *host = mtd_to_fsmc(nand_to_mtd(chip));
  677. uint32_t err_idx[8];
  678. uint32_t num_err, i;
  679. uint32_t ecc1, ecc2, ecc3, ecc4;
  680. num_err = (readl_relaxed(host->regs_va + STS) >> 10) & 0xF;
  681. /* no bit flipping */
  682. if (likely(num_err == 0))
  683. return 0;
  684. /* too many errors */
  685. if (unlikely(num_err > 8)) {
  686. /*
  687. * This is a temporary erase check. A newly erased page read
  688. * would result in an ecc error because the oob data is also
  689. * erased to FF and the calculated ecc for an FF data is not
  690. * FF..FF.
  691. * This is a workaround to skip performing correction in case
  692. * data is FF..FF
  693. *
  694. * Logic:
  695. * For every page, each bit written as 0 is counted until these
  696. * number of bits are greater than 8 (the maximum correction
  697. * capability of FSMC for each 512 + 13 bytes)
  698. */
  699. int bits_ecc = count_written_bits(read_ecc, chip->ecc.bytes, 8);
  700. int bits_data = count_written_bits(dat, chip->ecc.size, 8);
  701. if ((bits_ecc + bits_data) <= 8) {
  702. if (bits_data)
  703. memset(dat, 0xff, chip->ecc.size);
  704. return bits_data;
  705. }
  706. return -EBADMSG;
  707. }
  708. /*
  709. * ------------------- calc_ecc[] bit wise -----------|--13 bits--|
  710. * |---idx[7]--|--.....-----|---idx[2]--||---idx[1]--||---idx[0]--|
  711. *
  712. * calc_ecc is a 104 bit information containing maximum of 8 error
  713. * offset informations of 13 bits each. calc_ecc is copied into a
  714. * uint64_t array and error offset indexes are populated in err_idx
  715. * array
  716. */
  717. ecc1 = readl_relaxed(host->regs_va + ECC1);
  718. ecc2 = readl_relaxed(host->regs_va + ECC2);
  719. ecc3 = readl_relaxed(host->regs_va + ECC3);
  720. ecc4 = readl_relaxed(host->regs_va + STS);
  721. err_idx[0] = (ecc1 >> 0) & 0x1FFF;
  722. err_idx[1] = (ecc1 >> 13) & 0x1FFF;
  723. err_idx[2] = (((ecc2 >> 0) & 0x7F) << 6) | ((ecc1 >> 26) & 0x3F);
  724. err_idx[3] = (ecc2 >> 7) & 0x1FFF;
  725. err_idx[4] = (((ecc3 >> 0) & 0x1) << 12) | ((ecc2 >> 20) & 0xFFF);
  726. err_idx[5] = (ecc3 >> 1) & 0x1FFF;
  727. err_idx[6] = (ecc3 >> 14) & 0x1FFF;
  728. err_idx[7] = (((ecc4 >> 16) & 0xFF) << 5) | ((ecc3 >> 27) & 0x1F);
  729. i = 0;
  730. while (num_err--) {
  731. change_bit(0, (unsigned long *)&err_idx[i]);
  732. change_bit(1, (unsigned long *)&err_idx[i]);
  733. if (err_idx[i] < chip->ecc.size * 8) {
  734. change_bit(err_idx[i], (unsigned long *)dat);
  735. i++;
  736. }
  737. }
  738. return i;
  739. }
  740. static bool filter(struct dma_chan *chan, void *slave)
  741. {
  742. chan->private = slave;
  743. return true;
  744. }
  745. static int fsmc_nand_probe_config_dt(struct platform_device *pdev,
  746. struct fsmc_nand_data *host,
  747. struct nand_chip *nand)
  748. {
  749. struct device_node *np = pdev->dev.of_node;
  750. u32 val;
  751. int ret;
  752. nand->options = 0;
  753. if (!of_property_read_u32(np, "bank-width", &val)) {
  754. if (val == 2) {
  755. nand->options |= NAND_BUSWIDTH_16;
  756. } else if (val != 1) {
  757. dev_err(&pdev->dev, "invalid bank-width %u\n", val);
  758. return -EINVAL;
  759. }
  760. }
  761. if (of_get_property(np, "nand-skip-bbtscan", NULL))
  762. nand->options |= NAND_SKIP_BBTSCAN;
  763. host->dev_timings = devm_kzalloc(&pdev->dev,
  764. sizeof(*host->dev_timings), GFP_KERNEL);
  765. if (!host->dev_timings)
  766. return -ENOMEM;
  767. ret = of_property_read_u8_array(np, "timings", (u8 *)host->dev_timings,
  768. sizeof(*host->dev_timings));
  769. if (ret)
  770. host->dev_timings = NULL;
  771. /* Set default NAND bank to 0 */
  772. host->bank = 0;
  773. if (!of_property_read_u32(np, "bank", &val)) {
  774. if (val > 3) {
  775. dev_err(&pdev->dev, "invalid bank %u\n", val);
  776. return -EINVAL;
  777. }
  778. host->bank = val;
  779. }
  780. return 0;
  781. }
  782. static int fsmc_nand_attach_chip(struct nand_chip *nand)
  783. {
  784. struct mtd_info *mtd = nand_to_mtd(nand);
  785. struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
  786. if (AMBA_REV_BITS(host->pid) >= 8) {
  787. switch (mtd->oobsize) {
  788. case 16:
  789. case 64:
  790. case 128:
  791. case 224:
  792. case 256:
  793. break;
  794. default:
  795. dev_warn(host->dev,
  796. "No oob scheme defined for oobsize %d\n",
  797. mtd->oobsize);
  798. return -EINVAL;
  799. }
  800. mtd_set_ooblayout(mtd, &fsmc_ecc4_ooblayout_ops);
  801. return 0;
  802. }
  803. switch (nand->ecc.mode) {
  804. case NAND_ECC_HW:
  805. dev_info(host->dev, "Using 1-bit HW ECC scheme\n");
  806. nand->ecc.calculate = fsmc_read_hwecc_ecc1;
  807. nand->ecc.correct = nand_correct_data;
  808. nand->ecc.bytes = 3;
  809. nand->ecc.strength = 1;
  810. nand->ecc.options |= NAND_ECC_SOFT_HAMMING_SM_ORDER;
  811. break;
  812. case NAND_ECC_SOFT:
  813. if (nand->ecc.algo == NAND_ECC_BCH) {
  814. dev_info(host->dev,
  815. "Using 4-bit SW BCH ECC scheme\n");
  816. break;
  817. }
  818. case NAND_ECC_ON_DIE:
  819. break;
  820. default:
  821. dev_err(host->dev, "Unsupported ECC mode!\n");
  822. return -ENOTSUPP;
  823. }
  824. /*
  825. * Don't set layout for BCH4 SW ECC. This will be
  826. * generated later in nand_bch_init() later.
  827. */
  828. if (nand->ecc.mode == NAND_ECC_HW) {
  829. switch (mtd->oobsize) {
  830. case 16:
  831. case 64:
  832. case 128:
  833. mtd_set_ooblayout(mtd,
  834. &fsmc_ecc1_ooblayout_ops);
  835. break;
  836. default:
  837. dev_warn(host->dev,
  838. "No oob scheme defined for oobsize %d\n",
  839. mtd->oobsize);
  840. return -EINVAL;
  841. }
  842. }
  843. return 0;
  844. }
  845. static const struct nand_controller_ops fsmc_nand_controller_ops = {
  846. .attach_chip = fsmc_nand_attach_chip,
  847. };
  848. /*
  849. * fsmc_nand_probe - Probe function
  850. * @pdev: platform device structure
  851. */
  852. static int __init fsmc_nand_probe(struct platform_device *pdev)
  853. {
  854. struct fsmc_nand_data *host;
  855. struct mtd_info *mtd;
  856. struct nand_chip *nand;
  857. struct resource *res;
  858. void __iomem *base;
  859. dma_cap_mask_t mask;
  860. int ret = 0;
  861. u32 pid;
  862. int i;
  863. /* Allocate memory for the device structure (and zero it) */
  864. host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
  865. if (!host)
  866. return -ENOMEM;
  867. nand = &host->nand;
  868. ret = fsmc_nand_probe_config_dt(pdev, host, nand);
  869. if (ret)
  870. return ret;
  871. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data");
  872. host->data_va = devm_ioremap_resource(&pdev->dev, res);
  873. if (IS_ERR(host->data_va))
  874. return PTR_ERR(host->data_va);
  875. host->data_pa = (dma_addr_t)res->start;
  876. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_addr");
  877. host->addr_va = devm_ioremap_resource(&pdev->dev, res);
  878. if (IS_ERR(host->addr_va))
  879. return PTR_ERR(host->addr_va);
  880. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_cmd");
  881. host->cmd_va = devm_ioremap_resource(&pdev->dev, res);
  882. if (IS_ERR(host->cmd_va))
  883. return PTR_ERR(host->cmd_va);
  884. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fsmc_regs");
  885. base = devm_ioremap_resource(&pdev->dev, res);
  886. if (IS_ERR(base))
  887. return PTR_ERR(base);
  888. host->regs_va = base + FSMC_NOR_REG_SIZE +
  889. (host->bank * FSMC_NAND_BANK_SZ);
  890. host->clk = devm_clk_get(&pdev->dev, NULL);
  891. if (IS_ERR(host->clk)) {
  892. dev_err(&pdev->dev, "failed to fetch block clock\n");
  893. return PTR_ERR(host->clk);
  894. }
  895. ret = clk_prepare_enable(host->clk);
  896. if (ret)
  897. return ret;
  898. /*
  899. * This device ID is actually a common AMBA ID as used on the
  900. * AMBA PrimeCell bus. However it is not a PrimeCell.
  901. */
  902. for (pid = 0, i = 0; i < 4; i++)
  903. pid |= (readl(base + resource_size(res) - 0x20 + 4 * i) & 255) << (i * 8);
  904. host->pid = pid;
  905. dev_info(&pdev->dev, "FSMC device partno %03x, manufacturer %02x, "
  906. "revision %02x, config %02x\n",
  907. AMBA_PART_BITS(pid), AMBA_MANF_BITS(pid),
  908. AMBA_REV_BITS(pid), AMBA_CONFIG_BITS(pid));
  909. host->dev = &pdev->dev;
  910. if (host->mode == USE_DMA_ACCESS)
  911. init_completion(&host->dma_access_complete);
  912. /* Link all private pointers */
  913. mtd = nand_to_mtd(&host->nand);
  914. nand_set_controller_data(nand, host);
  915. nand_set_flash_node(nand, pdev->dev.of_node);
  916. mtd->dev.parent = &pdev->dev;
  917. nand->exec_op = fsmc_exec_op;
  918. nand->select_chip = fsmc_select_chip;
  919. /*
  920. * Setup default ECC mode. nand_dt_init() called from nand_scan_ident()
  921. * can overwrite this value if the DT provides a different value.
  922. */
  923. nand->ecc.mode = NAND_ECC_HW;
  924. nand->ecc.hwctl = fsmc_enable_hwecc;
  925. nand->ecc.size = 512;
  926. nand->badblockbits = 7;
  927. if (host->mode == USE_DMA_ACCESS) {
  928. dma_cap_zero(mask);
  929. dma_cap_set(DMA_MEMCPY, mask);
  930. host->read_dma_chan = dma_request_channel(mask, filter, NULL);
  931. if (!host->read_dma_chan) {
  932. dev_err(&pdev->dev, "Unable to get read dma channel\n");
  933. goto disable_clk;
  934. }
  935. host->write_dma_chan = dma_request_channel(mask, filter, NULL);
  936. if (!host->write_dma_chan) {
  937. dev_err(&pdev->dev, "Unable to get write dma channel\n");
  938. goto release_dma_read_chan;
  939. }
  940. }
  941. if (host->dev_timings)
  942. fsmc_nand_setup(host, host->dev_timings);
  943. else
  944. nand->setup_data_interface = fsmc_setup_data_interface;
  945. if (AMBA_REV_BITS(host->pid) >= 8) {
  946. nand->ecc.read_page = fsmc_read_page_hwecc;
  947. nand->ecc.calculate = fsmc_read_hwecc_ecc4;
  948. nand->ecc.correct = fsmc_bch8_correct_data;
  949. nand->ecc.bytes = 13;
  950. nand->ecc.strength = 8;
  951. }
  952. /*
  953. * Scan to find existence of the device
  954. */
  955. nand->dummy_controller.ops = &fsmc_nand_controller_ops;
  956. ret = nand_scan(nand, 1);
  957. if (ret)
  958. goto release_dma_write_chan;
  959. mtd->name = "nand";
  960. ret = mtd_device_register(mtd, NULL, 0);
  961. if (ret)
  962. goto cleanup_nand;
  963. platform_set_drvdata(pdev, host);
  964. dev_info(&pdev->dev, "FSMC NAND driver registration successful\n");
  965. return 0;
  966. cleanup_nand:
  967. nand_cleanup(nand);
  968. release_dma_write_chan:
  969. if (host->mode == USE_DMA_ACCESS)
  970. dma_release_channel(host->write_dma_chan);
  971. release_dma_read_chan:
  972. if (host->mode == USE_DMA_ACCESS)
  973. dma_release_channel(host->read_dma_chan);
  974. disable_clk:
  975. clk_disable_unprepare(host->clk);
  976. return ret;
  977. }
  978. /*
  979. * Clean up routine
  980. */
  981. static int fsmc_nand_remove(struct platform_device *pdev)
  982. {
  983. struct fsmc_nand_data *host = platform_get_drvdata(pdev);
  984. if (host) {
  985. nand_release(&host->nand);
  986. if (host->mode == USE_DMA_ACCESS) {
  987. dma_release_channel(host->write_dma_chan);
  988. dma_release_channel(host->read_dma_chan);
  989. }
  990. clk_disable_unprepare(host->clk);
  991. }
  992. return 0;
  993. }
  994. #ifdef CONFIG_PM_SLEEP
  995. static int fsmc_nand_suspend(struct device *dev)
  996. {
  997. struct fsmc_nand_data *host = dev_get_drvdata(dev);
  998. if (host)
  999. clk_disable_unprepare(host->clk);
  1000. return 0;
  1001. }
  1002. static int fsmc_nand_resume(struct device *dev)
  1003. {
  1004. struct fsmc_nand_data *host = dev_get_drvdata(dev);
  1005. if (host) {
  1006. clk_prepare_enable(host->clk);
  1007. if (host->dev_timings)
  1008. fsmc_nand_setup(host, host->dev_timings);
  1009. }
  1010. return 0;
  1011. }
  1012. #endif
  1013. static SIMPLE_DEV_PM_OPS(fsmc_nand_pm_ops, fsmc_nand_suspend, fsmc_nand_resume);
  1014. static const struct of_device_id fsmc_nand_id_table[] = {
  1015. { .compatible = "st,spear600-fsmc-nand" },
  1016. { .compatible = "stericsson,fsmc-nand" },
  1017. {}
  1018. };
  1019. MODULE_DEVICE_TABLE(of, fsmc_nand_id_table);
  1020. static struct platform_driver fsmc_nand_driver = {
  1021. .remove = fsmc_nand_remove,
  1022. .driver = {
  1023. .name = "fsmc-nand",
  1024. .of_match_table = fsmc_nand_id_table,
  1025. .pm = &fsmc_nand_pm_ops,
  1026. },
  1027. };
  1028. module_platform_driver_probe(fsmc_nand_driver, fsmc_nand_probe);
  1029. MODULE_LICENSE("GPL");
  1030. MODULE_AUTHOR("Vipin Kumar <vipin.kumar@st.com>, Ashish Priyadarshi");
  1031. MODULE_DESCRIPTION("NAND driver for SPEAr Platforms");