s3c2410.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright © 2004-2008 Simtec Electronics
  4. * http://armlinux.simtec.co.uk/
  5. * Ben Dooks <[email protected]>
  6. *
  7. * Samsung S3C2410/S3C2440/S3C2412 NAND driver
  8. */
  9. #define pr_fmt(fmt) "nand-s3c2410: " fmt
  10. #ifdef CONFIG_MTD_NAND_S3C2410_DEBUG
  11. #define DEBUG
  12. #endif
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/string.h>
  17. #include <linux/io.h>
  18. #include <linux/ioport.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/delay.h>
  21. #include <linux/err.h>
  22. #include <linux/slab.h>
  23. #include <linux/clk.h>
  24. #include <linux/cpufreq.h>
  25. #include <linux/of.h>
  26. #include <linux/of_device.h>
  27. #include <linux/mtd/mtd.h>
  28. #include <linux/mtd/rawnand.h>
  29. #include <linux/mtd/partitions.h>
  30. #include <linux/platform_data/mtd-nand-s3c2410.h>
  31. #define S3C2410_NFREG(x) (x)
  32. #define S3C2410_NFCONF S3C2410_NFREG(0x00)
  33. #define S3C2410_NFCMD S3C2410_NFREG(0x04)
  34. #define S3C2410_NFADDR S3C2410_NFREG(0x08)
  35. #define S3C2410_NFDATA S3C2410_NFREG(0x0C)
  36. #define S3C2410_NFSTAT S3C2410_NFREG(0x10)
  37. #define S3C2410_NFECC S3C2410_NFREG(0x14)
  38. #define S3C2440_NFCONT S3C2410_NFREG(0x04)
  39. #define S3C2440_NFCMD S3C2410_NFREG(0x08)
  40. #define S3C2440_NFADDR S3C2410_NFREG(0x0C)
  41. #define S3C2440_NFDATA S3C2410_NFREG(0x10)
  42. #define S3C2440_NFSTAT S3C2410_NFREG(0x20)
  43. #define S3C2440_NFMECC0 S3C2410_NFREG(0x2C)
  44. #define S3C2412_NFSTAT S3C2410_NFREG(0x28)
  45. #define S3C2412_NFMECC0 S3C2410_NFREG(0x34)
  46. #define S3C2410_NFCONF_EN (1<<15)
  47. #define S3C2410_NFCONF_INITECC (1<<12)
  48. #define S3C2410_NFCONF_nFCE (1<<11)
  49. #define S3C2410_NFCONF_TACLS(x) ((x)<<8)
  50. #define S3C2410_NFCONF_TWRPH0(x) ((x)<<4)
  51. #define S3C2410_NFCONF_TWRPH1(x) ((x)<<0)
  52. #define S3C2410_NFSTAT_BUSY (1<<0)
  53. #define S3C2440_NFCONF_TACLS(x) ((x)<<12)
  54. #define S3C2440_NFCONF_TWRPH0(x) ((x)<<8)
  55. #define S3C2440_NFCONF_TWRPH1(x) ((x)<<4)
  56. #define S3C2440_NFCONT_INITECC (1<<4)
  57. #define S3C2440_NFCONT_nFCE (1<<1)
  58. #define S3C2440_NFCONT_ENABLE (1<<0)
  59. #define S3C2440_NFSTAT_READY (1<<0)
  60. #define S3C2412_NFCONF_NANDBOOT (1<<31)
  61. #define S3C2412_NFCONT_INIT_MAIN_ECC (1<<5)
  62. #define S3C2412_NFCONT_nFCE0 (1<<1)
  63. #define S3C2412_NFSTAT_READY (1<<0)
  64. /* new oob placement block for use with hardware ecc generation
  65. */
  66. static int s3c2410_ooblayout_ecc(struct mtd_info *mtd, int section,
  67. struct mtd_oob_region *oobregion)
  68. {
  69. if (section)
  70. return -ERANGE;
  71. oobregion->offset = 0;
  72. oobregion->length = 3;
  73. return 0;
  74. }
  75. static int s3c2410_ooblayout_free(struct mtd_info *mtd, int section,
  76. struct mtd_oob_region *oobregion)
  77. {
  78. if (section)
  79. return -ERANGE;
  80. oobregion->offset = 8;
  81. oobregion->length = 8;
  82. return 0;
  83. }
  84. static const struct mtd_ooblayout_ops s3c2410_ooblayout_ops = {
  85. .ecc = s3c2410_ooblayout_ecc,
  86. .free = s3c2410_ooblayout_free,
  87. };
  88. /* controller and mtd information */
  89. struct s3c2410_nand_info;
  90. /**
  91. * struct s3c2410_nand_mtd - driver MTD structure
  92. * @mtd: The MTD instance to pass to the MTD layer.
  93. * @chip: The NAND chip information.
  94. * @set: The platform information supplied for this set of NAND chips.
  95. * @info: Link back to the hardware information.
  96. */
  97. struct s3c2410_nand_mtd {
  98. struct nand_chip chip;
  99. struct s3c2410_nand_set *set;
  100. struct s3c2410_nand_info *info;
  101. };
  102. enum s3c_cpu_type {
  103. TYPE_S3C2410,
  104. TYPE_S3C2412,
  105. TYPE_S3C2440,
  106. };
  107. enum s3c_nand_clk_state {
  108. CLOCK_DISABLE = 0,
  109. CLOCK_ENABLE,
  110. CLOCK_SUSPEND,
  111. };
  112. /* overview of the s3c2410 nand state */
  113. /**
  114. * struct s3c2410_nand_info - NAND controller state.
  115. * @controller: Base controller structure.
  116. * @mtds: An array of MTD instances on this controller.
  117. * @platform: The platform data for this board.
  118. * @device: The platform device we bound to.
  119. * @clk: The clock resource for this controller.
  120. * @regs: The area mapped for the hardware registers.
  121. * @sel_reg: Pointer to the register controlling the NAND selection.
  122. * @sel_bit: The bit in @sel_reg to select the NAND chip.
  123. * @mtd_count: The number of MTDs created from this controller.
  124. * @save_sel: The contents of @sel_reg to be saved over suspend.
  125. * @clk_rate: The clock rate from @clk.
  126. * @clk_state: The current clock state.
  127. * @cpu_type: The exact type of this controller.
  128. * @freq_transition: CPUFreq notifier block
  129. */
  130. struct s3c2410_nand_info {
  131. /* mtd info */
  132. struct nand_controller controller;
  133. struct s3c2410_nand_mtd *mtds;
  134. struct s3c2410_platform_nand *platform;
  135. /* device info */
  136. struct device *device;
  137. struct clk *clk;
  138. void __iomem *regs;
  139. void __iomem *sel_reg;
  140. int sel_bit;
  141. int mtd_count;
  142. unsigned long save_sel;
  143. unsigned long clk_rate;
  144. enum s3c_nand_clk_state clk_state;
  145. enum s3c_cpu_type cpu_type;
  146. #ifdef CONFIG_ARM_S3C24XX_CPUFREQ
  147. struct notifier_block freq_transition;
  148. #endif
  149. };
  150. struct s3c24XX_nand_devtype_data {
  151. enum s3c_cpu_type type;
  152. };
  153. static const struct s3c24XX_nand_devtype_data s3c2410_nand_devtype_data = {
  154. .type = TYPE_S3C2410,
  155. };
  156. static const struct s3c24XX_nand_devtype_data s3c2412_nand_devtype_data = {
  157. .type = TYPE_S3C2412,
  158. };
  159. static const struct s3c24XX_nand_devtype_data s3c2440_nand_devtype_data = {
  160. .type = TYPE_S3C2440,
  161. };
  162. /* conversion functions */
  163. static struct s3c2410_nand_mtd *s3c2410_nand_mtd_toours(struct mtd_info *mtd)
  164. {
  165. return container_of(mtd_to_nand(mtd), struct s3c2410_nand_mtd,
  166. chip);
  167. }
  168. static struct s3c2410_nand_info *s3c2410_nand_mtd_toinfo(struct mtd_info *mtd)
  169. {
  170. return s3c2410_nand_mtd_toours(mtd)->info;
  171. }
  172. static struct s3c2410_nand_info *to_nand_info(struct platform_device *dev)
  173. {
  174. return platform_get_drvdata(dev);
  175. }
  176. static struct s3c2410_platform_nand *to_nand_plat(struct platform_device *dev)
  177. {
  178. return dev_get_platdata(&dev->dev);
  179. }
  180. static inline int allow_clk_suspend(struct s3c2410_nand_info *info)
  181. {
  182. #ifdef CONFIG_MTD_NAND_S3C2410_CLKSTOP
  183. return 1;
  184. #else
  185. return 0;
  186. #endif
  187. }
  188. /**
  189. * s3c2410_nand_clk_set_state - Enable, disable or suspend NAND clock.
  190. * @info: The controller instance.
  191. * @new_state: State to which clock should be set.
  192. */
  193. static void s3c2410_nand_clk_set_state(struct s3c2410_nand_info *info,
  194. enum s3c_nand_clk_state new_state)
  195. {
  196. if (!allow_clk_suspend(info) && new_state == CLOCK_SUSPEND)
  197. return;
  198. if (info->clk_state == CLOCK_ENABLE) {
  199. if (new_state != CLOCK_ENABLE)
  200. clk_disable_unprepare(info->clk);
  201. } else {
  202. if (new_state == CLOCK_ENABLE)
  203. clk_prepare_enable(info->clk);
  204. }
  205. info->clk_state = new_state;
  206. }
  207. /* timing calculations */
  208. #define NS_IN_KHZ 1000000
  209. /**
  210. * s3c_nand_calc_rate - calculate timing data.
  211. * @wanted: The cycle time in nanoseconds.
  212. * @clk: The clock rate in kHz.
  213. * @max: The maximum divider value.
  214. *
  215. * Calculate the timing value from the given parameters.
  216. */
  217. static int s3c_nand_calc_rate(int wanted, unsigned long clk, int max)
  218. {
  219. int result;
  220. result = DIV_ROUND_UP((wanted * clk), NS_IN_KHZ);
  221. pr_debug("result %d from %ld, %d\n", result, clk, wanted);
  222. if (result > max) {
  223. pr_err("%d ns is too big for current clock rate %ld\n",
  224. wanted, clk);
  225. return -1;
  226. }
  227. if (result < 1)
  228. result = 1;
  229. return result;
  230. }
  231. #define to_ns(ticks, clk) (((ticks) * NS_IN_KHZ) / (unsigned int)(clk))
  232. /* controller setup */
  233. /**
  234. * s3c2410_nand_setrate - setup controller timing information.
  235. * @info: The controller instance.
  236. *
  237. * Given the information supplied by the platform, calculate and set
  238. * the necessary timing registers in the hardware to generate the
  239. * necessary timing cycles to the hardware.
  240. */
  241. static int s3c2410_nand_setrate(struct s3c2410_nand_info *info)
  242. {
  243. struct s3c2410_platform_nand *plat = info->platform;
  244. int tacls_max = (info->cpu_type == TYPE_S3C2412) ? 8 : 4;
  245. int tacls, twrph0, twrph1;
  246. unsigned long clkrate = clk_get_rate(info->clk);
  247. unsigned long set, cfg, mask;
  248. unsigned long flags;
  249. /* calculate the timing information for the controller */
  250. info->clk_rate = clkrate;
  251. clkrate /= 1000; /* turn clock into kHz for ease of use */
  252. if (plat != NULL) {
  253. tacls = s3c_nand_calc_rate(plat->tacls, clkrate, tacls_max);
  254. twrph0 = s3c_nand_calc_rate(plat->twrph0, clkrate, 8);
  255. twrph1 = s3c_nand_calc_rate(plat->twrph1, clkrate, 8);
  256. } else {
  257. /* default timings */
  258. tacls = tacls_max;
  259. twrph0 = 8;
  260. twrph1 = 8;
  261. }
  262. if (tacls < 0 || twrph0 < 0 || twrph1 < 0) {
  263. dev_err(info->device, "cannot get suitable timings\n");
  264. return -EINVAL;
  265. }
  266. dev_info(info->device, "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n",
  267. tacls, to_ns(tacls, clkrate), twrph0, to_ns(twrph0, clkrate),
  268. twrph1, to_ns(twrph1, clkrate));
  269. switch (info->cpu_type) {
  270. case TYPE_S3C2410:
  271. mask = (S3C2410_NFCONF_TACLS(3) |
  272. S3C2410_NFCONF_TWRPH0(7) |
  273. S3C2410_NFCONF_TWRPH1(7));
  274. set = S3C2410_NFCONF_EN;
  275. set |= S3C2410_NFCONF_TACLS(tacls - 1);
  276. set |= S3C2410_NFCONF_TWRPH0(twrph0 - 1);
  277. set |= S3C2410_NFCONF_TWRPH1(twrph1 - 1);
  278. break;
  279. case TYPE_S3C2440:
  280. case TYPE_S3C2412:
  281. mask = (S3C2440_NFCONF_TACLS(tacls_max - 1) |
  282. S3C2440_NFCONF_TWRPH0(7) |
  283. S3C2440_NFCONF_TWRPH1(7));
  284. set = S3C2440_NFCONF_TACLS(tacls - 1);
  285. set |= S3C2440_NFCONF_TWRPH0(twrph0 - 1);
  286. set |= S3C2440_NFCONF_TWRPH1(twrph1 - 1);
  287. break;
  288. default:
  289. BUG();
  290. }
  291. local_irq_save(flags);
  292. cfg = readl(info->regs + S3C2410_NFCONF);
  293. cfg &= ~mask;
  294. cfg |= set;
  295. writel(cfg, info->regs + S3C2410_NFCONF);
  296. local_irq_restore(flags);
  297. dev_dbg(info->device, "NF_CONF is 0x%lx\n", cfg);
  298. return 0;
  299. }
  300. /**
  301. * s3c2410_nand_inithw - basic hardware initialisation
  302. * @info: The hardware state.
  303. *
  304. * Do the basic initialisation of the hardware, using s3c2410_nand_setrate()
  305. * to setup the hardware access speeds and set the controller to be enabled.
  306. */
  307. static int s3c2410_nand_inithw(struct s3c2410_nand_info *info)
  308. {
  309. int ret;
  310. ret = s3c2410_nand_setrate(info);
  311. if (ret < 0)
  312. return ret;
  313. switch (info->cpu_type) {
  314. case TYPE_S3C2410:
  315. default:
  316. break;
  317. case TYPE_S3C2440:
  318. case TYPE_S3C2412:
  319. /* enable the controller and de-assert nFCE */
  320. writel(S3C2440_NFCONT_ENABLE, info->regs + S3C2440_NFCONT);
  321. }
  322. return 0;
  323. }
  324. /**
  325. * s3c2410_nand_select_chip - select the given nand chip
  326. * @this: NAND chip object.
  327. * @chip: The chip number.
  328. *
  329. * This is called by the MTD layer to either select a given chip for the
  330. * @mtd instance, or to indicate that the access has finished and the
  331. * chip can be de-selected.
  332. *
  333. * The routine ensures that the nFCE line is correctly setup, and any
  334. * platform specific selection code is called to route nFCE to the specific
  335. * chip.
  336. */
  337. static void s3c2410_nand_select_chip(struct nand_chip *this, int chip)
  338. {
  339. struct s3c2410_nand_info *info;
  340. struct s3c2410_nand_mtd *nmtd;
  341. unsigned long cur;
  342. nmtd = nand_get_controller_data(this);
  343. info = nmtd->info;
  344. if (chip != -1)
  345. s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
  346. cur = readl(info->sel_reg);
  347. if (chip == -1) {
  348. cur |= info->sel_bit;
  349. } else {
  350. if (nmtd->set != NULL && chip > nmtd->set->nr_chips) {
  351. dev_err(info->device, "invalid chip %d\n", chip);
  352. return;
  353. }
  354. if (info->platform != NULL) {
  355. if (info->platform->select_chip != NULL)
  356. (info->platform->select_chip) (nmtd->set, chip);
  357. }
  358. cur &= ~info->sel_bit;
  359. }
  360. writel(cur, info->sel_reg);
  361. if (chip == -1)
  362. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  363. }
  364. /* s3c2410_nand_hwcontrol
  365. *
  366. * Issue command and address cycles to the chip
  367. */
  368. static void s3c2410_nand_hwcontrol(struct nand_chip *chip, int cmd,
  369. unsigned int ctrl)
  370. {
  371. struct mtd_info *mtd = nand_to_mtd(chip);
  372. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  373. if (cmd == NAND_CMD_NONE)
  374. return;
  375. if (ctrl & NAND_CLE)
  376. writeb(cmd, info->regs + S3C2410_NFCMD);
  377. else
  378. writeb(cmd, info->regs + S3C2410_NFADDR);
  379. }
  380. /* command and control functions */
  381. static void s3c2440_nand_hwcontrol(struct nand_chip *chip, int cmd,
  382. unsigned int ctrl)
  383. {
  384. struct mtd_info *mtd = nand_to_mtd(chip);
  385. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  386. if (cmd == NAND_CMD_NONE)
  387. return;
  388. if (ctrl & NAND_CLE)
  389. writeb(cmd, info->regs + S3C2440_NFCMD);
  390. else
  391. writeb(cmd, info->regs + S3C2440_NFADDR);
  392. }
  393. /* s3c2410_nand_devready()
  394. *
  395. * returns 0 if the nand is busy, 1 if it is ready
  396. */
  397. static int s3c2410_nand_devready(struct nand_chip *chip)
  398. {
  399. struct mtd_info *mtd = nand_to_mtd(chip);
  400. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  401. return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
  402. }
  403. static int s3c2440_nand_devready(struct nand_chip *chip)
  404. {
  405. struct mtd_info *mtd = nand_to_mtd(chip);
  406. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  407. return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY;
  408. }
  409. static int s3c2412_nand_devready(struct nand_chip *chip)
  410. {
  411. struct mtd_info *mtd = nand_to_mtd(chip);
  412. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  413. return readb(info->regs + S3C2412_NFSTAT) & S3C2412_NFSTAT_READY;
  414. }
  415. /* ECC handling functions */
  416. static int s3c2410_nand_correct_data(struct nand_chip *chip, u_char *dat,
  417. u_char *read_ecc, u_char *calc_ecc)
  418. {
  419. struct mtd_info *mtd = nand_to_mtd(chip);
  420. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  421. unsigned int diff0, diff1, diff2;
  422. unsigned int bit, byte;
  423. pr_debug("%s(%p,%p,%p,%p)\n", __func__, mtd, dat, read_ecc, calc_ecc);
  424. diff0 = read_ecc[0] ^ calc_ecc[0];
  425. diff1 = read_ecc[1] ^ calc_ecc[1];
  426. diff2 = read_ecc[2] ^ calc_ecc[2];
  427. pr_debug("%s: rd %*phN calc %*phN diff %02x%02x%02x\n",
  428. __func__, 3, read_ecc, 3, calc_ecc,
  429. diff0, diff1, diff2);
  430. if (diff0 == 0 && diff1 == 0 && diff2 == 0)
  431. return 0; /* ECC is ok */
  432. /* sometimes people do not think about using the ECC, so check
  433. * to see if we have an 0xff,0xff,0xff read ECC and then ignore
  434. * the error, on the assumption that this is an un-eccd page.
  435. */
  436. if (read_ecc[0] == 0xff && read_ecc[1] == 0xff && read_ecc[2] == 0xff
  437. && info->platform->ignore_unset_ecc)
  438. return 0;
  439. /* Can we correct this ECC (ie, one row and column change).
  440. * Note, this is similar to the 256 error code on smartmedia */
  441. if (((diff0 ^ (diff0 >> 1)) & 0x55) == 0x55 &&
  442. ((diff1 ^ (diff1 >> 1)) & 0x55) == 0x55 &&
  443. ((diff2 ^ (diff2 >> 1)) & 0x55) == 0x55) {
  444. /* calculate the bit position of the error */
  445. bit = ((diff2 >> 3) & 1) |
  446. ((diff2 >> 4) & 2) |
  447. ((diff2 >> 5) & 4);
  448. /* calculate the byte position of the error */
  449. byte = ((diff2 << 7) & 0x100) |
  450. ((diff1 << 0) & 0x80) |
  451. ((diff1 << 1) & 0x40) |
  452. ((diff1 << 2) & 0x20) |
  453. ((diff1 << 3) & 0x10) |
  454. ((diff0 >> 4) & 0x08) |
  455. ((diff0 >> 3) & 0x04) |
  456. ((diff0 >> 2) & 0x02) |
  457. ((diff0 >> 1) & 0x01);
  458. dev_dbg(info->device, "correcting error bit %d, byte %d\n",
  459. bit, byte);
  460. dat[byte] ^= (1 << bit);
  461. return 1;
  462. }
  463. /* if there is only one bit difference in the ECC, then
  464. * one of only a row or column parity has changed, which
  465. * means the error is most probably in the ECC itself */
  466. diff0 |= (diff1 << 8);
  467. diff0 |= (diff2 << 16);
  468. /* equal to "(diff0 & ~(1 << __ffs(diff0)))" */
  469. if ((diff0 & (diff0 - 1)) == 0)
  470. return 1;
  471. return -1;
  472. }
  473. /* ECC functions
  474. *
  475. * These allow the s3c2410 and s3c2440 to use the controller's ECC
  476. * generator block to ECC the data as it passes through]
  477. */
  478. static void s3c2410_nand_enable_hwecc(struct nand_chip *chip, int mode)
  479. {
  480. struct s3c2410_nand_info *info;
  481. unsigned long ctrl;
  482. info = s3c2410_nand_mtd_toinfo(nand_to_mtd(chip));
  483. ctrl = readl(info->regs + S3C2410_NFCONF);
  484. ctrl |= S3C2410_NFCONF_INITECC;
  485. writel(ctrl, info->regs + S3C2410_NFCONF);
  486. }
  487. static void s3c2412_nand_enable_hwecc(struct nand_chip *chip, int mode)
  488. {
  489. struct s3c2410_nand_info *info;
  490. unsigned long ctrl;
  491. info = s3c2410_nand_mtd_toinfo(nand_to_mtd(chip));
  492. ctrl = readl(info->regs + S3C2440_NFCONT);
  493. writel(ctrl | S3C2412_NFCONT_INIT_MAIN_ECC,
  494. info->regs + S3C2440_NFCONT);
  495. }
  496. static void s3c2440_nand_enable_hwecc(struct nand_chip *chip, int mode)
  497. {
  498. struct s3c2410_nand_info *info;
  499. unsigned long ctrl;
  500. info = s3c2410_nand_mtd_toinfo(nand_to_mtd(chip));
  501. ctrl = readl(info->regs + S3C2440_NFCONT);
  502. writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT);
  503. }
  504. static int s3c2410_nand_calculate_ecc(struct nand_chip *chip,
  505. const u_char *dat, u_char *ecc_code)
  506. {
  507. struct mtd_info *mtd = nand_to_mtd(chip);
  508. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  509. ecc_code[0] = readb(info->regs + S3C2410_NFECC + 0);
  510. ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1);
  511. ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2);
  512. pr_debug("%s: returning ecc %*phN\n", __func__, 3, ecc_code);
  513. return 0;
  514. }
  515. static int s3c2412_nand_calculate_ecc(struct nand_chip *chip,
  516. const u_char *dat, u_char *ecc_code)
  517. {
  518. struct mtd_info *mtd = nand_to_mtd(chip);
  519. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  520. unsigned long ecc = readl(info->regs + S3C2412_NFMECC0);
  521. ecc_code[0] = ecc;
  522. ecc_code[1] = ecc >> 8;
  523. ecc_code[2] = ecc >> 16;
  524. pr_debug("%s: returning ecc %*phN\n", __func__, 3, ecc_code);
  525. return 0;
  526. }
  527. static int s3c2440_nand_calculate_ecc(struct nand_chip *chip,
  528. const u_char *dat, u_char *ecc_code)
  529. {
  530. struct mtd_info *mtd = nand_to_mtd(chip);
  531. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  532. unsigned long ecc = readl(info->regs + S3C2440_NFMECC0);
  533. ecc_code[0] = ecc;
  534. ecc_code[1] = ecc >> 8;
  535. ecc_code[2] = ecc >> 16;
  536. pr_debug("%s: returning ecc %06lx\n", __func__, ecc & 0xffffff);
  537. return 0;
  538. }
  539. /* over-ride the standard functions for a little more speed. We can
  540. * use read/write block to move the data buffers to/from the controller
  541. */
  542. static void s3c2410_nand_read_buf(struct nand_chip *this, u_char *buf, int len)
  543. {
  544. readsb(this->legacy.IO_ADDR_R, buf, len);
  545. }
  546. static void s3c2440_nand_read_buf(struct nand_chip *this, u_char *buf, int len)
  547. {
  548. struct mtd_info *mtd = nand_to_mtd(this);
  549. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  550. readsl(info->regs + S3C2440_NFDATA, buf, len >> 2);
  551. /* cleanup if we've got less than a word to do */
  552. if (len & 3) {
  553. buf += len & ~3;
  554. for (; len & 3; len--)
  555. *buf++ = readb(info->regs + S3C2440_NFDATA);
  556. }
  557. }
  558. static void s3c2410_nand_write_buf(struct nand_chip *this, const u_char *buf,
  559. int len)
  560. {
  561. writesb(this->legacy.IO_ADDR_W, buf, len);
  562. }
  563. static void s3c2440_nand_write_buf(struct nand_chip *this, const u_char *buf,
  564. int len)
  565. {
  566. struct mtd_info *mtd = nand_to_mtd(this);
  567. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  568. writesl(info->regs + S3C2440_NFDATA, buf, len >> 2);
  569. /* cleanup any fractional write */
  570. if (len & 3) {
  571. buf += len & ~3;
  572. for (; len & 3; len--, buf++)
  573. writeb(*buf, info->regs + S3C2440_NFDATA);
  574. }
  575. }
  576. /* cpufreq driver support */
  577. #ifdef CONFIG_ARM_S3C24XX_CPUFREQ
  578. static int s3c2410_nand_cpufreq_transition(struct notifier_block *nb,
  579. unsigned long val, void *data)
  580. {
  581. struct s3c2410_nand_info *info;
  582. unsigned long newclk;
  583. info = container_of(nb, struct s3c2410_nand_info, freq_transition);
  584. newclk = clk_get_rate(info->clk);
  585. if ((val == CPUFREQ_POSTCHANGE && newclk < info->clk_rate) ||
  586. (val == CPUFREQ_PRECHANGE && newclk > info->clk_rate)) {
  587. s3c2410_nand_setrate(info);
  588. }
  589. return 0;
  590. }
  591. static inline int s3c2410_nand_cpufreq_register(struct s3c2410_nand_info *info)
  592. {
  593. info->freq_transition.notifier_call = s3c2410_nand_cpufreq_transition;
  594. return cpufreq_register_notifier(&info->freq_transition,
  595. CPUFREQ_TRANSITION_NOTIFIER);
  596. }
  597. static inline void
  598. s3c2410_nand_cpufreq_deregister(struct s3c2410_nand_info *info)
  599. {
  600. cpufreq_unregister_notifier(&info->freq_transition,
  601. CPUFREQ_TRANSITION_NOTIFIER);
  602. }
  603. #else
  604. static inline int s3c2410_nand_cpufreq_register(struct s3c2410_nand_info *info)
  605. {
  606. return 0;
  607. }
  608. static inline void
  609. s3c2410_nand_cpufreq_deregister(struct s3c2410_nand_info *info)
  610. {
  611. }
  612. #endif
  613. /* device management functions */
  614. static int s3c24xx_nand_remove(struct platform_device *pdev)
  615. {
  616. struct s3c2410_nand_info *info = to_nand_info(pdev);
  617. if (info == NULL)
  618. return 0;
  619. s3c2410_nand_cpufreq_deregister(info);
  620. /* Release all our mtds and their partitions, then go through
  621. * freeing the resources used
  622. */
  623. if (info->mtds != NULL) {
  624. struct s3c2410_nand_mtd *ptr = info->mtds;
  625. int mtdno;
  626. for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) {
  627. pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
  628. WARN_ON(mtd_device_unregister(nand_to_mtd(&ptr->chip)));
  629. nand_cleanup(&ptr->chip);
  630. }
  631. }
  632. /* free the common resources */
  633. if (!IS_ERR(info->clk))
  634. s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
  635. return 0;
  636. }
  637. static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
  638. struct s3c2410_nand_mtd *mtd,
  639. struct s3c2410_nand_set *set)
  640. {
  641. if (set) {
  642. struct mtd_info *mtdinfo = nand_to_mtd(&mtd->chip);
  643. mtdinfo->name = set->name;
  644. return mtd_device_register(mtdinfo, set->partitions,
  645. set->nr_partitions);
  646. }
  647. return -ENODEV;
  648. }
  649. static int s3c2410_nand_setup_interface(struct nand_chip *chip, int csline,
  650. const struct nand_interface_config *conf)
  651. {
  652. struct mtd_info *mtd = nand_to_mtd(chip);
  653. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  654. struct s3c2410_platform_nand *pdata = info->platform;
  655. const struct nand_sdr_timings *timings;
  656. int tacls;
  657. timings = nand_get_sdr_timings(conf);
  658. if (IS_ERR(timings))
  659. return -ENOTSUPP;
  660. tacls = timings->tCLS_min - timings->tWP_min;
  661. if (tacls < 0)
  662. tacls = 0;
  663. pdata->tacls = DIV_ROUND_UP(tacls, 1000);
  664. pdata->twrph0 = DIV_ROUND_UP(timings->tWP_min, 1000);
  665. pdata->twrph1 = DIV_ROUND_UP(timings->tCLH_min, 1000);
  666. return s3c2410_nand_setrate(info);
  667. }
  668. /**
  669. * s3c2410_nand_init_chip - initialise a single instance of an chip
  670. * @info: The base NAND controller the chip is on.
  671. * @nmtd: The new controller MTD instance to fill in.
  672. * @set: The information passed from the board specific platform data.
  673. *
  674. * Initialise the given @nmtd from the information in @info and @set. This
  675. * readies the structure for use with the MTD layer functions by ensuring
  676. * all pointers are setup and the necessary control routines selected.
  677. */
  678. static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
  679. struct s3c2410_nand_mtd *nmtd,
  680. struct s3c2410_nand_set *set)
  681. {
  682. struct device_node *np = info->device->of_node;
  683. struct nand_chip *chip = &nmtd->chip;
  684. void __iomem *regs = info->regs;
  685. nand_set_flash_node(chip, set->of_node);
  686. chip->legacy.write_buf = s3c2410_nand_write_buf;
  687. chip->legacy.read_buf = s3c2410_nand_read_buf;
  688. chip->legacy.select_chip = s3c2410_nand_select_chip;
  689. chip->legacy.chip_delay = 50;
  690. nand_set_controller_data(chip, nmtd);
  691. chip->options = set->options;
  692. chip->controller = &info->controller;
  693. /*
  694. * let's keep behavior unchanged for legacy boards booting via pdata and
  695. * auto-detect timings only when booting with a device tree.
  696. */
  697. if (!np)
  698. chip->options |= NAND_KEEP_TIMINGS;
  699. switch (info->cpu_type) {
  700. case TYPE_S3C2410:
  701. chip->legacy.IO_ADDR_W = regs + S3C2410_NFDATA;
  702. info->sel_reg = regs + S3C2410_NFCONF;
  703. info->sel_bit = S3C2410_NFCONF_nFCE;
  704. chip->legacy.cmd_ctrl = s3c2410_nand_hwcontrol;
  705. chip->legacy.dev_ready = s3c2410_nand_devready;
  706. break;
  707. case TYPE_S3C2440:
  708. chip->legacy.IO_ADDR_W = regs + S3C2440_NFDATA;
  709. info->sel_reg = regs + S3C2440_NFCONT;
  710. info->sel_bit = S3C2440_NFCONT_nFCE;
  711. chip->legacy.cmd_ctrl = s3c2440_nand_hwcontrol;
  712. chip->legacy.dev_ready = s3c2440_nand_devready;
  713. chip->legacy.read_buf = s3c2440_nand_read_buf;
  714. chip->legacy.write_buf = s3c2440_nand_write_buf;
  715. break;
  716. case TYPE_S3C2412:
  717. chip->legacy.IO_ADDR_W = regs + S3C2440_NFDATA;
  718. info->sel_reg = regs + S3C2440_NFCONT;
  719. info->sel_bit = S3C2412_NFCONT_nFCE0;
  720. chip->legacy.cmd_ctrl = s3c2440_nand_hwcontrol;
  721. chip->legacy.dev_ready = s3c2412_nand_devready;
  722. if (readl(regs + S3C2410_NFCONF) & S3C2412_NFCONF_NANDBOOT)
  723. dev_info(info->device, "System booted from NAND\n");
  724. break;
  725. }
  726. chip->legacy.IO_ADDR_R = chip->legacy.IO_ADDR_W;
  727. nmtd->info = info;
  728. nmtd->set = set;
  729. chip->ecc.engine_type = info->platform->engine_type;
  730. /*
  731. * If you use u-boot BBT creation code, specifying this flag will
  732. * let the kernel fish out the BBT from the NAND.
  733. */
  734. if (set->flash_bbt)
  735. chip->bbt_options |= NAND_BBT_USE_FLASH;
  736. }
  737. /**
  738. * s3c2410_nand_attach_chip - Init the ECC engine after NAND scan
  739. * @chip: The NAND chip
  740. *
  741. * This hook is called by the core after the identification of the NAND chip,
  742. * once the relevant per-chip information is up to date.. This call ensure that
  743. * we update the internal state accordingly.
  744. *
  745. * The internal state is currently limited to the ECC state information.
  746. */
  747. static int s3c2410_nand_attach_chip(struct nand_chip *chip)
  748. {
  749. struct mtd_info *mtd = nand_to_mtd(chip);
  750. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  751. switch (chip->ecc.engine_type) {
  752. case NAND_ECC_ENGINE_TYPE_NONE:
  753. dev_info(info->device, "ECC disabled\n");
  754. break;
  755. case NAND_ECC_ENGINE_TYPE_SOFT:
  756. /*
  757. * This driver expects Hamming based ECC when engine_type is set
  758. * to NAND_ECC_ENGINE_TYPE_SOFT. Force ecc.algo to
  759. * NAND_ECC_ALGO_HAMMING to avoid adding an extra ecc_algo field
  760. * to s3c2410_platform_nand.
  761. */
  762. chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
  763. dev_info(info->device, "soft ECC\n");
  764. break;
  765. case NAND_ECC_ENGINE_TYPE_ON_HOST:
  766. chip->ecc.calculate = s3c2410_nand_calculate_ecc;
  767. chip->ecc.correct = s3c2410_nand_correct_data;
  768. chip->ecc.strength = 1;
  769. switch (info->cpu_type) {
  770. case TYPE_S3C2410:
  771. chip->ecc.hwctl = s3c2410_nand_enable_hwecc;
  772. chip->ecc.calculate = s3c2410_nand_calculate_ecc;
  773. break;
  774. case TYPE_S3C2412:
  775. chip->ecc.hwctl = s3c2412_nand_enable_hwecc;
  776. chip->ecc.calculate = s3c2412_nand_calculate_ecc;
  777. break;
  778. case TYPE_S3C2440:
  779. chip->ecc.hwctl = s3c2440_nand_enable_hwecc;
  780. chip->ecc.calculate = s3c2440_nand_calculate_ecc;
  781. break;
  782. }
  783. dev_dbg(info->device, "chip %p => page shift %d\n",
  784. chip, chip->page_shift);
  785. /* change the behaviour depending on whether we are using
  786. * the large or small page nand device */
  787. if (chip->page_shift > 10) {
  788. chip->ecc.size = 256;
  789. chip->ecc.bytes = 3;
  790. } else {
  791. chip->ecc.size = 512;
  792. chip->ecc.bytes = 3;
  793. mtd_set_ooblayout(nand_to_mtd(chip),
  794. &s3c2410_ooblayout_ops);
  795. }
  796. dev_info(info->device, "hardware ECC\n");
  797. break;
  798. default:
  799. dev_err(info->device, "invalid ECC mode!\n");
  800. return -EINVAL;
  801. }
  802. if (chip->bbt_options & NAND_BBT_USE_FLASH)
  803. chip->options |= NAND_SKIP_BBTSCAN;
  804. return 0;
  805. }
  806. static const struct nand_controller_ops s3c24xx_nand_controller_ops = {
  807. .attach_chip = s3c2410_nand_attach_chip,
  808. .setup_interface = s3c2410_nand_setup_interface,
  809. };
  810. static const struct of_device_id s3c24xx_nand_dt_ids[] = {
  811. {
  812. .compatible = "samsung,s3c2410-nand",
  813. .data = &s3c2410_nand_devtype_data,
  814. }, {
  815. /* also compatible with s3c6400 */
  816. .compatible = "samsung,s3c2412-nand",
  817. .data = &s3c2412_nand_devtype_data,
  818. }, {
  819. .compatible = "samsung,s3c2440-nand",
  820. .data = &s3c2440_nand_devtype_data,
  821. },
  822. { /* sentinel */ }
  823. };
  824. MODULE_DEVICE_TABLE(of, s3c24xx_nand_dt_ids);
  825. static int s3c24xx_nand_probe_dt(struct platform_device *pdev)
  826. {
  827. const struct s3c24XX_nand_devtype_data *devtype_data;
  828. struct s3c2410_platform_nand *pdata;
  829. struct s3c2410_nand_info *info = platform_get_drvdata(pdev);
  830. struct device_node *np = pdev->dev.of_node, *child;
  831. struct s3c2410_nand_set *sets;
  832. devtype_data = of_device_get_match_data(&pdev->dev);
  833. if (!devtype_data)
  834. return -ENODEV;
  835. info->cpu_type = devtype_data->type;
  836. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  837. if (!pdata)
  838. return -ENOMEM;
  839. pdev->dev.platform_data = pdata;
  840. pdata->nr_sets = of_get_child_count(np);
  841. if (!pdata->nr_sets)
  842. return 0;
  843. sets = devm_kcalloc(&pdev->dev, pdata->nr_sets, sizeof(*sets),
  844. GFP_KERNEL);
  845. if (!sets)
  846. return -ENOMEM;
  847. pdata->sets = sets;
  848. for_each_available_child_of_node(np, child) {
  849. sets->name = (char *)child->name;
  850. sets->of_node = child;
  851. sets->nr_chips = 1;
  852. of_node_get(child);
  853. sets++;
  854. }
  855. return 0;
  856. }
  857. static int s3c24xx_nand_probe_pdata(struct platform_device *pdev)
  858. {
  859. struct s3c2410_nand_info *info = platform_get_drvdata(pdev);
  860. info->cpu_type = platform_get_device_id(pdev)->driver_data;
  861. return 0;
  862. }
  863. /* s3c24xx_nand_probe
  864. *
  865. * called by device layer when it finds a device matching
  866. * one our driver can handled. This code checks to see if
  867. * it can allocate all necessary resources then calls the
  868. * nand layer to look for devices
  869. */
  870. static int s3c24xx_nand_probe(struct platform_device *pdev)
  871. {
  872. struct s3c2410_platform_nand *plat;
  873. struct s3c2410_nand_info *info;
  874. struct s3c2410_nand_mtd *nmtd;
  875. struct s3c2410_nand_set *sets;
  876. struct resource *res;
  877. int err = 0;
  878. int size;
  879. int nr_sets;
  880. int setno;
  881. info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
  882. if (info == NULL) {
  883. err = -ENOMEM;
  884. goto exit_error;
  885. }
  886. platform_set_drvdata(pdev, info);
  887. nand_controller_init(&info->controller);
  888. info->controller.ops = &s3c24xx_nand_controller_ops;
  889. /* get the clock source and enable it */
  890. info->clk = devm_clk_get(&pdev->dev, "nand");
  891. if (IS_ERR(info->clk)) {
  892. dev_err(&pdev->dev, "failed to get clock\n");
  893. err = -ENOENT;
  894. goto exit_error;
  895. }
  896. s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
  897. if (pdev->dev.of_node)
  898. err = s3c24xx_nand_probe_dt(pdev);
  899. else
  900. err = s3c24xx_nand_probe_pdata(pdev);
  901. if (err)
  902. goto exit_error;
  903. plat = to_nand_plat(pdev);
  904. /* allocate and map the resource */
  905. /* currently we assume we have the one resource */
  906. res = pdev->resource;
  907. size = resource_size(res);
  908. info->device = &pdev->dev;
  909. info->platform = plat;
  910. info->regs = devm_ioremap_resource(&pdev->dev, res);
  911. if (IS_ERR(info->regs)) {
  912. err = PTR_ERR(info->regs);
  913. goto exit_error;
  914. }
  915. dev_dbg(&pdev->dev, "mapped registers at %p\n", info->regs);
  916. if (!plat->sets || plat->nr_sets < 1) {
  917. err = -EINVAL;
  918. goto exit_error;
  919. }
  920. sets = plat->sets;
  921. nr_sets = plat->nr_sets;
  922. info->mtd_count = nr_sets;
  923. /* allocate our information */
  924. size = nr_sets * sizeof(*info->mtds);
  925. info->mtds = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
  926. if (info->mtds == NULL) {
  927. err = -ENOMEM;
  928. goto exit_error;
  929. }
  930. /* initialise all possible chips */
  931. nmtd = info->mtds;
  932. for (setno = 0; setno < nr_sets; setno++, nmtd++, sets++) {
  933. struct mtd_info *mtd = nand_to_mtd(&nmtd->chip);
  934. pr_debug("initialising set %d (%p, info %p)\n",
  935. setno, nmtd, info);
  936. mtd->dev.parent = &pdev->dev;
  937. s3c2410_nand_init_chip(info, nmtd, sets);
  938. err = nand_scan(&nmtd->chip, sets ? sets->nr_chips : 1);
  939. if (err)
  940. goto exit_error;
  941. s3c2410_nand_add_partition(info, nmtd, sets);
  942. }
  943. /* initialise the hardware */
  944. err = s3c2410_nand_inithw(info);
  945. if (err != 0)
  946. goto exit_error;
  947. err = s3c2410_nand_cpufreq_register(info);
  948. if (err < 0) {
  949. dev_err(&pdev->dev, "failed to init cpufreq support\n");
  950. goto exit_error;
  951. }
  952. if (allow_clk_suspend(info)) {
  953. dev_info(&pdev->dev, "clock idle support enabled\n");
  954. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  955. }
  956. return 0;
  957. exit_error:
  958. s3c24xx_nand_remove(pdev);
  959. if (err == 0)
  960. err = -EINVAL;
  961. return err;
  962. }
  963. /* PM Support */
  964. #ifdef CONFIG_PM
  965. static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
  966. {
  967. struct s3c2410_nand_info *info = platform_get_drvdata(dev);
  968. if (info) {
  969. info->save_sel = readl(info->sel_reg);
  970. /* For the moment, we must ensure nFCE is high during
  971. * the time we are suspended. This really should be
  972. * handled by suspending the MTDs we are using, but
  973. * that is currently not the case. */
  974. writel(info->save_sel | info->sel_bit, info->sel_reg);
  975. s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
  976. }
  977. return 0;
  978. }
  979. static int s3c24xx_nand_resume(struct platform_device *dev)
  980. {
  981. struct s3c2410_nand_info *info = platform_get_drvdata(dev);
  982. unsigned long sel;
  983. if (info) {
  984. s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
  985. s3c2410_nand_inithw(info);
  986. /* Restore the state of the nFCE line. */
  987. sel = readl(info->sel_reg);
  988. sel &= ~info->sel_bit;
  989. sel |= info->save_sel & info->sel_bit;
  990. writel(sel, info->sel_reg);
  991. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  992. }
  993. return 0;
  994. }
  995. #else
  996. #define s3c24xx_nand_suspend NULL
  997. #define s3c24xx_nand_resume NULL
  998. #endif
  999. /* driver device registration */
  1000. static const struct platform_device_id s3c24xx_driver_ids[] = {
  1001. {
  1002. .name = "s3c2410-nand",
  1003. .driver_data = TYPE_S3C2410,
  1004. }, {
  1005. .name = "s3c2440-nand",
  1006. .driver_data = TYPE_S3C2440,
  1007. }, {
  1008. .name = "s3c2412-nand",
  1009. .driver_data = TYPE_S3C2412,
  1010. }, {
  1011. .name = "s3c6400-nand",
  1012. .driver_data = TYPE_S3C2412, /* compatible with 2412 */
  1013. },
  1014. { }
  1015. };
  1016. MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
  1017. static struct platform_driver s3c24xx_nand_driver = {
  1018. .probe = s3c24xx_nand_probe,
  1019. .remove = s3c24xx_nand_remove,
  1020. .suspend = s3c24xx_nand_suspend,
  1021. .resume = s3c24xx_nand_resume,
  1022. .id_table = s3c24xx_driver_ids,
  1023. .driver = {
  1024. .name = "s3c24xx-nand",
  1025. .of_match_table = s3c24xx_nand_dt_ids,
  1026. },
  1027. };
  1028. module_platform_driver(s3c24xx_nand_driver);
  1029. MODULE_LICENSE("GPL");
  1030. MODULE_AUTHOR("Ben Dooks <[email protected]>");
  1031. MODULE_DESCRIPTION("S3C24XX MTD NAND driver");