blob: 35c6db54c985e160b1c77d694717e367d292cbdb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/drivers/mtd/nand/s3c2410.c
2 *
Ben Dooks7e74a502008-05-20 17:32:27 +01003 * Copyright © 2004-2008 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
Ben Dooksfdf2fd52005-02-18 14:46:15 +00005 * Ben Dooks <ben@simtec.co.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
Ben Dooks7e74a502008-05-20 17:32:27 +01007 * Samsung S3C2410/S3C2440/S3C2412 NAND driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#ifdef CONFIG_MTD_NAND_S3C2410_DEBUG
25#define DEBUG
26#endif
27
28#include <linux/module.h>
29#include <linux/types.h>
30#include <linux/init.h>
31#include <linux/kernel.h>
32#include <linux/string.h>
33#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010034#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/delay.h>
36#include <linux/err.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080037#include <linux/slab.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000038#include <linux/clk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#include <linux/mtd/mtd.h>
41#include <linux/mtd/nand.h>
42#include <linux/mtd/nand_ecc.h>
43#include <linux/mtd/partitions.h>
44
45#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Ben Dooksb7a70182007-07-24 13:37:27 +010047#include <asm/plat-s3c/regs-nand.h>
48#include <asm/plat-s3c/nand.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#ifdef CONFIG_MTD_NAND_S3C2410_HWECC
51static int hardware_ecc = 1;
52#else
53static int hardware_ecc = 0;
54#endif
55
Ben Dooksd1fef3c2006-06-19 09:29:38 +010056#ifdef CONFIG_MTD_NAND_S3C2410_CLKSTOP
57static int clock_stop = 1;
58#else
59static const int clock_stop = 0;
60#endif
61
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/* new oob placement block for use with hardware ecc generation
64 */
65
Thomas Gleixner5bd34c02006-05-27 22:16:10 +020066static struct nand_ecclayout nand_hw_eccoob = {
David Woodhousee0c7d762006-05-13 18:07:53 +010067 .eccbytes = 3,
68 .eccpos = {0, 1, 2},
69 .oobfree = {{8, 8}}
Linus Torvalds1da177e2005-04-16 15:20:36 -070070};
71
72/* controller and mtd information */
73
74struct s3c2410_nand_info;
75
76struct 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
Ben Dooks2c06a082006-06-27 14:35:46 +010084enum s3c_cpu_type {
85 TYPE_S3C2410,
86 TYPE_S3C2412,
87 TYPE_S3C2440,
88};
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090/* overview of the s3c2410 nand state */
91
92struct s3c2410_nand_info {
93 /* mtd info */
94 struct nand_hw_control controller;
95 struct s3c2410_nand_mtd *mtds;
96 struct s3c2410_platform_nand *platform;
97
98 /* device info */
99 struct device *device;
100 struct resource *area;
101 struct clk *clk;
Ben Dooksfdf2fd52005-02-18 14:46:15 +0000102 void __iomem *regs;
Ben Dooks2c06a082006-06-27 14:35:46 +0100103 void __iomem *sel_reg;
104 int sel_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 int mtd_count;
Ben Dooks09160832008-04-15 11:36:18 +0100106 unsigned long save_sel;
Ben Dooks03680b12007-11-19 23:28:07 +0000107
Ben Dooks2c06a082006-06-27 14:35:46 +0100108 enum s3c_cpu_type cpu_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109};
110
111/* conversion functions */
112
113static struct s3c2410_nand_mtd *s3c2410_nand_mtd_toours(struct mtd_info *mtd)
114{
115 return container_of(mtd, struct s3c2410_nand_mtd, mtd);
116}
117
118static struct s3c2410_nand_info *s3c2410_nand_mtd_toinfo(struct mtd_info *mtd)
119{
120 return s3c2410_nand_mtd_toours(mtd)->info;
121}
122
Russell King3ae5eae2005-11-09 22:32:44 +0000123static struct s3c2410_nand_info *to_nand_info(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Russell King3ae5eae2005-11-09 22:32:44 +0000125 return platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Russell King3ae5eae2005-11-09 22:32:44 +0000128static struct s3c2410_platform_nand *to_nand_plat(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Russell King3ae5eae2005-11-09 22:32:44 +0000130 return dev->dev.platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100133static inline int allow_clk_stop(struct s3c2410_nand_info *info)
134{
135 return clock_stop;
136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/* timing calculations */
139
Ben Dookscfd320f2005-10-20 22:22:58 +0100140#define NS_IN_KHZ 1000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Ben Dooks2c06a082006-06-27 14:35:46 +0100142static int s3c_nand_calc_rate(int wanted, unsigned long clk, int max)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
144 int result;
145
Ben Dookscfd320f2005-10-20 22:22:58 +0100146 result = (wanted * clk) / NS_IN_KHZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 result++;
148
149 pr_debug("result %d from %ld, %d\n", result, clk, wanted);
150
151 if (result > max) {
David Woodhousee0c7d762006-05-13 18:07:53 +0100152 printk("%d ns is too big for current clock rate %ld\n", wanted, clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return -1;
154 }
155
156 if (result < 1)
157 result = 1;
158
159 return result;
160}
161
Ben Dookscfd320f2005-10-20 22:22:58 +0100162#define to_ns(ticks,clk) (((ticks) * NS_IN_KHZ) / (unsigned int)(clk))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164/* controller setup */
165
Ben Dooks2c06a082006-06-27 14:35:46 +0100166static int s3c2410_nand_inithw(struct s3c2410_nand_info *info,
167 struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Russell King3ae5eae2005-11-09 22:32:44 +0000169 struct s3c2410_platform_nand *plat = to_nand_plat(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 unsigned long clkrate = clk_get_rate(info->clk);
Ben Dooks2c06a082006-06-27 14:35:46 +0100171 int tacls_max = (info->cpu_type == TYPE_S3C2412) ? 8 : 4;
Ben Dookscfd320f2005-10-20 22:22:58 +0100172 int tacls, twrph0, twrph1;
Ben Dooks2c06a082006-06-27 14:35:46 +0100173 unsigned long cfg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 /* calculate the timing information for the controller */
176
Ben Dookscfd320f2005-10-20 22:22:58 +0100177 clkrate /= 1000; /* turn clock into kHz for ease of use */
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 if (plat != NULL) {
Ben Dooks2c06a082006-06-27 14:35:46 +0100180 tacls = s3c_nand_calc_rate(plat->tacls, clkrate, tacls_max);
181 twrph0 = s3c_nand_calc_rate(plat->twrph0, clkrate, 8);
182 twrph1 = s3c_nand_calc_rate(plat->twrph1, clkrate, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 } else {
184 /* default timings */
Ben Dooks2c06a082006-06-27 14:35:46 +0100185 tacls = tacls_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 twrph0 = 8;
187 twrph1 = 8;
188 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (tacls < 0 || twrph0 < 0 || twrph1 < 0) {
Ben Dooks99974c62006-06-21 15:43:05 +0100191 dev_err(info->device, "cannot get suitable timings\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return -EINVAL;
193 }
194
Ben Dooks99974c62006-06-21 15:43:05 +0100195 dev_info(info->device, "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n",
David Woodhousee0c7d762006-05-13 18:07:53 +0100196 tacls, to_ns(tacls, clkrate), twrph0, to_ns(twrph0, clkrate), twrph1, to_ns(twrph1, clkrate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Ben Dooks2c06a082006-06-27 14:35:46 +0100198 switch (info->cpu_type) {
199 case TYPE_S3C2410:
David Woodhousee0c7d762006-05-13 18:07:53 +0100200 cfg = S3C2410_NFCONF_EN;
201 cfg |= S3C2410_NFCONF_TACLS(tacls - 1);
202 cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1);
203 cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1);
Ben Dooks2c06a082006-06-27 14:35:46 +0100204 break;
205
206 case TYPE_S3C2440:
207 case TYPE_S3C2412:
David Woodhousee0c7d762006-05-13 18:07:53 +0100208 cfg = S3C2440_NFCONF_TACLS(tacls - 1);
209 cfg |= S3C2440_NFCONF_TWRPH0(twrph0 - 1);
210 cfg |= S3C2440_NFCONF_TWRPH1(twrph1 - 1);
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100211
212 /* enable the controller and de-assert nFCE */
213
Ben Dooks2c06a082006-06-27 14:35:46 +0100214 writel(S3C2440_NFCONT_ENABLE, info->regs + S3C2440_NFCONT);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Ben Dooks99974c62006-06-21 15:43:05 +0100217 dev_dbg(info->device, "NF_CONF is 0x%lx\n", cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 writel(cfg, info->regs + S3C2410_NFCONF);
220 return 0;
221}
222
223/* select chip */
224
225static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
226{
227 struct s3c2410_nand_info *info;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000228 struct s3c2410_nand_mtd *nmtd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 struct nand_chip *this = mtd->priv;
230 unsigned long cur;
231
232 nmtd = this->priv;
233 info = nmtd->info;
234
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100235 if (chip != -1 && allow_clk_stop(info))
236 clk_enable(info->clk);
237
Ben Dooks2c06a082006-06-27 14:35:46 +0100238 cur = readl(info->sel_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 if (chip == -1) {
Ben Dooks2c06a082006-06-27 14:35:46 +0100241 cur |= info->sel_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 } else {
Ben Dooksfb8d82a2005-07-06 21:05:10 +0100243 if (nmtd->set != NULL && chip > nmtd->set->nr_chips) {
Ben Dooks99974c62006-06-21 15:43:05 +0100244 dev_err(info->device, "invalid chip %d\n", chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 return;
246 }
247
248 if (info->platform != NULL) {
249 if (info->platform->select_chip != NULL)
David Woodhousee0c7d762006-05-13 18:07:53 +0100250 (info->platform->select_chip) (nmtd->set, chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
252
Ben Dooks2c06a082006-06-27 14:35:46 +0100253 cur &= ~info->sel_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
255
Ben Dooks2c06a082006-06-27 14:35:46 +0100256 writel(cur, info->sel_reg);
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100257
258 if (chip == -1 && allow_clk_stop(info))
259 clk_disable(info->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
261
Ben Dooksad3b5fb2006-06-19 09:43:23 +0100262/* s3c2410_nand_hwcontrol
Ben Dooksa4f957f2005-06-20 12:48:25 +0100263 *
Ben Dooksad3b5fb2006-06-19 09:43:23 +0100264 * Issue command and address cycles to the chip
Ben Dooksa4f957f2005-06-20 12:48:25 +0100265*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200267static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd,
David Woodhousef9068872006-06-10 00:53:16 +0100268 unsigned int ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
270 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
David Woodhousec9ac5972006-11-30 08:17:38 +0000271
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200272 if (cmd == NAND_CMD_NONE)
273 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
David Woodhousef9068872006-06-10 00:53:16 +0100275 if (ctrl & NAND_CLE)
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200276 writeb(cmd, info->regs + S3C2410_NFCMD);
277 else
278 writeb(cmd, info->regs + S3C2410_NFADDR);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100279}
280
281/* command and control functions */
282
David Woodhousef9068872006-06-10 00:53:16 +0100283static void s3c2440_nand_hwcontrol(struct mtd_info *mtd, int cmd,
284 unsigned int ctrl)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100285{
286 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100287
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200288 if (cmd == NAND_CMD_NONE)
289 return;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100290
David Woodhousef9068872006-06-10 00:53:16 +0100291 if (ctrl & NAND_CLE)
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200292 writeb(cmd, info->regs + S3C2440_NFCMD);
293 else
294 writeb(cmd, info->regs + S3C2440_NFADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297/* s3c2410_nand_devready()
298 *
299 * returns 0 if the nand is busy, 1 if it is ready
300*/
301
302static int s3c2410_nand_devready(struct mtd_info *mtd)
303{
304 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
306}
307
Ben Dooks2c06a082006-06-27 14:35:46 +0100308static int s3c2440_nand_devready(struct mtd_info *mtd)
309{
310 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
311 return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY;
312}
313
314static int s3c2412_nand_devready(struct mtd_info *mtd)
315{
316 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
317 return readb(info->regs + S3C2412_NFSTAT) & S3C2412_NFSTAT_READY;
318}
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320/* ECC handling functions */
321
Ben Dooks2c06a082006-06-27 14:35:46 +0100322static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
323 u_char *read_ecc, u_char *calc_ecc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Ben Dooksa2593242007-02-02 16:59:33 +0000325 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
326 unsigned int diff0, diff1, diff2;
327 unsigned int bit, byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Ben Dooksa2593242007-02-02 16:59:33 +0000329 pr_debug("%s(%p,%p,%p,%p)\n", __func__, mtd, dat, read_ecc, calc_ecc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Ben Dooksa2593242007-02-02 16:59:33 +0000331 diff0 = read_ecc[0] ^ calc_ecc[0];
332 diff1 = read_ecc[1] ^ calc_ecc[1];
333 diff2 = read_ecc[2] ^ calc_ecc[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Ben Dooksa2593242007-02-02 16:59:33 +0000335 pr_debug("%s: rd %02x%02x%02x calc %02x%02x%02x diff %02x%02x%02x\n",
336 __func__,
337 read_ecc[0], read_ecc[1], read_ecc[2],
338 calc_ecc[0], calc_ecc[1], calc_ecc[2],
339 diff0, diff1, diff2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Ben Dooksa2593242007-02-02 16:59:33 +0000341 if (diff0 == 0 && diff1 == 0 && diff2 == 0)
342 return 0; /* ECC is ok */
343
Ben Dooksc45c6c62008-04-15 11:36:20 +0100344 /* sometimes people do not think about using the ECC, so check
345 * to see if we have an 0xff,0xff,0xff read ECC and then ignore
346 * the error, on the assumption that this is an un-eccd page.
347 */
348 if (read_ecc[0] == 0xff && read_ecc[1] == 0xff && read_ecc[2] == 0xff
349 && info->platform->ignore_unset_ecc)
350 return 0;
351
Ben Dooksa2593242007-02-02 16:59:33 +0000352 /* Can we correct this ECC (ie, one row and column change).
353 * Note, this is similar to the 256 error code on smartmedia */
354
355 if (((diff0 ^ (diff0 >> 1)) & 0x55) == 0x55 &&
356 ((diff1 ^ (diff1 >> 1)) & 0x55) == 0x55 &&
357 ((diff2 ^ (diff2 >> 1)) & 0x55) == 0x55) {
358 /* calculate the bit position of the error */
359
Matt Reimerd0bf3792007-10-18 18:02:43 -0700360 bit = ((diff2 >> 3) & 1) |
361 ((diff2 >> 4) & 2) |
362 ((diff2 >> 5) & 4);
Ben Dooksa2593242007-02-02 16:59:33 +0000363
364 /* calculate the byte position of the error */
365
Matt Reimerd0bf3792007-10-18 18:02:43 -0700366 byte = ((diff2 << 7) & 0x100) |
367 ((diff1 << 0) & 0x80) |
368 ((diff1 << 1) & 0x40) |
369 ((diff1 << 2) & 0x20) |
370 ((diff1 << 3) & 0x10) |
371 ((diff0 >> 4) & 0x08) |
372 ((diff0 >> 3) & 0x04) |
373 ((diff0 >> 2) & 0x02) |
374 ((diff0 >> 1) & 0x01);
Ben Dooksa2593242007-02-02 16:59:33 +0000375
376 dev_dbg(info->device, "correcting error bit %d, byte %d\n",
377 bit, byte);
378
379 dat[byte] ^= (1 << bit);
380 return 1;
381 }
382
383 /* if there is only one bit difference in the ECC, then
384 * one of only a row or column parity has changed, which
385 * means the error is most probably in the ECC itself */
386
387 diff0 |= (diff1 << 8);
388 diff0 |= (diff2 << 16);
389
390 if ((diff0 & ~(1<<fls(diff0))) == 0)
391 return 1;
392
Matt Reimer4fac9f62007-10-18 18:02:44 -0700393 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
Ben Dooksa4f957f2005-06-20 12:48:25 +0100396/* ECC functions
397 *
398 * These allow the s3c2410 and s3c2440 to use the controller's ECC
399 * generator block to ECC the data as it passes through]
400*/
401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode)
403{
404 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
405 unsigned long ctrl;
406
407 ctrl = readl(info->regs + S3C2410_NFCONF);
408 ctrl |= S3C2410_NFCONF_INITECC;
409 writel(ctrl, info->regs + S3C2410_NFCONF);
410}
411
Matthieu CASTET4f659922007-02-13 12:30:38 +0100412static void s3c2412_nand_enable_hwecc(struct mtd_info *mtd, int mode)
413{
414 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
415 unsigned long ctrl;
416
417 ctrl = readl(info->regs + S3C2440_NFCONT);
418 writel(ctrl | S3C2412_NFCONT_INIT_MAIN_ECC, info->regs + S3C2440_NFCONT);
419}
420
Ben Dooksa4f957f2005-06-20 12:48:25 +0100421static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
422{
423 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
424 unsigned long ctrl;
425
426 ctrl = readl(info->regs + S3C2440_NFCONT);
427 writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT);
428}
429
David Woodhousee0c7d762006-05-13 18:07:53 +0100430static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
432 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
433
434 ecc_code[0] = readb(info->regs + S3C2410_NFECC + 0);
435 ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1);
436 ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2);
437
Ben Dooksa2593242007-02-02 16:59:33 +0000438 pr_debug("%s: returning ecc %02x%02x%02x\n", __func__,
439 ecc_code[0], ecc_code[1], ecc_code[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 return 0;
442}
443
Matthieu CASTET4f659922007-02-13 12:30:38 +0100444static int s3c2412_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
445{
446 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
447 unsigned long ecc = readl(info->regs + S3C2412_NFMECC0);
448
449 ecc_code[0] = ecc;
450 ecc_code[1] = ecc >> 8;
451 ecc_code[2] = ecc >> 16;
452
453 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]);
454
455 return 0;
456}
457
David Woodhousee0c7d762006-05-13 18:07:53 +0100458static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100459{
460 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
461 unsigned long ecc = readl(info->regs + S3C2440_NFMECC0);
462
463 ecc_code[0] = ecc;
464 ecc_code[1] = ecc >> 8;
465 ecc_code[2] = ecc >> 16;
466
Ben Dooks71d54f32008-04-15 11:36:19 +0100467 pr_debug("%s: returning ecc %06lx\n", __func__, ecc & 0xffffff);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100468
469 return 0;
470}
471
Ben Dooksa4f957f2005-06-20 12:48:25 +0100472/* over-ride the standard functions for a little more speed. We can
473 * use read/write block to move the data buffers to/from the controller
474*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
477{
478 struct nand_chip *this = mtd->priv;
479 readsb(this->IO_ADDR_R, buf, len);
480}
481
Matt Reimerb773bb22007-10-18 17:43:07 -0700482static void s3c2440_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
483{
484 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
485 readsl(info->regs + S3C2440_NFDATA, buf, len / 4);
486}
487
David Woodhousee0c7d762006-05-13 18:07:53 +0100488static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
490 struct nand_chip *this = mtd->priv;
491 writesb(this->IO_ADDR_W, buf, len);
492}
493
Matt Reimerb773bb22007-10-18 17:43:07 -0700494static void s3c2440_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
495{
496 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
497 writesl(info->regs + S3C2440_NFDATA, buf, len / 4);
498}
499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500/* device management functions */
501
Russell King3ae5eae2005-11-09 22:32:44 +0000502static int s3c2410_nand_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Russell King3ae5eae2005-11-09 22:32:44 +0000504 struct s3c2410_nand_info *info = to_nand_info(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Russell King3ae5eae2005-11-09 22:32:44 +0000506 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000508 if (info == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 return 0;
510
511 /* first thing we need to do is release all our mtds
512 * and their partitions, then go through freeing the
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000513 * resources used
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 */
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 if (info->mtds != NULL) {
517 struct s3c2410_nand_mtd *ptr = info->mtds;
518 int mtdno;
519
520 for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) {
521 pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
522 nand_release(&ptr->mtd);
523 }
524
525 kfree(info->mtds);
526 }
527
528 /* free the common resources */
529
530 if (info->clk != NULL && !IS_ERR(info->clk)) {
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100531 if (!allow_clk_stop(info))
532 clk_disable(info->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 clk_put(info->clk);
534 }
535
536 if (info->regs != NULL) {
537 iounmap(info->regs);
538 info->regs = NULL;
539 }
540
541 if (info->area != NULL) {
542 release_resource(info->area);
543 kfree(info->area);
544 info->area = NULL;
545 }
546
547 kfree(info);
548
549 return 0;
550}
551
552#ifdef CONFIG_MTD_PARTITIONS
553static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
554 struct s3c2410_nand_mtd *mtd,
555 struct s3c2410_nand_set *set)
556{
557 if (set == NULL)
558 return add_mtd_device(&mtd->mtd);
559
560 if (set->nr_partitions > 0 && set->partitions != NULL) {
David Woodhousee0c7d762006-05-13 18:07:53 +0100561 return add_mtd_partitions(&mtd->mtd, set->partitions, set->nr_partitions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
563
564 return add_mtd_device(&mtd->mtd);
565}
566#else
567static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
568 struct s3c2410_nand_mtd *mtd,
569 struct s3c2410_nand_set *set)
570{
571 return add_mtd_device(&mtd->mtd);
572}
573#endif
574
575/* s3c2410_nand_init_chip
576 *
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000577 * init a single instance of an chip
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578*/
579
580static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
581 struct s3c2410_nand_mtd *nmtd,
582 struct s3c2410_nand_set *set)
583{
584 struct nand_chip *chip = &nmtd->chip;
Ben Dooks2c06a082006-06-27 14:35:46 +0100585 void __iomem *regs = info->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 chip->write_buf = s3c2410_nand_write_buf;
588 chip->read_buf = s3c2410_nand_read_buf;
589 chip->select_chip = s3c2410_nand_select_chip;
590 chip->chip_delay = 50;
591 chip->priv = nmtd;
592 chip->options = 0;
593 chip->controller = &info->controller;
594
Ben Dooks2c06a082006-06-27 14:35:46 +0100595 switch (info->cpu_type) {
596 case TYPE_S3C2410:
597 chip->IO_ADDR_W = regs + S3C2410_NFDATA;
598 info->sel_reg = regs + S3C2410_NFCONF;
599 info->sel_bit = S3C2410_NFCONF_nFCE;
600 chip->cmd_ctrl = s3c2410_nand_hwcontrol;
601 chip->dev_ready = s3c2410_nand_devready;
602 break;
603
604 case TYPE_S3C2440:
605 chip->IO_ADDR_W = regs + S3C2440_NFDATA;
606 info->sel_reg = regs + S3C2440_NFCONT;
607 info->sel_bit = S3C2440_NFCONT_nFCE;
608 chip->cmd_ctrl = s3c2440_nand_hwcontrol;
609 chip->dev_ready = s3c2440_nand_devready;
Matt Reimerb773bb22007-10-18 17:43:07 -0700610 chip->read_buf = s3c2440_nand_read_buf;
611 chip->write_buf = s3c2440_nand_write_buf;
Ben Dooks2c06a082006-06-27 14:35:46 +0100612 break;
613
614 case TYPE_S3C2412:
615 chip->IO_ADDR_W = regs + S3C2440_NFDATA;
616 info->sel_reg = regs + S3C2440_NFCONT;
617 info->sel_bit = S3C2412_NFCONT_nFCE0;
618 chip->cmd_ctrl = s3c2440_nand_hwcontrol;
619 chip->dev_ready = s3c2412_nand_devready;
620
621 if (readl(regs + S3C2410_NFCONF) & S3C2412_NFCONF_NANDBOOT)
622 dev_info(info->device, "System booted from NAND\n");
623
624 break;
625 }
626
627 chip->IO_ADDR_R = chip->IO_ADDR_W;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 nmtd->info = info;
630 nmtd->mtd.priv = chip;
David Woodhouse552d9202006-05-14 01:20:46 +0100631 nmtd->mtd.owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 nmtd->set = set;
633
634 if (hardware_ecc) {
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200635 chip->ecc.calculate = s3c2410_nand_calculate_ecc;
Ben Dooks2c06a082006-06-27 14:35:46 +0100636 chip->ecc.correct = s3c2410_nand_correct_data;
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200637 chip->ecc.mode = NAND_ECC_HW;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100638
Ben Dooks2c06a082006-06-27 14:35:46 +0100639 switch (info->cpu_type) {
640 case TYPE_S3C2410:
641 chip->ecc.hwctl = s3c2410_nand_enable_hwecc;
642 chip->ecc.calculate = s3c2410_nand_calculate_ecc;
643 break;
644
645 case TYPE_S3C2412:
Matthieu CASTET4f659922007-02-13 12:30:38 +0100646 chip->ecc.hwctl = s3c2412_nand_enable_hwecc;
647 chip->ecc.calculate = s3c2412_nand_calculate_ecc;
648 break;
649
Ben Dooks2c06a082006-06-27 14:35:46 +0100650 case TYPE_S3C2440:
651 chip->ecc.hwctl = s3c2440_nand_enable_hwecc;
652 chip->ecc.calculate = s3c2440_nand_calculate_ecc;
653 break;
654
Ben Dooksa4f957f2005-06-20 12:48:25 +0100655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 } else {
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200657 chip->ecc.mode = NAND_ECC_SOFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
Ben Dooks1c21ab62008-04-15 11:36:21 +0100659
660 if (set->ecc_layout != NULL)
661 chip->ecc.layout = set->ecc_layout;
Ben Dooks37e5ffa2008-04-15 11:36:22 +0100662
663 if (set->disable_ecc)
664 chip->ecc.mode = NAND_ECC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
666
Ben Dooks71d54f32008-04-15 11:36:19 +0100667/* s3c2410_nand_update_chip
668 *
669 * post-probe chip update, to change any items, such as the
670 * layout for large page nand
671 */
672
673static void s3c2410_nand_update_chip(struct s3c2410_nand_info *info,
674 struct s3c2410_nand_mtd *nmtd)
675{
676 struct nand_chip *chip = &nmtd->chip;
677
Ben Dooks451d3392008-05-20 17:32:14 +0100678 dev_dbg(info->device, "chip %p => page shift %d\n",
679 chip, chip->page_shift);
Ben Dooks71d54f32008-04-15 11:36:19 +0100680
681 if (hardware_ecc) {
682 /* change the behaviour depending on wether we are using
683 * the large or small page nand device */
684
685 if (chip->page_shift > 10) {
686 chip->ecc.size = 256;
687 chip->ecc.bytes = 3;
688 } else {
689 chip->ecc.size = 512;
690 chip->ecc.bytes = 3;
691 chip->ecc.layout = &nand_hw_eccoob;
692 }
693 }
694}
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696/* s3c2410_nand_probe
697 *
698 * called by device layer when it finds a device matching
699 * one our driver can handled. This code checks to see if
700 * it can allocate all necessary resources then calls the
701 * nand layer to look for devices
702*/
703
Ben Dooks2c06a082006-06-27 14:35:46 +0100704static int s3c24xx_nand_probe(struct platform_device *pdev,
705 enum s3c_cpu_type cpu_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706{
Russell King3ae5eae2005-11-09 22:32:44 +0000707 struct s3c2410_platform_nand *plat = to_nand_plat(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 struct s3c2410_nand_info *info;
709 struct s3c2410_nand_mtd *nmtd;
710 struct s3c2410_nand_set *sets;
711 struct resource *res;
712 int err = 0;
713 int size;
714 int nr_sets;
715 int setno;
716
Russell King3ae5eae2005-11-09 22:32:44 +0000717 pr_debug("s3c2410_nand_probe(%p)\n", pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 info = kmalloc(sizeof(*info), GFP_KERNEL);
720 if (info == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000721 dev_err(&pdev->dev, "no memory for flash info\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 err = -ENOMEM;
723 goto exit_error;
724 }
725
726 memzero(info, sizeof(*info));
Russell King3ae5eae2005-11-09 22:32:44 +0000727 platform_set_drvdata(pdev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729 spin_lock_init(&info->controller.lock);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100730 init_waitqueue_head(&info->controller.wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
732 /* get the clock source and enable it */
733
Russell King3ae5eae2005-11-09 22:32:44 +0000734 info->clk = clk_get(&pdev->dev, "nand");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 if (IS_ERR(info->clk)) {
Joe Perches898eb712007-10-18 03:06:30 -0700736 dev_err(&pdev->dev, "failed to get clock\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 err = -ENOENT;
738 goto exit_error;
739 }
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 clk_enable(info->clk);
742
743 /* allocate and map the resource */
744
Ben Dooksa4f957f2005-06-20 12:48:25 +0100745 /* currently we assume we have the one resource */
746 res = pdev->resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 size = res->end - res->start + 1;
748
749 info->area = request_mem_region(res->start, size, pdev->name);
750
751 if (info->area == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000752 dev_err(&pdev->dev, "cannot reserve register region\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 err = -ENOENT;
754 goto exit_error;
755 }
756
Russell King3ae5eae2005-11-09 22:32:44 +0000757 info->device = &pdev->dev;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100758 info->platform = plat;
759 info->regs = ioremap(res->start, size);
Ben Dooks2c06a082006-06-27 14:35:46 +0100760 info->cpu_type = cpu_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 if (info->regs == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000763 dev_err(&pdev->dev, "cannot reserve register region\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 err = -EIO;
765 goto exit_error;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000766 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Russell King3ae5eae2005-11-09 22:32:44 +0000768 dev_dbg(&pdev->dev, "mapped registers at %p\n", info->regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770 /* initialise the hardware */
771
Russell King3ae5eae2005-11-09 22:32:44 +0000772 err = s3c2410_nand_inithw(info, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 if (err != 0)
774 goto exit_error;
775
776 sets = (plat != NULL) ? plat->sets : NULL;
777 nr_sets = (plat != NULL) ? plat->nr_sets : 1;
778
779 info->mtd_count = nr_sets;
780
781 /* allocate our information */
782
783 size = nr_sets * sizeof(*info->mtds);
784 info->mtds = kmalloc(size, GFP_KERNEL);
785 if (info->mtds == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000786 dev_err(&pdev->dev, "failed to allocate mtd storage\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 err = -ENOMEM;
788 goto exit_error;
789 }
790
791 memzero(info->mtds, size);
792
793 /* initialise all possible chips */
794
795 nmtd = info->mtds;
796
797 for (setno = 0; setno < nr_sets; setno++, nmtd++) {
David Woodhousee0c7d762006-05-13 18:07:53 +0100798 pr_debug("initialising set %d (%p, info %p)\n", setno, nmtd, info);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 s3c2410_nand_init_chip(info, nmtd, sets);
801
Ben Dooks71d54f32008-04-15 11:36:19 +0100802 nmtd->scan_res = nand_scan_ident(&nmtd->mtd,
803 (sets) ? sets->nr_chips : 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 if (nmtd->scan_res == 0) {
Ben Dooks71d54f32008-04-15 11:36:19 +0100806 s3c2410_nand_update_chip(info, nmtd);
807 nand_scan_tail(&nmtd->mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 s3c2410_nand_add_partition(info, nmtd, sets);
809 }
810
811 if (sets != NULL)
812 sets++;
813 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000814
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100815 if (allow_clk_stop(info)) {
816 dev_info(&pdev->dev, "clock idle support enabled\n");
817 clk_disable(info->clk);
818 }
819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 pr_debug("initialised ok\n");
821 return 0;
822
823 exit_error:
Russell King3ae5eae2005-11-09 22:32:44 +0000824 s3c2410_nand_remove(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 if (err == 0)
827 err = -EINVAL;
828 return err;
829}
830
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100831/* PM Support */
832#ifdef CONFIG_PM
833
834static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
835{
836 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
837
838 if (info) {
Ben Dooks09160832008-04-15 11:36:18 +0100839 info->save_sel = readl(info->sel_reg);
Ben Dooks03680b12007-11-19 23:28:07 +0000840
841 /* For the moment, we must ensure nFCE is high during
842 * the time we are suspended. This really should be
843 * handled by suspending the MTDs we are using, but
844 * that is currently not the case. */
845
Ben Dooks09160832008-04-15 11:36:18 +0100846 writel(info->save_sel | info->sel_bit, info->sel_reg);
Ben Dooks03680b12007-11-19 23:28:07 +0000847
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100848 if (!allow_clk_stop(info))
849 clk_disable(info->clk);
850 }
851
852 return 0;
853}
854
855static int s3c24xx_nand_resume(struct platform_device *dev)
856{
857 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
Ben Dooks09160832008-04-15 11:36:18 +0100858 unsigned long sel;
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100859
860 if (info) {
861 clk_enable(info->clk);
862 s3c2410_nand_inithw(info, dev);
863
Ben Dooks03680b12007-11-19 23:28:07 +0000864 /* Restore the state of the nFCE line. */
865
Ben Dooks09160832008-04-15 11:36:18 +0100866 sel = readl(info->sel_reg);
867 sel &= ~info->sel_bit;
868 sel |= info->save_sel & info->sel_bit;
869 writel(sel, info->sel_reg);
Ben Dooks03680b12007-11-19 23:28:07 +0000870
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100871 if (allow_clk_stop(info))
872 clk_disable(info->clk);
873 }
874
875 return 0;
876}
877
878#else
879#define s3c24xx_nand_suspend NULL
880#define s3c24xx_nand_resume NULL
881#endif
882
Ben Dooksa4f957f2005-06-20 12:48:25 +0100883/* driver device registration */
884
Russell King3ae5eae2005-11-09 22:32:44 +0000885static int s3c2410_nand_probe(struct platform_device *dev)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100886{
Ben Dooks2c06a082006-06-27 14:35:46 +0100887 return s3c24xx_nand_probe(dev, TYPE_S3C2410);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100888}
889
Russell King3ae5eae2005-11-09 22:32:44 +0000890static int s3c2440_nand_probe(struct platform_device *dev)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100891{
Ben Dooks2c06a082006-06-27 14:35:46 +0100892 return s3c24xx_nand_probe(dev, TYPE_S3C2440);
893}
894
895static int s3c2412_nand_probe(struct platform_device *dev)
896{
897 return s3c24xx_nand_probe(dev, TYPE_S3C2412);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100898}
899
Russell King3ae5eae2005-11-09 22:32:44 +0000900static struct platform_driver s3c2410_nand_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 .probe = s3c2410_nand_probe,
902 .remove = s3c2410_nand_remove,
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100903 .suspend = s3c24xx_nand_suspend,
904 .resume = s3c24xx_nand_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000905 .driver = {
906 .name = "s3c2410-nand",
907 .owner = THIS_MODULE,
908 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909};
910
Russell King3ae5eae2005-11-09 22:32:44 +0000911static struct platform_driver s3c2440_nand_driver = {
Ben Dooksa4f957f2005-06-20 12:48:25 +0100912 .probe = s3c2440_nand_probe,
913 .remove = s3c2410_nand_remove,
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100914 .suspend = s3c24xx_nand_suspend,
915 .resume = s3c24xx_nand_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000916 .driver = {
917 .name = "s3c2440-nand",
918 .owner = THIS_MODULE,
919 },
Ben Dooksa4f957f2005-06-20 12:48:25 +0100920};
921
Ben Dooks2c06a082006-06-27 14:35:46 +0100922static struct platform_driver s3c2412_nand_driver = {
923 .probe = s3c2412_nand_probe,
924 .remove = s3c2410_nand_remove,
925 .suspend = s3c24xx_nand_suspend,
926 .resume = s3c24xx_nand_resume,
927 .driver = {
928 .name = "s3c2412-nand",
929 .owner = THIS_MODULE,
930 },
931};
932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933static int __init s3c2410_nand_init(void)
934{
Ben Dooksa4f957f2005-06-20 12:48:25 +0100935 printk("S3C24XX NAND Driver, (c) 2004 Simtec Electronics\n");
936
Ben Dooks2c06a082006-06-27 14:35:46 +0100937 platform_driver_register(&s3c2412_nand_driver);
Russell King3ae5eae2005-11-09 22:32:44 +0000938 platform_driver_register(&s3c2440_nand_driver);
939 return platform_driver_register(&s3c2410_nand_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940}
941
942static void __exit s3c2410_nand_exit(void)
943{
Ben Dooks2c06a082006-06-27 14:35:46 +0100944 platform_driver_unregister(&s3c2412_nand_driver);
Russell King3ae5eae2005-11-09 22:32:44 +0000945 platform_driver_unregister(&s3c2440_nand_driver);
946 platform_driver_unregister(&s3c2410_nand_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
949module_init(s3c2410_nand_init);
950module_exit(s3c2410_nand_exit);
951
952MODULE_LICENSE("GPL");
953MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
Ben Dooksa4f957f2005-06-20 12:48:25 +0100954MODULE_DESCRIPTION("S3C24XX MTD NAND driver");
Kay Sievers1ff18422008-04-18 13:44:27 -0700955MODULE_ALIAS("platform:s3c2410-nand");
956MODULE_ALIAS("platform:s3c2412-nand");
957MODULE_ALIAS("platform:s3c2440-nand");