s3c2410.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /* linux/drivers/mtd/nand/s3c2410.c
  2. *
  3. * Copyright (c) 2004,2005 Simtec Electronics
  4. * http://www.simtec.co.uk/products/SWLINUX/
  5. * Ben Dooks <ben@simtec.co.uk>
  6. *
  7. * Samsung S3C2410/S3C240 NAND driver
  8. *
  9. * Changelog:
  10. * 21-Sep-2004 BJD Initial version
  11. * 23-Sep-2004 BJD Mulitple device support
  12. * 28-Sep-2004 BJD Fixed ECC placement for Hardware mode
  13. * 12-Oct-2004 BJD Fixed errors in use of platform data
  14. * 18-Feb-2005 BJD Fix sparse errors
  15. * 14-Mar-2005 BJD Applied tglx's code reduction patch
  16. * 02-May-2005 BJD Fixed s3c2440 support
  17. * 02-May-2005 BJD Reduced hwcontrol decode
  18. * 20-Jun-2005 BJD Updated s3c2440 support, fixed timing bug
  19. * 08-Jul-2005 BJD Fix OOPS when no platform data supplied
  20. * 20-Oct-2005 BJD Fix timing calculation bug
  21. *
  22. * $Id: s3c2410.c,v 1.20 2005/11/07 11:14:31 gleixner Exp $
  23. *
  24. * This program is free software; you can redistribute it and/or modify
  25. * it under the terms of the GNU General Public License as published by
  26. * the Free Software Foundation; either version 2 of the License, or
  27. * (at your option) any later version.
  28. *
  29. * This program is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. * GNU General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU General Public License
  35. * along with this program; if not, write to the Free Software
  36. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  37. */
  38. #include <config/mtd/nand/s3c2410/hwecc.h>
  39. #include <config/mtd/nand/s3c2410/debug.h>
  40. #ifdef CONFIG_MTD_NAND_S3C2410_DEBUG
  41. #define DEBUG
  42. #endif
  43. #include <linux/module.h>
  44. #include <linux/types.h>
  45. #include <linux/init.h>
  46. #include <linux/kernel.h>
  47. #include <linux/string.h>
  48. #include <linux/ioport.h>
  49. #include <linux/platform_device.h>
  50. #include <linux/delay.h>
  51. #include <linux/err.h>
  52. #include <linux/slab.h>
  53. #include <linux/clk.h>
  54. #include <linux/mtd/mtd.h>
  55. #include <linux/mtd/nand.h>
  56. #include <linux/mtd/nand_ecc.h>
  57. #include <linux/mtd/partitions.h>
  58. #include <asm/io.h>
  59. #include <asm/arch/regs-nand.h>
  60. #include <asm/arch/nand.h>
  61. #define PFX "s3c2410-nand: "
  62. #ifdef CONFIG_MTD_NAND_S3C2410_HWECC
  63. static int hardware_ecc = 1;
  64. #else
  65. static int hardware_ecc = 0;
  66. #endif
  67. /* new oob placement block for use with hardware ecc generation
  68. */
  69. static struct nand_oobinfo nand_hw_eccoob = {
  70. .useecc = MTD_NANDECC_AUTOPLACE,
  71. .eccbytes = 3,
  72. .eccpos = {0, 1, 2},
  73. .oobfree = {{8, 8}}
  74. };
  75. /* controller and mtd information */
  76. struct s3c2410_nand_info;
  77. struct s3c2410_nand_mtd {
  78. struct mtd_info mtd;
  79. struct nand_chip chip;
  80. struct s3c2410_nand_set *set;
  81. struct s3c2410_nand_info *info;
  82. int scan_res;
  83. };
  84. /* overview of the s3c2410 nand state */
  85. struct s3c2410_nand_info {
  86. /* mtd info */
  87. struct nand_hw_control controller;
  88. struct s3c2410_nand_mtd *mtds;
  89. struct s3c2410_platform_nand *platform;
  90. /* device info */
  91. struct device *device;
  92. struct resource *area;
  93. struct clk *clk;
  94. void __iomem *regs;
  95. int mtd_count;
  96. unsigned char is_s3c2440;
  97. };
  98. /* conversion functions */
  99. static struct s3c2410_nand_mtd *s3c2410_nand_mtd_toours(struct mtd_info *mtd)
  100. {
  101. return container_of(mtd, struct s3c2410_nand_mtd, mtd);
  102. }
  103. static struct s3c2410_nand_info *s3c2410_nand_mtd_toinfo(struct mtd_info *mtd)
  104. {
  105. return s3c2410_nand_mtd_toours(mtd)->info;
  106. }
  107. static struct s3c2410_nand_info *to_nand_info(struct platform_device *dev)
  108. {
  109. return platform_get_drvdata(dev);
  110. }
  111. static struct s3c2410_platform_nand *to_nand_plat(struct platform_device *dev)
  112. {
  113. return dev->dev.platform_data;
  114. }
  115. /* timing calculations */
  116. #define NS_IN_KHZ 1000000
  117. static int s3c2410_nand_calc_rate(int wanted, unsigned long clk, int max)
  118. {
  119. int result;
  120. result = (wanted * clk) / NS_IN_KHZ;
  121. result++;
  122. pr_debug("result %d from %ld, %d\n", result, clk, wanted);
  123. if (result > max) {
  124. printk("%d ns is too big for current clock rate %ld\n", wanted, clk);
  125. return -1;
  126. }
  127. if (result < 1)
  128. result = 1;
  129. return result;
  130. }
  131. #define to_ns(ticks,clk) (((ticks) * NS_IN_KHZ) / (unsigned int)(clk))
  132. /* controller setup */
  133. static int s3c2410_nand_inithw(struct s3c2410_nand_info *info, struct platform_device *pdev)
  134. {
  135. struct s3c2410_platform_nand *plat = to_nand_plat(pdev);
  136. unsigned long clkrate = clk_get_rate(info->clk);
  137. int tacls, twrph0, twrph1;
  138. unsigned long cfg;
  139. /* calculate the timing information for the controller */
  140. clkrate /= 1000; /* turn clock into kHz for ease of use */
  141. if (plat != NULL) {
  142. tacls = s3c2410_nand_calc_rate(plat->tacls, clkrate, 4);
  143. twrph0 = s3c2410_nand_calc_rate(plat->twrph0, clkrate, 8);
  144. twrph1 = s3c2410_nand_calc_rate(plat->twrph1, clkrate, 8);
  145. } else {
  146. /* default timings */
  147. tacls = 4;
  148. twrph0 = 8;
  149. twrph1 = 8;
  150. }
  151. if (tacls < 0 || twrph0 < 0 || twrph1 < 0) {
  152. printk(KERN_ERR PFX "cannot get timings suitable for board\n");
  153. return -EINVAL;
  154. }
  155. printk(KERN_INFO PFX "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n",
  156. tacls, to_ns(tacls, clkrate), twrph0, to_ns(twrph0, clkrate), twrph1, to_ns(twrph1, clkrate));
  157. if (!info->is_s3c2440) {
  158. cfg = S3C2410_NFCONF_EN;
  159. cfg |= S3C2410_NFCONF_TACLS(tacls - 1);
  160. cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1);
  161. cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1);
  162. } else {
  163. cfg = S3C2440_NFCONF_TACLS(tacls - 1);
  164. cfg |= S3C2440_NFCONF_TWRPH0(twrph0 - 1);
  165. cfg |= S3C2440_NFCONF_TWRPH1(twrph1 - 1);
  166. }
  167. pr_debug(PFX "NF_CONF is 0x%lx\n", cfg);
  168. writel(cfg, info->regs + S3C2410_NFCONF);
  169. return 0;
  170. }
  171. /* select chip */
  172. static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
  173. {
  174. struct s3c2410_nand_info *info;
  175. struct s3c2410_nand_mtd *nmtd;
  176. struct nand_chip *this = mtd->priv;
  177. void __iomem *reg;
  178. unsigned long cur;
  179. unsigned long bit;
  180. nmtd = this->priv;
  181. info = nmtd->info;
  182. bit = (info->is_s3c2440) ? S3C2440_NFCONT_nFCE : S3C2410_NFCONF_nFCE;
  183. reg = info->regs + ((info->is_s3c2440) ? S3C2440_NFCONT : S3C2410_NFCONF);
  184. cur = readl(reg);
  185. if (chip == -1) {
  186. cur |= bit;
  187. } else {
  188. if (nmtd->set != NULL && chip > nmtd->set->nr_chips) {
  189. printk(KERN_ERR PFX "chip %d out of range\n", chip);
  190. return;
  191. }
  192. if (info->platform != NULL) {
  193. if (info->platform->select_chip != NULL)
  194. (info->platform->select_chip) (nmtd->set, chip);
  195. }
  196. cur &= ~bit;
  197. }
  198. writel(cur, reg);
  199. }
  200. /* command and control functions
  201. *
  202. * Note, these all use tglx's method of changing the IO_ADDR_W field
  203. * to make the code simpler, and use the nand layer's code to issue the
  204. * command and address sequences via the proper IO ports.
  205. *
  206. */
  207. static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd)
  208. {
  209. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  210. struct nand_chip *chip = mtd->priv;
  211. switch (cmd) {
  212. case NAND_CTL_SETNCE:
  213. case NAND_CTL_CLRNCE:
  214. printk(KERN_ERR "%s: called for NCE\n", __FUNCTION__);
  215. break;
  216. case NAND_CTL_SETCLE:
  217. chip->IO_ADDR_W = info->regs + S3C2410_NFCMD;
  218. break;
  219. case NAND_CTL_SETALE:
  220. chip->IO_ADDR_W = info->regs + S3C2410_NFADDR;
  221. break;
  222. /* NAND_CTL_CLRCLE: */
  223. /* NAND_CTL_CLRALE: */
  224. default:
  225. chip->IO_ADDR_W = info->regs + S3C2410_NFDATA;
  226. break;
  227. }
  228. }
  229. /* command and control functions */
  230. static void s3c2440_nand_hwcontrol(struct mtd_info *mtd, int cmd)
  231. {
  232. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  233. struct nand_chip *chip = mtd->priv;
  234. switch (cmd) {
  235. case NAND_CTL_SETNCE:
  236. case NAND_CTL_CLRNCE:
  237. printk(KERN_ERR "%s: called for NCE\n", __FUNCTION__);
  238. break;
  239. case NAND_CTL_SETCLE:
  240. chip->IO_ADDR_W = info->regs + S3C2440_NFCMD;
  241. break;
  242. case NAND_CTL_SETALE:
  243. chip->IO_ADDR_W = info->regs + S3C2440_NFADDR;
  244. break;
  245. /* NAND_CTL_CLRCLE: */
  246. /* NAND_CTL_CLRALE: */
  247. default:
  248. chip->IO_ADDR_W = info->regs + S3C2440_NFDATA;
  249. break;
  250. }
  251. }
  252. /* s3c2410_nand_devready()
  253. *
  254. * returns 0 if the nand is busy, 1 if it is ready
  255. */
  256. static int s3c2410_nand_devready(struct mtd_info *mtd)
  257. {
  258. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  259. if (info->is_s3c2440)
  260. return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY;
  261. return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
  262. }
  263. /* ECC handling functions */
  264. static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc)
  265. {
  266. pr_debug("s3c2410_nand_correct_data(%p,%p,%p,%p)\n", mtd, dat, read_ecc, calc_ecc);
  267. pr_debug("eccs: read %02x,%02x,%02x vs calc %02x,%02x,%02x\n",
  268. read_ecc[0], read_ecc[1], read_ecc[2], calc_ecc[0], calc_ecc[1], calc_ecc[2]);
  269. if (read_ecc[0] == calc_ecc[0] && read_ecc[1] == calc_ecc[1] && read_ecc[2] == calc_ecc[2])
  270. return 0;
  271. /* we curently have no method for correcting the error */
  272. return -1;
  273. }
  274. /* ECC functions
  275. *
  276. * These allow the s3c2410 and s3c2440 to use the controller's ECC
  277. * generator block to ECC the data as it passes through]
  278. */
  279. static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode)
  280. {
  281. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  282. unsigned long ctrl;
  283. ctrl = readl(info->regs + S3C2410_NFCONF);
  284. ctrl |= S3C2410_NFCONF_INITECC;
  285. writel(ctrl, info->regs + S3C2410_NFCONF);
  286. }
  287. static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
  288. {
  289. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  290. unsigned long ctrl;
  291. ctrl = readl(info->regs + S3C2440_NFCONT);
  292. writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT);
  293. }
  294. static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
  295. {
  296. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  297. ecc_code[0] = readb(info->regs + S3C2410_NFECC + 0);
  298. ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1);
  299. ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2);
  300. pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]);
  301. return 0;
  302. }
  303. static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
  304. {
  305. struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
  306. unsigned long ecc = readl(info->regs + S3C2440_NFMECC0);
  307. ecc_code[0] = ecc;
  308. ecc_code[1] = ecc >> 8;
  309. ecc_code[2] = ecc >> 16;
  310. pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]);
  311. return 0;
  312. }
  313. /* over-ride the standard functions for a little more speed. We can
  314. * use read/write block to move the data buffers to/from the controller
  315. */
  316. static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
  317. {
  318. struct nand_chip *this = mtd->priv;
  319. readsb(this->IO_ADDR_R, buf, len);
  320. }
  321. static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
  322. {
  323. struct nand_chip *this = mtd->priv;
  324. writesb(this->IO_ADDR_W, buf, len);
  325. }
  326. /* device management functions */
  327. static int s3c2410_nand_remove(struct platform_device *pdev)
  328. {
  329. struct s3c2410_nand_info *info = to_nand_info(pdev);
  330. platform_set_drvdata(pdev, NULL);
  331. if (info == NULL)
  332. return 0;
  333. /* first thing we need to do is release all our mtds
  334. * and their partitions, then go through freeing the
  335. * resources used
  336. */
  337. if (info->mtds != NULL) {
  338. struct s3c2410_nand_mtd *ptr = info->mtds;
  339. int mtdno;
  340. for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) {
  341. pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
  342. nand_release(&ptr->mtd);
  343. }
  344. kfree(info->mtds);
  345. }
  346. /* free the common resources */
  347. if (info->clk != NULL && !IS_ERR(info->clk)) {
  348. clk_disable(info->clk);
  349. clk_put(info->clk);
  350. }
  351. if (info->regs != NULL) {
  352. iounmap(info->regs);
  353. info->regs = NULL;
  354. }
  355. if (info->area != NULL) {
  356. release_resource(info->area);
  357. kfree(info->area);
  358. info->area = NULL;
  359. }
  360. kfree(info);
  361. return 0;
  362. }
  363. #ifdef CONFIG_MTD_PARTITIONS
  364. static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
  365. struct s3c2410_nand_mtd *mtd,
  366. struct s3c2410_nand_set *set)
  367. {
  368. if (set == NULL)
  369. return add_mtd_device(&mtd->mtd);
  370. if (set->nr_partitions > 0 && set->partitions != NULL) {
  371. return add_mtd_partitions(&mtd->mtd, set->partitions, set->nr_partitions);
  372. }
  373. return add_mtd_device(&mtd->mtd);
  374. }
  375. #else
  376. static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
  377. struct s3c2410_nand_mtd *mtd,
  378. struct s3c2410_nand_set *set)
  379. {
  380. return add_mtd_device(&mtd->mtd);
  381. }
  382. #endif
  383. /* s3c2410_nand_init_chip
  384. *
  385. * init a single instance of an chip
  386. */
  387. static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
  388. struct s3c2410_nand_mtd *nmtd,
  389. struct s3c2410_nand_set *set)
  390. {
  391. struct nand_chip *chip = &nmtd->chip;
  392. chip->IO_ADDR_R = info->regs + S3C2410_NFDATA;
  393. chip->IO_ADDR_W = info->regs + S3C2410_NFDATA;
  394. chip->hwcontrol = s3c2410_nand_hwcontrol;
  395. chip->dev_ready = s3c2410_nand_devready;
  396. chip->write_buf = s3c2410_nand_write_buf;
  397. chip->read_buf = s3c2410_nand_read_buf;
  398. chip->select_chip = s3c2410_nand_select_chip;
  399. chip->chip_delay = 50;
  400. chip->priv = nmtd;
  401. chip->options = 0;
  402. chip->controller = &info->controller;
  403. if (info->is_s3c2440) {
  404. chip->IO_ADDR_R = info->regs + S3C2440_NFDATA;
  405. chip->IO_ADDR_W = info->regs + S3C2440_NFDATA;
  406. chip->hwcontrol = s3c2440_nand_hwcontrol;
  407. }
  408. nmtd->info = info;
  409. nmtd->mtd.priv = chip;
  410. nmtd->set = set;
  411. if (hardware_ecc) {
  412. chip->correct_data = s3c2410_nand_correct_data;
  413. chip->enable_hwecc = s3c2410_nand_enable_hwecc;
  414. chip->calculate_ecc = s3c2410_nand_calculate_ecc;
  415. chip->eccmode = NAND_ECC_HW3_512;
  416. chip->autooob = &nand_hw_eccoob;
  417. if (info->is_s3c2440) {
  418. chip->enable_hwecc = s3c2440_nand_enable_hwecc;
  419. chip->calculate_ecc = s3c2440_nand_calculate_ecc;
  420. }
  421. } else {
  422. chip->eccmode = NAND_ECC_SOFT;
  423. }
  424. }
  425. /* s3c2410_nand_probe
  426. *
  427. * called by device layer when it finds a device matching
  428. * one our driver can handled. This code checks to see if
  429. * it can allocate all necessary resources then calls the
  430. * nand layer to look for devices
  431. */
  432. static int s3c24xx_nand_probe(struct platform_device *pdev, int is_s3c2440)
  433. {
  434. struct s3c2410_platform_nand *plat = to_nand_plat(pdev);
  435. struct s3c2410_nand_info *info;
  436. struct s3c2410_nand_mtd *nmtd;
  437. struct s3c2410_nand_set *sets;
  438. struct resource *res;
  439. int err = 0;
  440. int size;
  441. int nr_sets;
  442. int setno;
  443. pr_debug("s3c2410_nand_probe(%p)\n", pdev);
  444. info = kmalloc(sizeof(*info), GFP_KERNEL);
  445. if (info == NULL) {
  446. dev_err(&pdev->dev, "no memory for flash info\n");
  447. err = -ENOMEM;
  448. goto exit_error;
  449. }
  450. memzero(info, sizeof(*info));
  451. platform_set_drvdata(pdev, info);
  452. spin_lock_init(&info->controller.lock);
  453. init_waitqueue_head(&info->controller.wq);
  454. /* get the clock source and enable it */
  455. info->clk = clk_get(&pdev->dev, "nand");
  456. if (IS_ERR(info->clk)) {
  457. dev_err(&pdev->dev, "failed to get clock");
  458. err = -ENOENT;
  459. goto exit_error;
  460. }
  461. clk_enable(info->clk);
  462. /* allocate and map the resource */
  463. /* currently we assume we have the one resource */
  464. res = pdev->resource;
  465. size = res->end - res->start + 1;
  466. info->area = request_mem_region(res->start, size, pdev->name);
  467. if (info->area == NULL) {
  468. dev_err(&pdev->dev, "cannot reserve register region\n");
  469. err = -ENOENT;
  470. goto exit_error;
  471. }
  472. info->device = &pdev->dev;
  473. info->platform = plat;
  474. info->regs = ioremap(res->start, size);
  475. info->is_s3c2440 = is_s3c2440;
  476. if (info->regs == NULL) {
  477. dev_err(&pdev->dev, "cannot reserve register region\n");
  478. err = -EIO;
  479. goto exit_error;
  480. }
  481. dev_dbg(&pdev->dev, "mapped registers at %p\n", info->regs);
  482. /* initialise the hardware */
  483. err = s3c2410_nand_inithw(info, pdev);
  484. if (err != 0)
  485. goto exit_error;
  486. sets = (plat != NULL) ? plat->sets : NULL;
  487. nr_sets = (plat != NULL) ? plat->nr_sets : 1;
  488. info->mtd_count = nr_sets;
  489. /* allocate our information */
  490. size = nr_sets * sizeof(*info->mtds);
  491. info->mtds = kmalloc(size, GFP_KERNEL);
  492. if (info->mtds == NULL) {
  493. dev_err(&pdev->dev, "failed to allocate mtd storage\n");
  494. err = -ENOMEM;
  495. goto exit_error;
  496. }
  497. memzero(info->mtds, size);
  498. /* initialise all possible chips */
  499. nmtd = info->mtds;
  500. for (setno = 0; setno < nr_sets; setno++, nmtd++) {
  501. pr_debug("initialising set %d (%p, info %p)\n", setno, nmtd, info);
  502. s3c2410_nand_init_chip(info, nmtd, sets);
  503. nmtd->scan_res = nand_scan(&nmtd->mtd, (sets) ? sets->nr_chips : 1);
  504. if (nmtd->scan_res == 0) {
  505. s3c2410_nand_add_partition(info, nmtd, sets);
  506. }
  507. if (sets != NULL)
  508. sets++;
  509. }
  510. pr_debug("initialised ok\n");
  511. return 0;
  512. exit_error:
  513. s3c2410_nand_remove(pdev);
  514. if (err == 0)
  515. err = -EINVAL;
  516. return err;
  517. }
  518. /* driver device registration */
  519. static int s3c2410_nand_probe(struct platform_device *dev)
  520. {
  521. return s3c24xx_nand_probe(dev, 0);
  522. }
  523. static int s3c2440_nand_probe(struct platform_device *dev)
  524. {
  525. return s3c24xx_nand_probe(dev, 1);
  526. }
  527. static struct platform_driver s3c2410_nand_driver = {
  528. .probe = s3c2410_nand_probe,
  529. .remove = s3c2410_nand_remove,
  530. .driver = {
  531. .name = "s3c2410-nand",
  532. .owner = THIS_MODULE,
  533. },
  534. };
  535. static struct platform_driver s3c2440_nand_driver = {
  536. .probe = s3c2440_nand_probe,
  537. .remove = s3c2410_nand_remove,
  538. .driver = {
  539. .name = "s3c2440-nand",
  540. .owner = THIS_MODULE,
  541. },
  542. };
  543. static int __init s3c2410_nand_init(void)
  544. {
  545. printk("S3C24XX NAND Driver, (c) 2004 Simtec Electronics\n");
  546. platform_driver_register(&s3c2440_nand_driver);
  547. return platform_driver_register(&s3c2410_nand_driver);
  548. }
  549. static void __exit s3c2410_nand_exit(void)
  550. {
  551. platform_driver_unregister(&s3c2440_nand_driver);
  552. platform_driver_unregister(&s3c2410_nand_driver);
  553. }
  554. module_init(s3c2410_nand_init);
  555. module_exit(s3c2410_nand_exit);
  556. MODULE_LICENSE("GPL");
  557. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  558. MODULE_DESCRIPTION("S3C24XX MTD NAND driver");