s3c2410.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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_hw_control 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(nand_to_mtd(&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_parse_register(mtdinfo, NULL, NULL,
  645. set->partitions, 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_update_chip - post probe update
  738. * @info: The controller instance.
  739. * @nmtd: The driver version of the MTD instance.
  740. *
  741. * This routine is called after the chip probe has successfully completed
  742. * and the relevant per-chip information updated. This call ensure that
  743. * we update the internal state accordingly.
  744. *
  745. * The internal state is currently limited to the ECC state information.
  746. */
  747. static int s3c2410_nand_update_chip(struct s3c2410_nand_info *info,
  748. struct s3c2410_nand_mtd *nmtd)
  749. {
  750. struct nand_chip *chip = &nmtd->chip;
  751. switch (chip->ecc.mode) {
  752. case NAND_ECC_NONE:
  753. dev_info(info->device, "ECC disabled\n");
  754. break;
  755. case NAND_ECC_SOFT:
  756. /*
  757. * This driver expects Hamming based ECC when ecc_mode is set
  758. * to NAND_ECC_SOFT. Force ecc.algo to NAND_ECC_HAMMING to
  759. * avoid adding an extra ecc_algo field to
  760. * s3c2410_platform_nand.
  761. */
  762. chip->ecc.algo = NAND_ECC_HAMMING;
  763. dev_info(info->device, "soft ECC\n");
  764. break;
  765. case NAND_ECC_HW:
  766. chip->ecc.calculate = s3c2410_nand_calculate_ecc;
  767. chip->ecc.correct = s3c2410_nand_correct_data;
  768. chip->ecc.strength = 1;
  769. switch (info->cpu_type) {
  770. case TYPE_S3C2410:
  771. chip->ecc.hwctl = s3c2410_nand_enable_hwecc;
  772. chip->ecc.calculate = s3c2410_nand_calculate_ecc;
  773. break;
  774. case TYPE_S3C2412:
  775. chip->ecc.hwctl = s3c2412_nand_enable_hwecc;
  776. chip->ecc.calculate = s3c2412_nand_calculate_ecc;
  777. break;
  778. case TYPE_S3C2440:
  779. chip->ecc.hwctl = s3c2440_nand_enable_hwecc;
  780. chip->ecc.calculate = s3c2440_nand_calculate_ecc;
  781. break;
  782. }
  783. dev_dbg(info->device, "chip %p => page shift %d\n",
  784. chip, chip->page_shift);
  785. /* change the behaviour depending on whether we are using
  786. * the large or small page nand device */
  787. if (chip->page_shift > 10) {
  788. chip->ecc.size = 256;
  789. chip->ecc.bytes = 3;
  790. } else {
  791. chip->ecc.size = 512;
  792. chip->ecc.bytes = 3;
  793. mtd_set_ooblayout(nand_to_mtd(chip),
  794. &s3c2410_ooblayout_ops);
  795. }
  796. dev_info(info->device, "hardware ECC\n");
  797. break;
  798. default:
  799. dev_err(info->device, "invalid ECC mode!\n");
  800. return -EINVAL;
  801. }
  802. if (chip->bbt_options & NAND_BBT_USE_FLASH)
  803. chip->options |= NAND_SKIP_BBTSCAN;
  804. return 0;
  805. }
  806. static const struct of_device_id s3c24xx_nand_dt_ids[] = {
  807. {
  808. .compatible = "samsung,s3c2410-nand",
  809. .data = &s3c2410_nand_devtype_data,
  810. }, {
  811. /* also compatible with s3c6400 */
  812. .compatible = "samsung,s3c2412-nand",
  813. .data = &s3c2412_nand_devtype_data,
  814. }, {
  815. .compatible = "samsung,s3c2440-nand",
  816. .data = &s3c2440_nand_devtype_data,
  817. },
  818. { /* sentinel */ }
  819. };
  820. MODULE_DEVICE_TABLE(of, s3c24xx_nand_dt_ids);
  821. static int s3c24xx_nand_probe_dt(struct platform_device *pdev)
  822. {
  823. const struct s3c24XX_nand_devtype_data *devtype_data;
  824. struct s3c2410_platform_nand *pdata;
  825. struct s3c2410_nand_info *info = platform_get_drvdata(pdev);
  826. struct device_node *np = pdev->dev.of_node, *child;
  827. struct s3c2410_nand_set *sets;
  828. devtype_data = of_device_get_match_data(&pdev->dev);
  829. if (!devtype_data)
  830. return -ENODEV;
  831. info->cpu_type = devtype_data->type;
  832. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  833. if (!pdata)
  834. return -ENOMEM;
  835. pdev->dev.platform_data = pdata;
  836. pdata->nr_sets = of_get_child_count(np);
  837. if (!pdata->nr_sets)
  838. return 0;
  839. sets = devm_kcalloc(&pdev->dev, pdata->nr_sets, sizeof(*sets),
  840. GFP_KERNEL);
  841. if (!sets)
  842. return -ENOMEM;
  843. pdata->sets = sets;
  844. for_each_available_child_of_node(np, child) {
  845. sets->name = (char *)child->name;
  846. sets->of_node = child;
  847. sets->nr_chips = 1;
  848. of_node_get(child);
  849. sets++;
  850. }
  851. return 0;
  852. }
  853. static int s3c24xx_nand_probe_pdata(struct platform_device *pdev)
  854. {
  855. struct s3c2410_nand_info *info = platform_get_drvdata(pdev);
  856. info->cpu_type = platform_get_device_id(pdev)->driver_data;
  857. return 0;
  858. }
  859. /* s3c24xx_nand_probe
  860. *
  861. * called by device layer when it finds a device matching
  862. * one our driver can handled. This code checks to see if
  863. * it can allocate all necessary resources then calls the
  864. * nand layer to look for devices
  865. */
  866. static int s3c24xx_nand_probe(struct platform_device *pdev)
  867. {
  868. struct s3c2410_platform_nand *plat;
  869. struct s3c2410_nand_info *info;
  870. struct s3c2410_nand_mtd *nmtd;
  871. struct s3c2410_nand_set *sets;
  872. struct resource *res;
  873. int err = 0;
  874. int size;
  875. int nr_sets;
  876. int setno;
  877. info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
  878. if (info == NULL) {
  879. err = -ENOMEM;
  880. goto exit_error;
  881. }
  882. platform_set_drvdata(pdev, info);
  883. nand_hw_control_init(&info->controller);
  884. /* get the clock source and enable it */
  885. info->clk = devm_clk_get(&pdev->dev, "nand");
  886. if (IS_ERR(info->clk)) {
  887. dev_err(&pdev->dev, "failed to get clock\n");
  888. err = -ENOENT;
  889. goto exit_error;
  890. }
  891. s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
  892. if (pdev->dev.of_node)
  893. err = s3c24xx_nand_probe_dt(pdev);
  894. else
  895. err = s3c24xx_nand_probe_pdata(pdev);
  896. if (err)
  897. goto exit_error;
  898. plat = to_nand_plat(pdev);
  899. /* allocate and map the resource */
  900. /* currently we assume we have the one resource */
  901. res = pdev->resource;
  902. size = resource_size(res);
  903. info->device = &pdev->dev;
  904. info->platform = plat;
  905. info->regs = devm_ioremap_resource(&pdev->dev, res);
  906. if (IS_ERR(info->regs)) {
  907. err = PTR_ERR(info->regs);
  908. goto exit_error;
  909. }
  910. dev_dbg(&pdev->dev, "mapped registers at %p\n", info->regs);
  911. sets = (plat != NULL) ? plat->sets : NULL;
  912. nr_sets = (plat != NULL) ? plat->nr_sets : 1;
  913. info->mtd_count = nr_sets;
  914. /* allocate our information */
  915. size = nr_sets * sizeof(*info->mtds);
  916. info->mtds = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
  917. if (info->mtds == NULL) {
  918. err = -ENOMEM;
  919. goto exit_error;
  920. }
  921. /* initialise all possible chips */
  922. nmtd = info->mtds;
  923. for (setno = 0; setno < nr_sets; setno++, nmtd++) {
  924. struct mtd_info *mtd = nand_to_mtd(&nmtd->chip);
  925. pr_debug("initialising set %d (%p, info %p)\n",
  926. setno, nmtd, info);
  927. mtd->dev.parent = &pdev->dev;
  928. s3c2410_nand_init_chip(info, nmtd, sets);
  929. err = nand_scan_ident(mtd, (sets) ? sets->nr_chips : 1, NULL);
  930. if (err)
  931. goto exit_error;
  932. err = s3c2410_nand_update_chip(info, nmtd);
  933. if (err < 0)
  934. goto exit_error;
  935. err = nand_scan_tail(mtd);
  936. if (err)
  937. goto exit_error;
  938. s3c2410_nand_add_partition(info, nmtd, sets);
  939. if (sets != NULL)
  940. sets++;
  941. }
  942. /* initialise the hardware */
  943. err = s3c2410_nand_inithw(info);
  944. if (err != 0)
  945. goto exit_error;
  946. err = s3c2410_nand_cpufreq_register(info);
  947. if (err < 0) {
  948. dev_err(&pdev->dev, "failed to init cpufreq support\n");
  949. goto exit_error;
  950. }
  951. if (allow_clk_suspend(info)) {
  952. dev_info(&pdev->dev, "clock idle support enabled\n");
  953. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  954. }
  955. return 0;
  956. exit_error:
  957. s3c24xx_nand_remove(pdev);
  958. if (err == 0)
  959. err = -EINVAL;
  960. return err;
  961. }
  962. /* PM Support */
  963. #ifdef CONFIG_PM
  964. static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
  965. {
  966. struct s3c2410_nand_info *info = platform_get_drvdata(dev);
  967. if (info) {
  968. info->save_sel = readl(info->sel_reg);
  969. /* For the moment, we must ensure nFCE is high during
  970. * the time we are suspended. This really should be
  971. * handled by suspending the MTDs we are using, but
  972. * that is currently not the case. */
  973. writel(info->save_sel | info->sel_bit, info->sel_reg);
  974. s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
  975. }
  976. return 0;
  977. }
  978. static int s3c24xx_nand_resume(struct platform_device *dev)
  979. {
  980. struct s3c2410_nand_info *info = platform_get_drvdata(dev);
  981. unsigned long sel;
  982. if (info) {
  983. s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
  984. s3c2410_nand_inithw(info);
  985. /* Restore the state of the nFCE line. */
  986. sel = readl(info->sel_reg);
  987. sel &= ~info->sel_bit;
  988. sel |= info->save_sel & info->sel_bit;
  989. writel(sel, info->sel_reg);
  990. s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
  991. }
  992. return 0;
  993. }
  994. #else
  995. #define s3c24xx_nand_suspend NULL
  996. #define s3c24xx_nand_resume NULL
  997. #endif
  998. /* driver device registration */
  999. static const struct platform_device_id s3c24xx_driver_ids[] = {
  1000. {
  1001. .name = "s3c2410-nand",
  1002. .driver_data = TYPE_S3C2410,
  1003. }, {
  1004. .name = "s3c2440-nand",
  1005. .driver_data = TYPE_S3C2440,
  1006. }, {
  1007. .name = "s3c2412-nand",
  1008. .driver_data = TYPE_S3C2412,
  1009. }, {
  1010. .name = "s3c6400-nand",
  1011. .driver_data = TYPE_S3C2412, /* compatible with 2412 */
  1012. },
  1013. { }
  1014. };
  1015. MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
  1016. static struct platform_driver s3c24xx_nand_driver = {
  1017. .probe = s3c24xx_nand_probe,
  1018. .remove = s3c24xx_nand_remove,
  1019. .suspend = s3c24xx_nand_suspend,
  1020. .resume = s3c24xx_nand_resume,
  1021. .id_table = s3c24xx_driver_ids,
  1022. .driver = {
  1023. .name = "s3c24xx-nand",
  1024. .of_match_table = s3c24xx_nand_dt_ids,
  1025. },
  1026. };
  1027. module_platform_driver(s3c24xx_nand_driver);
  1028. MODULE_LICENSE("GPL");
  1029. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  1030. MODULE_DESCRIPTION("S3C24XX MTD NAND driver");