s3c2410.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  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. * @mtd: The MTD instance for this chip.
  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 mtd_info *mtd, int chip)
  350. {
  351. struct s3c2410_nand_info *info;
  352. struct s3c2410_nand_mtd *nmtd;
  353. struct nand_chip *this = mtd_to_nand(mtd);
  354. unsigned long cur;
  355. nmtd = nand_get_controller_data(this);
  356. info = nmtd->info;
  357. if (chip != -1)
  358. s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
  359. cur = readl(info->sel_reg);
  360. if (chip == -1) {
  361. cur |= info->sel_bit;
  362. } else {
  363. if (nmtd->set != NULL && chip > nmtd->set->nr_chips) {
  364. dev_err(info->device, "invalid chip %d\n", chip);
  365. return;
  366. }
  367. if (info->platform != NULL) {
  368. if (info->platform->select_chip != NULL)
  369. (info->platform->select_chip) (nmtd->set, chip);
  370. }
  371. cur &= ~info->sel_bit;
  372. }
  373. writel(cur, info->sel_reg);
  374. if (chip == -1)
  375. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  376. }
  377. /* s3c2410_nand_hwcontrol
  378. *
  379. * Issue command and address cycles to the chip
  380. */
  381. static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd,
  382. unsigned int ctrl)
  383. {
  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 mtd_info *mtd, int cmd,
  394. unsigned int ctrl)
  395. {
  396. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  397. if (cmd == NAND_CMD_NONE)
  398. return;
  399. if (ctrl & NAND_CLE)
  400. writeb(cmd, info->regs + S3C2440_NFCMD);
  401. else
  402. writeb(cmd, info->regs + S3C2440_NFADDR);
  403. }
  404. /* s3c2410_nand_devready()
  405. *
  406. * returns 0 if the nand is busy, 1 if it is ready
  407. */
  408. static int s3c2410_nand_devready(struct mtd_info *mtd)
  409. {
  410. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  411. return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
  412. }
  413. static int s3c2440_nand_devready(struct mtd_info *mtd)
  414. {
  415. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  416. return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY;
  417. }
  418. static int s3c2412_nand_devready(struct mtd_info *mtd)
  419. {
  420. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  421. return readb(info->regs + S3C2412_NFSTAT) & S3C2412_NFSTAT_READY;
  422. }
  423. /* ECC handling functions */
  424. static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
  425. u_char *read_ecc, u_char *calc_ecc)
  426. {
  427. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  428. unsigned int diff0, diff1, diff2;
  429. unsigned int bit, byte;
  430. pr_debug("%s(%p,%p,%p,%p)\n", __func__, mtd, dat, read_ecc, calc_ecc);
  431. diff0 = read_ecc[0] ^ calc_ecc[0];
  432. diff1 = read_ecc[1] ^ calc_ecc[1];
  433. diff2 = read_ecc[2] ^ calc_ecc[2];
  434. pr_debug("%s: rd %*phN calc %*phN diff %02x%02x%02x\n",
  435. __func__, 3, read_ecc, 3, calc_ecc,
  436. diff0, diff1, diff2);
  437. if (diff0 == 0 && diff1 == 0 && diff2 == 0)
  438. return 0; /* ECC is ok */
  439. /* sometimes people do not think about using the ECC, so check
  440. * to see if we have an 0xff,0xff,0xff read ECC and then ignore
  441. * the error, on the assumption that this is an un-eccd page.
  442. */
  443. if (read_ecc[0] == 0xff && read_ecc[1] == 0xff && read_ecc[2] == 0xff
  444. && info->platform->ignore_unset_ecc)
  445. return 0;
  446. /* Can we correct this ECC (ie, one row and column change).
  447. * Note, this is similar to the 256 error code on smartmedia */
  448. if (((diff0 ^ (diff0 >> 1)) & 0x55) == 0x55 &&
  449. ((diff1 ^ (diff1 >> 1)) & 0x55) == 0x55 &&
  450. ((diff2 ^ (diff2 >> 1)) & 0x55) == 0x55) {
  451. /* calculate the bit position of the error */
  452. bit = ((diff2 >> 3) & 1) |
  453. ((diff2 >> 4) & 2) |
  454. ((diff2 >> 5) & 4);
  455. /* calculate the byte position of the error */
  456. byte = ((diff2 << 7) & 0x100) |
  457. ((diff1 << 0) & 0x80) |
  458. ((diff1 << 1) & 0x40) |
  459. ((diff1 << 2) & 0x20) |
  460. ((diff1 << 3) & 0x10) |
  461. ((diff0 >> 4) & 0x08) |
  462. ((diff0 >> 3) & 0x04) |
  463. ((diff0 >> 2) & 0x02) |
  464. ((diff0 >> 1) & 0x01);
  465. dev_dbg(info->device, "correcting error bit %d, byte %d\n",
  466. bit, byte);
  467. dat[byte] ^= (1 << bit);
  468. return 1;
  469. }
  470. /* if there is only one bit difference in the ECC, then
  471. * one of only a row or column parity has changed, which
  472. * means the error is most probably in the ECC itself */
  473. diff0 |= (diff1 << 8);
  474. diff0 |= (diff2 << 16);
  475. /* equal to "(diff0 & ~(1 << __ffs(diff0)))" */
  476. if ((diff0 & (diff0 - 1)) == 0)
  477. return 1;
  478. return -1;
  479. }
  480. /* ECC functions
  481. *
  482. * These allow the s3c2410 and s3c2440 to use the controller's ECC
  483. * generator block to ECC the data as it passes through]
  484. */
  485. static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode)
  486. {
  487. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  488. unsigned long ctrl;
  489. ctrl = readl(info->regs + S3C2410_NFCONF);
  490. ctrl |= S3C2410_NFCONF_INITECC;
  491. writel(ctrl, info->regs + S3C2410_NFCONF);
  492. }
  493. static void s3c2412_nand_enable_hwecc(struct mtd_info *mtd, int mode)
  494. {
  495. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  496. unsigned long ctrl;
  497. ctrl = readl(info->regs + S3C2440_NFCONT);
  498. writel(ctrl | S3C2412_NFCONT_INIT_MAIN_ECC,
  499. info->regs + S3C2440_NFCONT);
  500. }
  501. static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
  502. {
  503. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  504. unsigned long ctrl;
  505. ctrl = readl(info->regs + S3C2440_NFCONT);
  506. writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT);
  507. }
  508. static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
  509. u_char *ecc_code)
  510. {
  511. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  512. ecc_code[0] = readb(info->regs + S3C2410_NFECC + 0);
  513. ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1);
  514. ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2);
  515. pr_debug("%s: returning ecc %*phN\n", __func__, 3, ecc_code);
  516. return 0;
  517. }
  518. static int s3c2412_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
  519. u_char *ecc_code)
  520. {
  521. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  522. unsigned long ecc = readl(info->regs + S3C2412_NFMECC0);
  523. ecc_code[0] = ecc;
  524. ecc_code[1] = ecc >> 8;
  525. ecc_code[2] = ecc >> 16;
  526. pr_debug("%s: returning ecc %*phN\n", __func__, 3, ecc_code);
  527. return 0;
  528. }
  529. static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
  530. u_char *ecc_code)
  531. {
  532. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  533. unsigned long ecc = readl(info->regs + S3C2440_NFMECC0);
  534. ecc_code[0] = ecc;
  535. ecc_code[1] = ecc >> 8;
  536. ecc_code[2] = ecc >> 16;
  537. pr_debug("%s: returning ecc %06lx\n", __func__, ecc & 0xffffff);
  538. return 0;
  539. }
  540. /* over-ride the standard functions for a little more speed. We can
  541. * use read/write block to move the data buffers to/from the controller
  542. */
  543. static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
  544. {
  545. struct nand_chip *this = mtd_to_nand(mtd);
  546. readsb(this->IO_ADDR_R, buf, len);
  547. }
  548. static void s3c2440_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
  549. {
  550. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  551. readsl(info->regs + S3C2440_NFDATA, buf, len >> 2);
  552. /* cleanup if we've got less than a word to do */
  553. if (len & 3) {
  554. buf += len & ~3;
  555. for (; len & 3; len--)
  556. *buf++ = readb(info->regs + S3C2440_NFDATA);
  557. }
  558. }
  559. static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf,
  560. int len)
  561. {
  562. struct nand_chip *this = mtd_to_nand(mtd);
  563. writesb(this->IO_ADDR_W, buf, len);
  564. }
  565. static void s3c2440_nand_write_buf(struct mtd_info *mtd, const u_char *buf,
  566. int len)
  567. {
  568. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  569. writesl(info->regs + S3C2440_NFDATA, buf, len >> 2);
  570. /* cleanup any fractional write */
  571. if (len & 3) {
  572. buf += len & ~3;
  573. for (; len & 3; len--, buf++)
  574. writeb(*buf, info->regs + S3C2440_NFDATA);
  575. }
  576. }
  577. /* cpufreq driver support */
  578. #ifdef CONFIG_ARM_S3C24XX_CPUFREQ
  579. static int s3c2410_nand_cpufreq_transition(struct notifier_block *nb,
  580. unsigned long val, void *data)
  581. {
  582. struct s3c2410_nand_info *info;
  583. unsigned long newclk;
  584. info = container_of(nb, struct s3c2410_nand_info, freq_transition);
  585. newclk = clk_get_rate(info->clk);
  586. if ((val == CPUFREQ_POSTCHANGE && newclk < info->clk_rate) ||
  587. (val == CPUFREQ_PRECHANGE && newclk > info->clk_rate)) {
  588. s3c2410_nand_setrate(info);
  589. }
  590. return 0;
  591. }
  592. static inline int s3c2410_nand_cpufreq_register(struct s3c2410_nand_info *info)
  593. {
  594. info->freq_transition.notifier_call = s3c2410_nand_cpufreq_transition;
  595. return cpufreq_register_notifier(&info->freq_transition,
  596. CPUFREQ_TRANSITION_NOTIFIER);
  597. }
  598. static inline void
  599. s3c2410_nand_cpufreq_deregister(struct s3c2410_nand_info *info)
  600. {
  601. cpufreq_unregister_notifier(&info->freq_transition,
  602. CPUFREQ_TRANSITION_NOTIFIER);
  603. }
  604. #else
  605. static inline int s3c2410_nand_cpufreq_register(struct s3c2410_nand_info *info)
  606. {
  607. return 0;
  608. }
  609. static inline void
  610. s3c2410_nand_cpufreq_deregister(struct s3c2410_nand_info *info)
  611. {
  612. }
  613. #endif
  614. /* device management functions */
  615. static int s3c24xx_nand_remove(struct platform_device *pdev)
  616. {
  617. struct s3c2410_nand_info *info = to_nand_info(pdev);
  618. if (info == NULL)
  619. return 0;
  620. s3c2410_nand_cpufreq_deregister(info);
  621. /* Release all our mtds and their partitions, then go through
  622. * freeing the resources used
  623. */
  624. if (info->mtds != NULL) {
  625. struct s3c2410_nand_mtd *ptr = info->mtds;
  626. int mtdno;
  627. for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) {
  628. pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
  629. nand_release(&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_data_interface(struct mtd_info *mtd, int csline,
  650. const struct nand_data_interface *conf)
  651. {
  652. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  653. struct s3c2410_platform_nand *pdata = info->platform;
  654. const struct nand_sdr_timings *timings;
  655. int tacls;
  656. timings = nand_get_sdr_timings(conf);
  657. if (IS_ERR(timings))
  658. return -ENOTSUPP;
  659. tacls = timings->tCLS_min - timings->tWP_min;
  660. if (tacls < 0)
  661. tacls = 0;
  662. pdata->tacls = DIV_ROUND_UP(tacls, 1000);
  663. pdata->twrph0 = DIV_ROUND_UP(timings->tWP_min, 1000);
  664. pdata->twrph1 = DIV_ROUND_UP(timings->tCLH_min, 1000);
  665. return s3c2410_nand_setrate(info);
  666. }
  667. /**
  668. * s3c2410_nand_init_chip - initialise a single instance of an chip
  669. * @info: The base NAND controller the chip is on.
  670. * @nmtd: The new controller MTD instance to fill in.
  671. * @set: The information passed from the board specific platform data.
  672. *
  673. * Initialise the given @nmtd from the information in @info and @set. This
  674. * readies the structure for use with the MTD layer functions by ensuring
  675. * all pointers are setup and the necessary control routines selected.
  676. */
  677. static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
  678. struct s3c2410_nand_mtd *nmtd,
  679. struct s3c2410_nand_set *set)
  680. {
  681. struct device_node *np = info->device->of_node;
  682. struct nand_chip *chip = &nmtd->chip;
  683. void __iomem *regs = info->regs;
  684. nand_set_flash_node(chip, set->of_node);
  685. chip->write_buf = s3c2410_nand_write_buf;
  686. chip->read_buf = s3c2410_nand_read_buf;
  687. chip->select_chip = s3c2410_nand_select_chip;
  688. chip->chip_delay = 50;
  689. nand_set_controller_data(chip, nmtd);
  690. chip->options = set->options;
  691. chip->controller = &info->controller;
  692. /*
  693. * let's keep behavior unchanged for legacy boards booting via pdata and
  694. * auto-detect timings only when booting with a device tree.
  695. */
  696. if (np)
  697. chip->setup_data_interface = s3c2410_nand_setup_data_interface;
  698. switch (info->cpu_type) {
  699. case TYPE_S3C2410:
  700. chip->IO_ADDR_W = regs + S3C2410_NFDATA;
  701. info->sel_reg = regs + S3C2410_NFCONF;
  702. info->sel_bit = S3C2410_NFCONF_nFCE;
  703. chip->cmd_ctrl = s3c2410_nand_hwcontrol;
  704. chip->dev_ready = s3c2410_nand_devready;
  705. break;
  706. case TYPE_S3C2440:
  707. chip->IO_ADDR_W = regs + S3C2440_NFDATA;
  708. info->sel_reg = regs + S3C2440_NFCONT;
  709. info->sel_bit = S3C2440_NFCONT_nFCE;
  710. chip->cmd_ctrl = s3c2440_nand_hwcontrol;
  711. chip->dev_ready = s3c2440_nand_devready;
  712. chip->read_buf = s3c2440_nand_read_buf;
  713. chip->write_buf = s3c2440_nand_write_buf;
  714. break;
  715. case TYPE_S3C2412:
  716. chip->IO_ADDR_W = regs + S3C2440_NFDATA;
  717. info->sel_reg = regs + S3C2440_NFCONT;
  718. info->sel_bit = S3C2412_NFCONT_nFCE0;
  719. chip->cmd_ctrl = s3c2440_nand_hwcontrol;
  720. chip->dev_ready = s3c2412_nand_devready;
  721. if (readl(regs + S3C2410_NFCONF) & S3C2412_NFCONF_NANDBOOT)
  722. dev_info(info->device, "System booted from NAND\n");
  723. break;
  724. }
  725. chip->IO_ADDR_R = chip->IO_ADDR_W;
  726. nmtd->info = info;
  727. nmtd->set = set;
  728. chip->ecc.mode = info->platform->ecc_mode;
  729. /*
  730. * If you use u-boot BBT creation code, specifying this flag will
  731. * let the kernel fish out the BBT from the NAND.
  732. */
  733. if (set->flash_bbt)
  734. chip->bbt_options |= NAND_BBT_USE_FLASH;
  735. }
  736. /**
  737. * s3c2410_nand_attach_chip - Init the ECC engine after NAND scan
  738. * @chip: The NAND chip
  739. *
  740. * This hook is called by the core after the identification of the NAND chip,
  741. * once the relevant per-chip information is up to date.. This call ensure that
  742. * we update the internal state accordingly.
  743. *
  744. * The internal state is currently limited to the ECC state information.
  745. */
  746. static int s3c2410_nand_attach_chip(struct nand_chip *chip)
  747. {
  748. struct mtd_info *mtd = nand_to_mtd(chip);
  749. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  750. switch (chip->ecc.mode) {
  751. case NAND_ECC_NONE:
  752. dev_info(info->device, "ECC disabled\n");
  753. break;
  754. case NAND_ECC_SOFT:
  755. /*
  756. * This driver expects Hamming based ECC when ecc_mode is set
  757. * to NAND_ECC_SOFT. Force ecc.algo to NAND_ECC_HAMMING to
  758. * avoid adding an extra ecc_algo field to
  759. * s3c2410_platform_nand.
  760. */
  761. chip->ecc.algo = NAND_ECC_HAMMING;
  762. dev_info(info->device, "soft ECC\n");
  763. break;
  764. case NAND_ECC_HW:
  765. chip->ecc.calculate = s3c2410_nand_calculate_ecc;
  766. chip->ecc.correct = s3c2410_nand_correct_data;
  767. chip->ecc.strength = 1;
  768. switch (info->cpu_type) {
  769. case TYPE_S3C2410:
  770. chip->ecc.hwctl = s3c2410_nand_enable_hwecc;
  771. chip->ecc.calculate = s3c2410_nand_calculate_ecc;
  772. break;
  773. case TYPE_S3C2412:
  774. chip->ecc.hwctl = s3c2412_nand_enable_hwecc;
  775. chip->ecc.calculate = s3c2412_nand_calculate_ecc;
  776. break;
  777. case TYPE_S3C2440:
  778. chip->ecc.hwctl = s3c2440_nand_enable_hwecc;
  779. chip->ecc.calculate = s3c2440_nand_calculate_ecc;
  780. break;
  781. }
  782. dev_dbg(info->device, "chip %p => page shift %d\n",
  783. chip, chip->page_shift);
  784. /* change the behaviour depending on whether we are using
  785. * the large or small page nand device */
  786. if (chip->page_shift > 10) {
  787. chip->ecc.size = 256;
  788. chip->ecc.bytes = 3;
  789. } else {
  790. chip->ecc.size = 512;
  791. chip->ecc.bytes = 3;
  792. mtd_set_ooblayout(nand_to_mtd(chip),
  793. &s3c2410_ooblayout_ops);
  794. }
  795. dev_info(info->device, "hardware ECC\n");
  796. break;
  797. default:
  798. dev_err(info->device, "invalid ECC mode!\n");
  799. return -EINVAL;
  800. }
  801. if (chip->bbt_options & NAND_BBT_USE_FLASH)
  802. chip->options |= NAND_SKIP_BBTSCAN;
  803. return 0;
  804. }
  805. static const struct nand_controller_ops s3c24xx_nand_controller_ops = {
  806. .attach_chip = s3c2410_nand_attach_chip,
  807. };
  808. static const struct of_device_id s3c24xx_nand_dt_ids[] = {
  809. {
  810. .compatible = "samsung,s3c2410-nand",
  811. .data = &s3c2410_nand_devtype_data,
  812. }, {
  813. /* also compatible with s3c6400 */
  814. .compatible = "samsung,s3c2412-nand",
  815. .data = &s3c2412_nand_devtype_data,
  816. }, {
  817. .compatible = "samsung,s3c2440-nand",
  818. .data = &s3c2440_nand_devtype_data,
  819. },
  820. { /* sentinel */ }
  821. };
  822. MODULE_DEVICE_TABLE(of, s3c24xx_nand_dt_ids);
  823. static int s3c24xx_nand_probe_dt(struct platform_device *pdev)
  824. {
  825. const struct s3c24XX_nand_devtype_data *devtype_data;
  826. struct s3c2410_platform_nand *pdata;
  827. struct s3c2410_nand_info *info = platform_get_drvdata(pdev);
  828. struct device_node *np = pdev->dev.of_node, *child;
  829. struct s3c2410_nand_set *sets;
  830. devtype_data = of_device_get_match_data(&pdev->dev);
  831. if (!devtype_data)
  832. return -ENODEV;
  833. info->cpu_type = devtype_data->type;
  834. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  835. if (!pdata)
  836. return -ENOMEM;
  837. pdev->dev.platform_data = pdata;
  838. pdata->nr_sets = of_get_child_count(np);
  839. if (!pdata->nr_sets)
  840. return 0;
  841. sets = devm_kcalloc(&pdev->dev, pdata->nr_sets, sizeof(*sets),
  842. GFP_KERNEL);
  843. if (!sets)
  844. return -ENOMEM;
  845. pdata->sets = sets;
  846. for_each_available_child_of_node(np, child) {
  847. sets->name = (char *)child->name;
  848. sets->of_node = child;
  849. sets->nr_chips = 1;
  850. of_node_get(child);
  851. sets++;
  852. }
  853. return 0;
  854. }
  855. static int s3c24xx_nand_probe_pdata(struct platform_device *pdev)
  856. {
  857. struct s3c2410_nand_info *info = platform_get_drvdata(pdev);
  858. info->cpu_type = platform_get_device_id(pdev)->driver_data;
  859. return 0;
  860. }
  861. /* s3c24xx_nand_probe
  862. *
  863. * called by device layer when it finds a device matching
  864. * one our driver can handled. This code checks to see if
  865. * it can allocate all necessary resources then calls the
  866. * nand layer to look for devices
  867. */
  868. static int s3c24xx_nand_probe(struct platform_device *pdev)
  869. {
  870. struct s3c2410_platform_nand *plat;
  871. struct s3c2410_nand_info *info;
  872. struct s3c2410_nand_mtd *nmtd;
  873. struct s3c2410_nand_set *sets;
  874. struct resource *res;
  875. int err = 0;
  876. int size;
  877. int nr_sets;
  878. int setno;
  879. info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
  880. if (info == NULL) {
  881. err = -ENOMEM;
  882. goto exit_error;
  883. }
  884. platform_set_drvdata(pdev, info);
  885. nand_controller_init(&info->controller);
  886. info->controller.ops = &s3c24xx_nand_controller_ops;
  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. if (!plat->sets || plat->nr_sets < 1) {
  915. err = -EINVAL;
  916. goto exit_error;
  917. }
  918. sets = plat->sets;
  919. nr_sets = plat->nr_sets;
  920. info->mtd_count = nr_sets;
  921. /* allocate our information */
  922. size = nr_sets * sizeof(*info->mtds);
  923. info->mtds = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
  924. if (info->mtds == NULL) {
  925. err = -ENOMEM;
  926. goto exit_error;
  927. }
  928. /* initialise all possible chips */
  929. nmtd = info->mtds;
  930. for (setno = 0; setno < nr_sets; setno++, nmtd++, sets++) {
  931. struct mtd_info *mtd = nand_to_mtd(&nmtd->chip);
  932. pr_debug("initialising set %d (%p, info %p)\n",
  933. setno, nmtd, info);
  934. mtd->dev.parent = &pdev->dev;
  935. s3c2410_nand_init_chip(info, nmtd, sets);
  936. err = nand_scan(&nmtd->chip, sets ? sets->nr_chips : 1);
  937. if (err)
  938. goto exit_error;
  939. s3c2410_nand_add_partition(info, nmtd, sets);
  940. }
  941. /* initialise the hardware */
  942. err = s3c2410_nand_inithw(info);
  943. if (err != 0)
  944. goto exit_error;
  945. err = s3c2410_nand_cpufreq_register(info);
  946. if (err < 0) {
  947. dev_err(&pdev->dev, "failed to init cpufreq support\n");
  948. goto exit_error;
  949. }
  950. if (allow_clk_suspend(info)) {
  951. dev_info(&pdev->dev, "clock idle support enabled\n");
  952. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  953. }
  954. return 0;
  955. exit_error:
  956. s3c24xx_nand_remove(pdev);
  957. if (err == 0)
  958. err = -EINVAL;
  959. return err;
  960. }
  961. /* PM Support */
  962. #ifdef CONFIG_PM
  963. static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
  964. {
  965. struct s3c2410_nand_info *info = platform_get_drvdata(dev);
  966. if (info) {
  967. info->save_sel = readl(info->sel_reg);
  968. /* For the moment, we must ensure nFCE is high during
  969. * the time we are suspended. This really should be
  970. * handled by suspending the MTDs we are using, but
  971. * that is currently not the case. */
  972. writel(info->save_sel | info->sel_bit, info->sel_reg);
  973. s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
  974. }
  975. return 0;
  976. }
  977. static int s3c24xx_nand_resume(struct platform_device *dev)
  978. {
  979. struct s3c2410_nand_info *info = platform_get_drvdata(dev);
  980. unsigned long sel;
  981. if (info) {
  982. s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
  983. s3c2410_nand_inithw(info);
  984. /* Restore the state of the nFCE line. */
  985. sel = readl(info->sel_reg);
  986. sel &= ~info->sel_bit;
  987. sel |= info->save_sel & info->sel_bit;
  988. writel(sel, info->sel_reg);
  989. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  990. }
  991. return 0;
  992. }
  993. #else
  994. #define s3c24xx_nand_suspend NULL
  995. #define s3c24xx_nand_resume NULL
  996. #endif
  997. /* driver device registration */
  998. static const struct platform_device_id s3c24xx_driver_ids[] = {
  999. {
  1000. .name = "s3c2410-nand",
  1001. .driver_data = TYPE_S3C2410,
  1002. }, {
  1003. .name = "s3c2440-nand",
  1004. .driver_data = TYPE_S3C2440,
  1005. }, {
  1006. .name = "s3c2412-nand",
  1007. .driver_data = TYPE_S3C2412,
  1008. }, {
  1009. .name = "s3c6400-nand",
  1010. .driver_data = TYPE_S3C2412, /* compatible with 2412 */
  1011. },
  1012. { }
  1013. };
  1014. MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
  1015. static struct platform_driver s3c24xx_nand_driver = {
  1016. .probe = s3c24xx_nand_probe,
  1017. .remove = s3c24xx_nand_remove,
  1018. .suspend = s3c24xx_nand_suspend,
  1019. .resume = s3c24xx_nand_resume,
  1020. .id_table = s3c24xx_driver_ids,
  1021. .driver = {
  1022. .name = "s3c24xx-nand",
  1023. .of_match_table = s3c24xx_nand_dt_ids,
  1024. },
  1025. };
  1026. module_platform_driver(s3c24xx_nand_driver);
  1027. MODULE_LICENSE("GPL");
  1028. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  1029. MODULE_DESCRIPTION("S3C24XX MTD NAND driver");