s3c2410.c 32 KB

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