s3c2410.c 33 KB

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