s3c2410.c 17 KB

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