s3c2410.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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/nand.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,
  653. const struct nand_data_interface *conf,
  654. bool check_only)
  655. {
  656. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  657. struct s3c2410_platform_nand *pdata = info->platform;
  658. const struct nand_sdr_timings *timings;
  659. int tacls;
  660. timings = nand_get_sdr_timings(conf);
  661. if (IS_ERR(timings))
  662. return -ENOTSUPP;
  663. tacls = timings->tCLS_min - timings->tWP_min;
  664. if (tacls < 0)
  665. tacls = 0;
  666. pdata->tacls = DIV_ROUND_UP(tacls, 1000);
  667. pdata->twrph0 = DIV_ROUND_UP(timings->tWP_min, 1000);
  668. pdata->twrph1 = DIV_ROUND_UP(timings->tCLH_min, 1000);
  669. return s3c2410_nand_setrate(info);
  670. }
  671. /**
  672. * s3c2410_nand_init_chip - initialise a single instance of an chip
  673. * @info: The base NAND controller the chip is on.
  674. * @nmtd: The new controller MTD instance to fill in.
  675. * @set: The information passed from the board specific platform data.
  676. *
  677. * Initialise the given @nmtd from the information in @info and @set. This
  678. * readies the structure for use with the MTD layer functions by ensuring
  679. * all pointers are setup and the necessary control routines selected.
  680. */
  681. static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
  682. struct s3c2410_nand_mtd *nmtd,
  683. struct s3c2410_nand_set *set)
  684. {
  685. struct device_node *np = info->device->of_node;
  686. struct nand_chip *chip = &nmtd->chip;
  687. void __iomem *regs = info->regs;
  688. nand_set_flash_node(chip, set->of_node);
  689. chip->write_buf = s3c2410_nand_write_buf;
  690. chip->read_buf = s3c2410_nand_read_buf;
  691. chip->select_chip = s3c2410_nand_select_chip;
  692. chip->chip_delay = 50;
  693. nand_set_controller_data(chip, nmtd);
  694. chip->options = set->options;
  695. chip->controller = &info->controller;
  696. /*
  697. * let's keep behavior unchanged for legacy boards booting via pdata and
  698. * auto-detect timings only when booting with a device tree.
  699. */
  700. if (np)
  701. chip->setup_data_interface = s3c2410_nand_setup_data_interface;
  702. switch (info->cpu_type) {
  703. case TYPE_S3C2410:
  704. chip->IO_ADDR_W = regs + S3C2410_NFDATA;
  705. info->sel_reg = regs + S3C2410_NFCONF;
  706. info->sel_bit = S3C2410_NFCONF_nFCE;
  707. chip->cmd_ctrl = s3c2410_nand_hwcontrol;
  708. chip->dev_ready = s3c2410_nand_devready;
  709. break;
  710. case TYPE_S3C2440:
  711. chip->IO_ADDR_W = regs + S3C2440_NFDATA;
  712. info->sel_reg = regs + S3C2440_NFCONT;
  713. info->sel_bit = S3C2440_NFCONT_nFCE;
  714. chip->cmd_ctrl = s3c2440_nand_hwcontrol;
  715. chip->dev_ready = s3c2440_nand_devready;
  716. chip->read_buf = s3c2440_nand_read_buf;
  717. chip->write_buf = s3c2440_nand_write_buf;
  718. break;
  719. case TYPE_S3C2412:
  720. chip->IO_ADDR_W = regs + S3C2440_NFDATA;
  721. info->sel_reg = regs + S3C2440_NFCONT;
  722. info->sel_bit = S3C2412_NFCONT_nFCE0;
  723. chip->cmd_ctrl = s3c2440_nand_hwcontrol;
  724. chip->dev_ready = s3c2412_nand_devready;
  725. if (readl(regs + S3C2410_NFCONF) & S3C2412_NFCONF_NANDBOOT)
  726. dev_info(info->device, "System booted from NAND\n");
  727. break;
  728. }
  729. chip->IO_ADDR_R = chip->IO_ADDR_W;
  730. nmtd->info = info;
  731. nmtd->set = set;
  732. chip->ecc.mode = info->platform->ecc_mode;
  733. /*
  734. * If you use u-boot BBT creation code, specifying this flag will
  735. * let the kernel fish out the BBT from the NAND.
  736. */
  737. if (set->flash_bbt)
  738. chip->bbt_options |= NAND_BBT_USE_FLASH;
  739. }
  740. /**
  741. * s3c2410_nand_update_chip - post probe update
  742. * @info: The controller instance.
  743. * @nmtd: The driver version of the MTD instance.
  744. *
  745. * This routine is called after the chip probe has successfully completed
  746. * and the relevant per-chip information updated. This call ensure that
  747. * we update the internal state accordingly.
  748. *
  749. * The internal state is currently limited to the ECC state information.
  750. */
  751. static int s3c2410_nand_update_chip(struct s3c2410_nand_info *info,
  752. struct s3c2410_nand_mtd *nmtd)
  753. {
  754. struct nand_chip *chip = &nmtd->chip;
  755. switch (chip->ecc.mode) {
  756. case NAND_ECC_NONE:
  757. dev_info(info->device, "ECC disabled\n");
  758. break;
  759. case NAND_ECC_SOFT:
  760. /*
  761. * This driver expects Hamming based ECC when ecc_mode is set
  762. * to NAND_ECC_SOFT. Force ecc.algo to NAND_ECC_HAMMING to
  763. * avoid adding an extra ecc_algo field to
  764. * s3c2410_platform_nand.
  765. */
  766. chip->ecc.algo = NAND_ECC_HAMMING;
  767. dev_info(info->device, "soft ECC\n");
  768. break;
  769. case NAND_ECC_HW:
  770. chip->ecc.calculate = s3c2410_nand_calculate_ecc;
  771. chip->ecc.correct = s3c2410_nand_correct_data;
  772. chip->ecc.strength = 1;
  773. switch (info->cpu_type) {
  774. case TYPE_S3C2410:
  775. chip->ecc.hwctl = s3c2410_nand_enable_hwecc;
  776. chip->ecc.calculate = s3c2410_nand_calculate_ecc;
  777. break;
  778. case TYPE_S3C2412:
  779. chip->ecc.hwctl = s3c2412_nand_enable_hwecc;
  780. chip->ecc.calculate = s3c2412_nand_calculate_ecc;
  781. break;
  782. case TYPE_S3C2440:
  783. chip->ecc.hwctl = s3c2440_nand_enable_hwecc;
  784. chip->ecc.calculate = s3c2440_nand_calculate_ecc;
  785. break;
  786. }
  787. dev_dbg(info->device, "chip %p => page shift %d\n",
  788. chip, chip->page_shift);
  789. /* change the behaviour depending on whether we are using
  790. * the large or small page nand device */
  791. if (chip->page_shift > 10) {
  792. chip->ecc.size = 256;
  793. chip->ecc.bytes = 3;
  794. } else {
  795. chip->ecc.size = 512;
  796. chip->ecc.bytes = 3;
  797. mtd_set_ooblayout(nand_to_mtd(chip),
  798. &s3c2410_ooblayout_ops);
  799. }
  800. dev_info(info->device, "hardware ECC\n");
  801. break;
  802. default:
  803. dev_err(info->device, "invalid ECC mode!\n");
  804. return -EINVAL;
  805. }
  806. if (chip->bbt_options & NAND_BBT_USE_FLASH)
  807. chip->options |= NAND_SKIP_BBTSCAN;
  808. return 0;
  809. }
  810. static const struct of_device_id s3c24xx_nand_dt_ids[] = {
  811. {
  812. .compatible = "samsung,s3c2410-nand",
  813. .data = &s3c2410_nand_devtype_data,
  814. }, {
  815. /* also compatible with s3c6400 */
  816. .compatible = "samsung,s3c2412-nand",
  817. .data = &s3c2412_nand_devtype_data,
  818. }, {
  819. .compatible = "samsung,s3c2440-nand",
  820. .data = &s3c2440_nand_devtype_data,
  821. },
  822. { /* sentinel */ }
  823. };
  824. MODULE_DEVICE_TABLE(of, s3c24xx_nand_dt_ids);
  825. static int s3c24xx_nand_probe_dt(struct platform_device *pdev)
  826. {
  827. const struct s3c24XX_nand_devtype_data *devtype_data;
  828. struct s3c2410_platform_nand *pdata;
  829. struct s3c2410_nand_info *info = platform_get_drvdata(pdev);
  830. struct device_node *np = pdev->dev.of_node, *child;
  831. struct s3c2410_nand_set *sets;
  832. devtype_data = of_device_get_match_data(&pdev->dev);
  833. if (!devtype_data)
  834. return -ENODEV;
  835. info->cpu_type = devtype_data->type;
  836. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  837. if (!pdata)
  838. return -ENOMEM;
  839. pdev->dev.platform_data = pdata;
  840. pdata->nr_sets = of_get_child_count(np);
  841. if (!pdata->nr_sets)
  842. return 0;
  843. sets = devm_kzalloc(&pdev->dev, sizeof(*sets) * pdata->nr_sets,
  844. GFP_KERNEL);
  845. if (!sets)
  846. return -ENOMEM;
  847. pdata->sets = sets;
  848. for_each_available_child_of_node(np, child) {
  849. sets->name = (char *)child->name;
  850. sets->of_node = child;
  851. sets->nr_chips = 1;
  852. of_node_get(child);
  853. sets++;
  854. }
  855. return 0;
  856. }
  857. static int s3c24xx_nand_probe_pdata(struct platform_device *pdev)
  858. {
  859. struct s3c2410_nand_info *info = platform_get_drvdata(pdev);
  860. info->cpu_type = platform_get_device_id(pdev)->driver_data;
  861. return 0;
  862. }
  863. /* s3c24xx_nand_probe
  864. *
  865. * called by device layer when it finds a device matching
  866. * one our driver can handled. This code checks to see if
  867. * it can allocate all necessary resources then calls the
  868. * nand layer to look for devices
  869. */
  870. static int s3c24xx_nand_probe(struct platform_device *pdev)
  871. {
  872. struct s3c2410_platform_nand *plat;
  873. struct s3c2410_nand_info *info;
  874. struct s3c2410_nand_mtd *nmtd;
  875. struct s3c2410_nand_set *sets;
  876. struct resource *res;
  877. int err = 0;
  878. int size;
  879. int nr_sets;
  880. int setno;
  881. info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
  882. if (info == NULL) {
  883. err = -ENOMEM;
  884. goto exit_error;
  885. }
  886. platform_set_drvdata(pdev, info);
  887. nand_hw_control_init(&info->controller);
  888. /* get the clock source and enable it */
  889. info->clk = devm_clk_get(&pdev->dev, "nand");
  890. if (IS_ERR(info->clk)) {
  891. dev_err(&pdev->dev, "failed to get clock\n");
  892. err = -ENOENT;
  893. goto exit_error;
  894. }
  895. s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
  896. if (pdev->dev.of_node)
  897. err = s3c24xx_nand_probe_dt(pdev);
  898. else
  899. err = s3c24xx_nand_probe_pdata(pdev);
  900. if (err)
  901. goto exit_error;
  902. plat = to_nand_plat(pdev);
  903. /* allocate and map the resource */
  904. /* currently we assume we have the one resource */
  905. res = pdev->resource;
  906. size = resource_size(res);
  907. info->device = &pdev->dev;
  908. info->platform = plat;
  909. info->regs = devm_ioremap_resource(&pdev->dev, res);
  910. if (IS_ERR(info->regs)) {
  911. err = PTR_ERR(info->regs);
  912. goto exit_error;
  913. }
  914. dev_dbg(&pdev->dev, "mapped registers at %p\n", info->regs);
  915. sets = (plat != NULL) ? plat->sets : NULL;
  916. nr_sets = (plat != NULL) ? plat->nr_sets : 1;
  917. info->mtd_count = nr_sets;
  918. /* allocate our information */
  919. size = nr_sets * sizeof(*info->mtds);
  920. info->mtds = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
  921. if (info->mtds == NULL) {
  922. err = -ENOMEM;
  923. goto exit_error;
  924. }
  925. /* initialise all possible chips */
  926. nmtd = info->mtds;
  927. for (setno = 0; setno < nr_sets; setno++, nmtd++) {
  928. struct mtd_info *mtd = nand_to_mtd(&nmtd->chip);
  929. pr_debug("initialising set %d (%p, info %p)\n",
  930. setno, nmtd, info);
  931. mtd->dev.parent = &pdev->dev;
  932. s3c2410_nand_init_chip(info, nmtd, sets);
  933. nmtd->scan_res = nand_scan_ident(mtd,
  934. (sets) ? sets->nr_chips : 1,
  935. NULL);
  936. if (nmtd->scan_res == 0) {
  937. err = s3c2410_nand_update_chip(info, nmtd);
  938. if (err < 0)
  939. goto exit_error;
  940. nand_scan_tail(mtd);
  941. s3c2410_nand_add_partition(info, nmtd, sets);
  942. }
  943. if (sets != NULL)
  944. sets++;
  945. }
  946. /* initialise the hardware */
  947. err = s3c2410_nand_inithw(info);
  948. if (err != 0)
  949. goto exit_error;
  950. err = s3c2410_nand_cpufreq_register(info);
  951. if (err < 0) {
  952. dev_err(&pdev->dev, "failed to init cpufreq support\n");
  953. goto exit_error;
  954. }
  955. if (allow_clk_suspend(info)) {
  956. dev_info(&pdev->dev, "clock idle support enabled\n");
  957. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  958. }
  959. return 0;
  960. exit_error:
  961. s3c24xx_nand_remove(pdev);
  962. if (err == 0)
  963. err = -EINVAL;
  964. return err;
  965. }
  966. /* PM Support */
  967. #ifdef CONFIG_PM
  968. static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
  969. {
  970. struct s3c2410_nand_info *info = platform_get_drvdata(dev);
  971. if (info) {
  972. info->save_sel = readl(info->sel_reg);
  973. /* For the moment, we must ensure nFCE is high during
  974. * the time we are suspended. This really should be
  975. * handled by suspending the MTDs we are using, but
  976. * that is currently not the case. */
  977. writel(info->save_sel | info->sel_bit, info->sel_reg);
  978. s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
  979. }
  980. return 0;
  981. }
  982. static int s3c24xx_nand_resume(struct platform_device *dev)
  983. {
  984. struct s3c2410_nand_info *info = platform_get_drvdata(dev);
  985. unsigned long sel;
  986. if (info) {
  987. s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
  988. s3c2410_nand_inithw(info);
  989. /* Restore the state of the nFCE line. */
  990. sel = readl(info->sel_reg);
  991. sel &= ~info->sel_bit;
  992. sel |= info->save_sel & info->sel_bit;
  993. writel(sel, info->sel_reg);
  994. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  995. }
  996. return 0;
  997. }
  998. #else
  999. #define s3c24xx_nand_suspend NULL
  1000. #define s3c24xx_nand_resume NULL
  1001. #endif
  1002. /* driver device registration */
  1003. static const struct platform_device_id s3c24xx_driver_ids[] = {
  1004. {
  1005. .name = "s3c2410-nand",
  1006. .driver_data = TYPE_S3C2410,
  1007. }, {
  1008. .name = "s3c2440-nand",
  1009. .driver_data = TYPE_S3C2440,
  1010. }, {
  1011. .name = "s3c2412-nand",
  1012. .driver_data = TYPE_S3C2412,
  1013. }, {
  1014. .name = "s3c6400-nand",
  1015. .driver_data = TYPE_S3C2412, /* compatible with 2412 */
  1016. },
  1017. { }
  1018. };
  1019. MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
  1020. static struct platform_driver s3c24xx_nand_driver = {
  1021. .probe = s3c24xx_nand_probe,
  1022. .remove = s3c24xx_nand_remove,
  1023. .suspend = s3c24xx_nand_suspend,
  1024. .resume = s3c24xx_nand_resume,
  1025. .id_table = s3c24xx_driver_ids,
  1026. .driver = {
  1027. .name = "s3c24xx-nand",
  1028. .of_match_table = s3c24xx_nand_dt_ids,
  1029. },
  1030. };
  1031. module_platform_driver(s3c24xx_nand_driver);
  1032. MODULE_LICENSE("GPL");
  1033. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  1034. MODULE_DESCRIPTION("S3C24XX MTD NAND driver");