blob: 15397e0f39651f79eb1dd5e7093ff4beddbab326 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/drivers/mtd/nand/s3c2410.c
2 *
Ben Dooksa4f957f2005-06-20 12:48:25 +01003 * Copyright (c) 2004,2005 Simtec Electronics
Ben Dooksfdf2fd52005-02-18 14:46:15 +00004 * http://www.simtec.co.uk/products/SWLINUX/
5 * Ben Dooks <ben@simtec.co.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
Ben Dooksa4f957f2005-06-20 12:48:25 +01007 * Samsung S3C2410/S3C240 NAND driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * Changelog:
10 * 21-Sep-2004 BJD Initial version
Joe Perches8e87d782008-02-03 17:22:34 +020011 * 23-Sep-2004 BJD Multiple device support
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * 28-Sep-2004 BJD Fixed ECC placement for Hardware mode
13 * 12-Oct-2004 BJD Fixed errors in use of platform data
Ben Dooks3e4ef3b2005-03-17 11:31:30 +000014 * 18-Feb-2005 BJD Fix sparse errors
15 * 14-Mar-2005 BJD Applied tglx's code reduction patch
Ben Dooksa4f957f2005-06-20 12:48:25 +010016 * 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
Ben Dooksfb8d82a2005-07-06 21:05:10 +010019 * 08-Jul-2005 BJD Fix OOPS when no platform data supplied
Ben Dookscfd320f2005-10-20 22:22:58 +010020 * 20-Oct-2005 BJD Fix timing calculation bug
Ben Dooksd1fef3c2006-06-19 09:29:38 +010021 * 14-Jan-2006 BJD Allow clock to be stopped when idle
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
Ben Dooksd1fef3c2006-06-19 09:29:38 +010023 * $Id: s3c2410.c,v 1.23 2006/04/01 18:06:29 bjd Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38*/
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#ifdef CONFIG_MTD_NAND_S3C2410_DEBUG
41#define DEBUG
42#endif
43
44#include <linux/module.h>
45#include <linux/types.h>
46#include <linux/init.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010050#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/delay.h>
52#include <linux/err.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080053#include <linux/slab.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000054#include <linux/clk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#include <linux/mtd/mtd.h>
57#include <linux/mtd/nand.h>
58#include <linux/mtd/nand_ecc.h>
59#include <linux/mtd/partitions.h>
60
61#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Ben Dooksb7a70182007-07-24 13:37:27 +010063#include <asm/plat-s3c/regs-nand.h>
64#include <asm/plat-s3c/nand.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#ifdef CONFIG_MTD_NAND_S3C2410_HWECC
67static int hardware_ecc = 1;
68#else
69static int hardware_ecc = 0;
70#endif
71
Ben Dooksd1fef3c2006-06-19 09:29:38 +010072#ifdef CONFIG_MTD_NAND_S3C2410_CLKSTOP
73static int clock_stop = 1;
74#else
75static const int clock_stop = 0;
76#endif
77
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079/* new oob placement block for use with hardware ecc generation
80 */
81
Thomas Gleixner5bd34c02006-05-27 22:16:10 +020082static struct nand_ecclayout nand_hw_eccoob = {
David Woodhousee0c7d762006-05-13 18:07:53 +010083 .eccbytes = 3,
84 .eccpos = {0, 1, 2},
85 .oobfree = {{8, 8}}
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
88/* controller and mtd information */
89
90struct s3c2410_nand_info;
91
92struct s3c2410_nand_mtd {
93 struct mtd_info mtd;
94 struct nand_chip chip;
95 struct s3c2410_nand_set *set;
96 struct s3c2410_nand_info *info;
97 int scan_res;
98};
99
Ben Dooks2c06a082006-06-27 14:35:46 +0100100enum s3c_cpu_type {
101 TYPE_S3C2410,
102 TYPE_S3C2412,
103 TYPE_S3C2440,
104};
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/* overview of the s3c2410 nand state */
107
108struct s3c2410_nand_info {
109 /* mtd info */
110 struct nand_hw_control controller;
111 struct s3c2410_nand_mtd *mtds;
112 struct s3c2410_platform_nand *platform;
113
114 /* device info */
115 struct device *device;
116 struct resource *area;
117 struct clk *clk;
Ben Dooksfdf2fd52005-02-18 14:46:15 +0000118 void __iomem *regs;
Ben Dooks2c06a082006-06-27 14:35:46 +0100119 void __iomem *sel_reg;
120 int sel_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 int mtd_count;
Ben Dooks09160832008-04-15 11:36:18 +0100122 unsigned long save_sel;
Ben Dooks03680b12007-11-19 23:28:07 +0000123
Ben Dooks2c06a082006-06-27 14:35:46 +0100124 enum s3c_cpu_type cpu_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125};
126
127/* conversion functions */
128
129static struct s3c2410_nand_mtd *s3c2410_nand_mtd_toours(struct mtd_info *mtd)
130{
131 return container_of(mtd, struct s3c2410_nand_mtd, mtd);
132}
133
134static struct s3c2410_nand_info *s3c2410_nand_mtd_toinfo(struct mtd_info *mtd)
135{
136 return s3c2410_nand_mtd_toours(mtd)->info;
137}
138
Russell King3ae5eae2005-11-09 22:32:44 +0000139static struct s3c2410_nand_info *to_nand_info(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Russell King3ae5eae2005-11-09 22:32:44 +0000141 return platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
Russell King3ae5eae2005-11-09 22:32:44 +0000144static struct s3c2410_platform_nand *to_nand_plat(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Russell King3ae5eae2005-11-09 22:32:44 +0000146 return dev->dev.platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100149static inline int allow_clk_stop(struct s3c2410_nand_info *info)
150{
151 return clock_stop;
152}
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154/* timing calculations */
155
Ben Dookscfd320f2005-10-20 22:22:58 +0100156#define NS_IN_KHZ 1000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Ben Dooks2c06a082006-06-27 14:35:46 +0100158static int s3c_nand_calc_rate(int wanted, unsigned long clk, int max)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
160 int result;
161
Ben Dookscfd320f2005-10-20 22:22:58 +0100162 result = (wanted * clk) / NS_IN_KHZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 result++;
164
165 pr_debug("result %d from %ld, %d\n", result, clk, wanted);
166
167 if (result > max) {
David Woodhousee0c7d762006-05-13 18:07:53 +0100168 printk("%d ns is too big for current clock rate %ld\n", wanted, clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return -1;
170 }
171
172 if (result < 1)
173 result = 1;
174
175 return result;
176}
177
Ben Dookscfd320f2005-10-20 22:22:58 +0100178#define to_ns(ticks,clk) (((ticks) * NS_IN_KHZ) / (unsigned int)(clk))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180/* controller setup */
181
Ben Dooks2c06a082006-06-27 14:35:46 +0100182static int s3c2410_nand_inithw(struct s3c2410_nand_info *info,
183 struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Russell King3ae5eae2005-11-09 22:32:44 +0000185 struct s3c2410_platform_nand *plat = to_nand_plat(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 unsigned long clkrate = clk_get_rate(info->clk);
Ben Dooks2c06a082006-06-27 14:35:46 +0100187 int tacls_max = (info->cpu_type == TYPE_S3C2412) ? 8 : 4;
Ben Dookscfd320f2005-10-20 22:22:58 +0100188 int tacls, twrph0, twrph1;
Ben Dooks2c06a082006-06-27 14:35:46 +0100189 unsigned long cfg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 /* calculate the timing information for the controller */
192
Ben Dookscfd320f2005-10-20 22:22:58 +0100193 clkrate /= 1000; /* turn clock into kHz for ease of use */
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 if (plat != NULL) {
Ben Dooks2c06a082006-06-27 14:35:46 +0100196 tacls = s3c_nand_calc_rate(plat->tacls, clkrate, tacls_max);
197 twrph0 = s3c_nand_calc_rate(plat->twrph0, clkrate, 8);
198 twrph1 = s3c_nand_calc_rate(plat->twrph1, clkrate, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 } else {
200 /* default timings */
Ben Dooks2c06a082006-06-27 14:35:46 +0100201 tacls = tacls_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 twrph0 = 8;
203 twrph1 = 8;
204 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 if (tacls < 0 || twrph0 < 0 || twrph1 < 0) {
Ben Dooks99974c62006-06-21 15:43:05 +0100207 dev_err(info->device, "cannot get suitable timings\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return -EINVAL;
209 }
210
Ben Dooks99974c62006-06-21 15:43:05 +0100211 dev_info(info->device, "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n",
David Woodhousee0c7d762006-05-13 18:07:53 +0100212 tacls, to_ns(tacls, clkrate), twrph0, to_ns(twrph0, clkrate), twrph1, to_ns(twrph1, clkrate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Ben Dooks2c06a082006-06-27 14:35:46 +0100214 switch (info->cpu_type) {
215 case TYPE_S3C2410:
David Woodhousee0c7d762006-05-13 18:07:53 +0100216 cfg = S3C2410_NFCONF_EN;
217 cfg |= S3C2410_NFCONF_TACLS(tacls - 1);
218 cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1);
219 cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1);
Ben Dooks2c06a082006-06-27 14:35:46 +0100220 break;
221
222 case TYPE_S3C2440:
223 case TYPE_S3C2412:
David Woodhousee0c7d762006-05-13 18:07:53 +0100224 cfg = S3C2440_NFCONF_TACLS(tacls - 1);
225 cfg |= S3C2440_NFCONF_TWRPH0(twrph0 - 1);
226 cfg |= S3C2440_NFCONF_TWRPH1(twrph1 - 1);
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100227
228 /* enable the controller and de-assert nFCE */
229
Ben Dooks2c06a082006-06-27 14:35:46 +0100230 writel(S3C2440_NFCONT_ENABLE, info->regs + S3C2440_NFCONT);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Ben Dooks99974c62006-06-21 15:43:05 +0100233 dev_dbg(info->device, "NF_CONF is 0x%lx\n", cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 writel(cfg, info->regs + S3C2410_NFCONF);
236 return 0;
237}
238
239/* select chip */
240
241static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
242{
243 struct s3c2410_nand_info *info;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000244 struct s3c2410_nand_mtd *nmtd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 struct nand_chip *this = mtd->priv;
246 unsigned long cur;
247
248 nmtd = this->priv;
249 info = nmtd->info;
250
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100251 if (chip != -1 && allow_clk_stop(info))
252 clk_enable(info->clk);
253
Ben Dooks2c06a082006-06-27 14:35:46 +0100254 cur = readl(info->sel_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 if (chip == -1) {
Ben Dooks2c06a082006-06-27 14:35:46 +0100257 cur |= info->sel_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 } else {
Ben Dooksfb8d82a2005-07-06 21:05:10 +0100259 if (nmtd->set != NULL && chip > nmtd->set->nr_chips) {
Ben Dooks99974c62006-06-21 15:43:05 +0100260 dev_err(info->device, "invalid chip %d\n", chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return;
262 }
263
264 if (info->platform != NULL) {
265 if (info->platform->select_chip != NULL)
David Woodhousee0c7d762006-05-13 18:07:53 +0100266 (info->platform->select_chip) (nmtd->set, chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268
Ben Dooks2c06a082006-06-27 14:35:46 +0100269 cur &= ~info->sel_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271
Ben Dooks2c06a082006-06-27 14:35:46 +0100272 writel(cur, info->sel_reg);
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100273
274 if (chip == -1 && allow_clk_stop(info))
275 clk_disable(info->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
Ben Dooksad3b5fb2006-06-19 09:43:23 +0100278/* s3c2410_nand_hwcontrol
Ben Dooksa4f957f2005-06-20 12:48:25 +0100279 *
Ben Dooksad3b5fb2006-06-19 09:43:23 +0100280 * Issue command and address cycles to the chip
Ben Dooksa4f957f2005-06-20 12:48:25 +0100281*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200283static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd,
David Woodhousef9068872006-06-10 00:53:16 +0100284 unsigned int ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
David Woodhousec9ac5972006-11-30 08:17:38 +0000287
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200288 if (cmd == NAND_CMD_NONE)
289 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
David Woodhousef9068872006-06-10 00:53:16 +0100291 if (ctrl & NAND_CLE)
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200292 writeb(cmd, info->regs + S3C2410_NFCMD);
293 else
294 writeb(cmd, info->regs + S3C2410_NFADDR);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100295}
296
297/* command and control functions */
298
David Woodhousef9068872006-06-10 00:53:16 +0100299static void s3c2440_nand_hwcontrol(struct mtd_info *mtd, int cmd,
300 unsigned int ctrl)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100301{
302 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100303
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200304 if (cmd == NAND_CMD_NONE)
305 return;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100306
David Woodhousef9068872006-06-10 00:53:16 +0100307 if (ctrl & NAND_CLE)
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200308 writeb(cmd, info->regs + S3C2440_NFCMD);
309 else
310 writeb(cmd, info->regs + S3C2440_NFADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313/* s3c2410_nand_devready()
314 *
315 * returns 0 if the nand is busy, 1 if it is ready
316*/
317
318static int s3c2410_nand_devready(struct mtd_info *mtd)
319{
320 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
322}
323
Ben Dooks2c06a082006-06-27 14:35:46 +0100324static int s3c2440_nand_devready(struct mtd_info *mtd)
325{
326 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
327 return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY;
328}
329
330static int s3c2412_nand_devready(struct mtd_info *mtd)
331{
332 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
333 return readb(info->regs + S3C2412_NFSTAT) & S3C2412_NFSTAT_READY;
334}
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336/* ECC handling functions */
337
Ben Dooks2c06a082006-06-27 14:35:46 +0100338static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
339 u_char *read_ecc, u_char *calc_ecc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Ben Dooksa2593242007-02-02 16:59:33 +0000341 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
342 unsigned int diff0, diff1, diff2;
343 unsigned int bit, byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Ben Dooksa2593242007-02-02 16:59:33 +0000345 pr_debug("%s(%p,%p,%p,%p)\n", __func__, mtd, dat, read_ecc, calc_ecc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Ben Dooksa2593242007-02-02 16:59:33 +0000347 diff0 = read_ecc[0] ^ calc_ecc[0];
348 diff1 = read_ecc[1] ^ calc_ecc[1];
349 diff2 = read_ecc[2] ^ calc_ecc[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Ben Dooksa2593242007-02-02 16:59:33 +0000351 pr_debug("%s: rd %02x%02x%02x calc %02x%02x%02x diff %02x%02x%02x\n",
352 __func__,
353 read_ecc[0], read_ecc[1], read_ecc[2],
354 calc_ecc[0], calc_ecc[1], calc_ecc[2],
355 diff0, diff1, diff2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Ben Dooksa2593242007-02-02 16:59:33 +0000357 if (diff0 == 0 && diff1 == 0 && diff2 == 0)
358 return 0; /* ECC is ok */
359
360 /* Can we correct this ECC (ie, one row and column change).
361 * Note, this is similar to the 256 error code on smartmedia */
362
363 if (((diff0 ^ (diff0 >> 1)) & 0x55) == 0x55 &&
364 ((diff1 ^ (diff1 >> 1)) & 0x55) == 0x55 &&
365 ((diff2 ^ (diff2 >> 1)) & 0x55) == 0x55) {
366 /* calculate the bit position of the error */
367
Matt Reimerd0bf3792007-10-18 18:02:43 -0700368 bit = ((diff2 >> 3) & 1) |
369 ((diff2 >> 4) & 2) |
370 ((diff2 >> 5) & 4);
Ben Dooksa2593242007-02-02 16:59:33 +0000371
372 /* calculate the byte position of the error */
373
Matt Reimerd0bf3792007-10-18 18:02:43 -0700374 byte = ((diff2 << 7) & 0x100) |
375 ((diff1 << 0) & 0x80) |
376 ((diff1 << 1) & 0x40) |
377 ((diff1 << 2) & 0x20) |
378 ((diff1 << 3) & 0x10) |
379 ((diff0 >> 4) & 0x08) |
380 ((diff0 >> 3) & 0x04) |
381 ((diff0 >> 2) & 0x02) |
382 ((diff0 >> 1) & 0x01);
Ben Dooksa2593242007-02-02 16:59:33 +0000383
384 dev_dbg(info->device, "correcting error bit %d, byte %d\n",
385 bit, byte);
386
387 dat[byte] ^= (1 << bit);
388 return 1;
389 }
390
391 /* if there is only one bit difference in the ECC, then
392 * one of only a row or column parity has changed, which
393 * means the error is most probably in the ECC itself */
394
395 diff0 |= (diff1 << 8);
396 diff0 |= (diff2 << 16);
397
398 if ((diff0 & ~(1<<fls(diff0))) == 0)
399 return 1;
400
Matt Reimer4fac9f62007-10-18 18:02:44 -0700401 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402}
403
Ben Dooksa4f957f2005-06-20 12:48:25 +0100404/* ECC functions
405 *
406 * These allow the s3c2410 and s3c2440 to use the controller's ECC
407 * generator block to ECC the data as it passes through]
408*/
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode)
411{
412 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
413 unsigned long ctrl;
414
415 ctrl = readl(info->regs + S3C2410_NFCONF);
416 ctrl |= S3C2410_NFCONF_INITECC;
417 writel(ctrl, info->regs + S3C2410_NFCONF);
418}
419
Matthieu CASTET4f659922007-02-13 12:30:38 +0100420static void s3c2412_nand_enable_hwecc(struct mtd_info *mtd, int mode)
421{
422 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
423 unsigned long ctrl;
424
425 ctrl = readl(info->regs + S3C2440_NFCONT);
426 writel(ctrl | S3C2412_NFCONT_INIT_MAIN_ECC, info->regs + S3C2440_NFCONT);
427}
428
Ben Dooksa4f957f2005-06-20 12:48:25 +0100429static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
430{
431 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
432 unsigned long ctrl;
433
434 ctrl = readl(info->regs + S3C2440_NFCONT);
435 writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT);
436}
437
David Woodhousee0c7d762006-05-13 18:07:53 +0100438static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
441
442 ecc_code[0] = readb(info->regs + S3C2410_NFECC + 0);
443 ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1);
444 ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2);
445
Ben Dooksa2593242007-02-02 16:59:33 +0000446 pr_debug("%s: returning ecc %02x%02x%02x\n", __func__,
447 ecc_code[0], ecc_code[1], ecc_code[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 return 0;
450}
451
Matthieu CASTET4f659922007-02-13 12:30:38 +0100452static int s3c2412_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
453{
454 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
455 unsigned long ecc = readl(info->regs + S3C2412_NFMECC0);
456
457 ecc_code[0] = ecc;
458 ecc_code[1] = ecc >> 8;
459 ecc_code[2] = ecc >> 16;
460
461 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]);
462
463 return 0;
464}
465
David Woodhousee0c7d762006-05-13 18:07:53 +0100466static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100467{
468 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
469 unsigned long ecc = readl(info->regs + S3C2440_NFMECC0);
470
471 ecc_code[0] = ecc;
472 ecc_code[1] = ecc >> 8;
473 ecc_code[2] = ecc >> 16;
474
Ben Dooks71d54f32008-04-15 11:36:19 +0100475 pr_debug("%s: returning ecc %06lx\n", __func__, ecc & 0xffffff);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100476
477 return 0;
478}
479
Ben Dooksa4f957f2005-06-20 12:48:25 +0100480/* over-ride the standard functions for a little more speed. We can
481 * use read/write block to move the data buffers to/from the controller
482*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
485{
486 struct nand_chip *this = mtd->priv;
487 readsb(this->IO_ADDR_R, buf, len);
488}
489
Matt Reimerb773bb22007-10-18 17:43:07 -0700490static void s3c2440_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
491{
492 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
493 readsl(info->regs + S3C2440_NFDATA, buf, len / 4);
494}
495
David Woodhousee0c7d762006-05-13 18:07:53 +0100496static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
498 struct nand_chip *this = mtd->priv;
499 writesb(this->IO_ADDR_W, buf, len);
500}
501
Matt Reimerb773bb22007-10-18 17:43:07 -0700502static void s3c2440_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
503{
504 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
505 writesl(info->regs + S3C2440_NFDATA, buf, len / 4);
506}
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508/* device management functions */
509
Russell King3ae5eae2005-11-09 22:32:44 +0000510static int s3c2410_nand_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
Russell King3ae5eae2005-11-09 22:32:44 +0000512 struct s3c2410_nand_info *info = to_nand_info(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Russell King3ae5eae2005-11-09 22:32:44 +0000514 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000516 if (info == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return 0;
518
519 /* first thing we need to do is release all our mtds
520 * and their partitions, then go through freeing the
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000521 * resources used
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 */
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 if (info->mtds != NULL) {
525 struct s3c2410_nand_mtd *ptr = info->mtds;
526 int mtdno;
527
528 for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) {
529 pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
530 nand_release(&ptr->mtd);
531 }
532
533 kfree(info->mtds);
534 }
535
536 /* free the common resources */
537
538 if (info->clk != NULL && !IS_ERR(info->clk)) {
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100539 if (!allow_clk_stop(info))
540 clk_disable(info->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 clk_put(info->clk);
542 }
543
544 if (info->regs != NULL) {
545 iounmap(info->regs);
546 info->regs = NULL;
547 }
548
549 if (info->area != NULL) {
550 release_resource(info->area);
551 kfree(info->area);
552 info->area = NULL;
553 }
554
555 kfree(info);
556
557 return 0;
558}
559
560#ifdef CONFIG_MTD_PARTITIONS
561static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
562 struct s3c2410_nand_mtd *mtd,
563 struct s3c2410_nand_set *set)
564{
565 if (set == NULL)
566 return add_mtd_device(&mtd->mtd);
567
568 if (set->nr_partitions > 0 && set->partitions != NULL) {
David Woodhousee0c7d762006-05-13 18:07:53 +0100569 return add_mtd_partitions(&mtd->mtd, set->partitions, set->nr_partitions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 }
571
572 return add_mtd_device(&mtd->mtd);
573}
574#else
575static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
576 struct s3c2410_nand_mtd *mtd,
577 struct s3c2410_nand_set *set)
578{
579 return add_mtd_device(&mtd->mtd);
580}
581#endif
582
583/* s3c2410_nand_init_chip
584 *
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000585 * init a single instance of an chip
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586*/
587
588static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
589 struct s3c2410_nand_mtd *nmtd,
590 struct s3c2410_nand_set *set)
591{
592 struct nand_chip *chip = &nmtd->chip;
Ben Dooks2c06a082006-06-27 14:35:46 +0100593 void __iomem *regs = info->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 chip->write_buf = s3c2410_nand_write_buf;
596 chip->read_buf = s3c2410_nand_read_buf;
597 chip->select_chip = s3c2410_nand_select_chip;
598 chip->chip_delay = 50;
599 chip->priv = nmtd;
600 chip->options = 0;
601 chip->controller = &info->controller;
602
Ben Dooks2c06a082006-06-27 14:35:46 +0100603 switch (info->cpu_type) {
604 case TYPE_S3C2410:
605 chip->IO_ADDR_W = regs + S3C2410_NFDATA;
606 info->sel_reg = regs + S3C2410_NFCONF;
607 info->sel_bit = S3C2410_NFCONF_nFCE;
608 chip->cmd_ctrl = s3c2410_nand_hwcontrol;
609 chip->dev_ready = s3c2410_nand_devready;
610 break;
611
612 case TYPE_S3C2440:
613 chip->IO_ADDR_W = regs + S3C2440_NFDATA;
614 info->sel_reg = regs + S3C2440_NFCONT;
615 info->sel_bit = S3C2440_NFCONT_nFCE;
616 chip->cmd_ctrl = s3c2440_nand_hwcontrol;
617 chip->dev_ready = s3c2440_nand_devready;
Matt Reimerb773bb22007-10-18 17:43:07 -0700618 chip->read_buf = s3c2440_nand_read_buf;
619 chip->write_buf = s3c2440_nand_write_buf;
Ben Dooks2c06a082006-06-27 14:35:46 +0100620 break;
621
622 case TYPE_S3C2412:
623 chip->IO_ADDR_W = regs + S3C2440_NFDATA;
624 info->sel_reg = regs + S3C2440_NFCONT;
625 info->sel_bit = S3C2412_NFCONT_nFCE0;
626 chip->cmd_ctrl = s3c2440_nand_hwcontrol;
627 chip->dev_ready = s3c2412_nand_devready;
628
629 if (readl(regs + S3C2410_NFCONF) & S3C2412_NFCONF_NANDBOOT)
630 dev_info(info->device, "System booted from NAND\n");
631
632 break;
633 }
634
635 chip->IO_ADDR_R = chip->IO_ADDR_W;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 nmtd->info = info;
638 nmtd->mtd.priv = chip;
David Woodhouse552d9202006-05-14 01:20:46 +0100639 nmtd->mtd.owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 nmtd->set = set;
641
642 if (hardware_ecc) {
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200643 chip->ecc.calculate = s3c2410_nand_calculate_ecc;
Ben Dooks2c06a082006-06-27 14:35:46 +0100644 chip->ecc.correct = s3c2410_nand_correct_data;
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200645 chip->ecc.mode = NAND_ECC_HW;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100646
Ben Dooks2c06a082006-06-27 14:35:46 +0100647 switch (info->cpu_type) {
648 case TYPE_S3C2410:
649 chip->ecc.hwctl = s3c2410_nand_enable_hwecc;
650 chip->ecc.calculate = s3c2410_nand_calculate_ecc;
651 break;
652
653 case TYPE_S3C2412:
Matthieu CASTET4f659922007-02-13 12:30:38 +0100654 chip->ecc.hwctl = s3c2412_nand_enable_hwecc;
655 chip->ecc.calculate = s3c2412_nand_calculate_ecc;
656 break;
657
Ben Dooks2c06a082006-06-27 14:35:46 +0100658 case TYPE_S3C2440:
659 chip->ecc.hwctl = s3c2440_nand_enable_hwecc;
660 chip->ecc.calculate = s3c2440_nand_calculate_ecc;
661 break;
662
Ben Dooksa4f957f2005-06-20 12:48:25 +0100663 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 } else {
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200665 chip->ecc.mode = NAND_ECC_SOFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 }
667}
668
Ben Dooks71d54f32008-04-15 11:36:19 +0100669/* s3c2410_nand_update_chip
670 *
671 * post-probe chip update, to change any items, such as the
672 * layout for large page nand
673 */
674
675static void s3c2410_nand_update_chip(struct s3c2410_nand_info *info,
676 struct s3c2410_nand_mtd *nmtd)
677{
678 struct nand_chip *chip = &nmtd->chip;
679
680 printk("%s: chip %p: %d\n", __func__, chip, chip->page_shift);
681
682 if (hardware_ecc) {
683 /* change the behaviour depending on wether we are using
684 * the large or small page nand device */
685
686 if (chip->page_shift > 10) {
687 chip->ecc.size = 256;
688 chip->ecc.bytes = 3;
689 } else {
690 chip->ecc.size = 512;
691 chip->ecc.bytes = 3;
692 chip->ecc.layout = &nand_hw_eccoob;
693 }
694 }
695}
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697/* s3c2410_nand_probe
698 *
699 * called by device layer when it finds a device matching
700 * one our driver can handled. This code checks to see if
701 * it can allocate all necessary resources then calls the
702 * nand layer to look for devices
703*/
704
Ben Dooks2c06a082006-06-27 14:35:46 +0100705static int s3c24xx_nand_probe(struct platform_device *pdev,
706 enum s3c_cpu_type cpu_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Russell King3ae5eae2005-11-09 22:32:44 +0000708 struct s3c2410_platform_nand *plat = to_nand_plat(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 struct s3c2410_nand_info *info;
710 struct s3c2410_nand_mtd *nmtd;
711 struct s3c2410_nand_set *sets;
712 struct resource *res;
713 int err = 0;
714 int size;
715 int nr_sets;
716 int setno;
717
Russell King3ae5eae2005-11-09 22:32:44 +0000718 pr_debug("s3c2410_nand_probe(%p)\n", pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 info = kmalloc(sizeof(*info), GFP_KERNEL);
721 if (info == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000722 dev_err(&pdev->dev, "no memory for flash info\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 err = -ENOMEM;
724 goto exit_error;
725 }
726
727 memzero(info, sizeof(*info));
Russell King3ae5eae2005-11-09 22:32:44 +0000728 platform_set_drvdata(pdev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 spin_lock_init(&info->controller.lock);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100731 init_waitqueue_head(&info->controller.wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 /* get the clock source and enable it */
734
Russell King3ae5eae2005-11-09 22:32:44 +0000735 info->clk = clk_get(&pdev->dev, "nand");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 if (IS_ERR(info->clk)) {
Joe Perches898eb712007-10-18 03:06:30 -0700737 dev_err(&pdev->dev, "failed to get clock\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 err = -ENOENT;
739 goto exit_error;
740 }
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 clk_enable(info->clk);
743
744 /* allocate and map the resource */
745
Ben Dooksa4f957f2005-06-20 12:48:25 +0100746 /* currently we assume we have the one resource */
747 res = pdev->resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 size = res->end - res->start + 1;
749
750 info->area = request_mem_region(res->start, size, pdev->name);
751
752 if (info->area == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000753 dev_err(&pdev->dev, "cannot reserve register region\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 err = -ENOENT;
755 goto exit_error;
756 }
757
Russell King3ae5eae2005-11-09 22:32:44 +0000758 info->device = &pdev->dev;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100759 info->platform = plat;
760 info->regs = ioremap(res->start, size);
Ben Dooks2c06a082006-06-27 14:35:46 +0100761 info->cpu_type = cpu_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 if (info->regs == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000764 dev_err(&pdev->dev, "cannot reserve register region\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 err = -EIO;
766 goto exit_error;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000767 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Russell King3ae5eae2005-11-09 22:32:44 +0000769 dev_dbg(&pdev->dev, "mapped registers at %p\n", info->regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 /* initialise the hardware */
772
Russell King3ae5eae2005-11-09 22:32:44 +0000773 err = s3c2410_nand_inithw(info, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 if (err != 0)
775 goto exit_error;
776
777 sets = (plat != NULL) ? plat->sets : NULL;
778 nr_sets = (plat != NULL) ? plat->nr_sets : 1;
779
780 info->mtd_count = nr_sets;
781
782 /* allocate our information */
783
784 size = nr_sets * sizeof(*info->mtds);
785 info->mtds = kmalloc(size, GFP_KERNEL);
786 if (info->mtds == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000787 dev_err(&pdev->dev, "failed to allocate mtd storage\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 err = -ENOMEM;
789 goto exit_error;
790 }
791
792 memzero(info->mtds, size);
793
794 /* initialise all possible chips */
795
796 nmtd = info->mtds;
797
798 for (setno = 0; setno < nr_sets; setno++, nmtd++) {
David Woodhousee0c7d762006-05-13 18:07:53 +0100799 pr_debug("initialising set %d (%p, info %p)\n", setno, nmtd, info);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 s3c2410_nand_init_chip(info, nmtd, sets);
802
Ben Dooks71d54f32008-04-15 11:36:19 +0100803 nmtd->scan_res = nand_scan_ident(&nmtd->mtd,
804 (sets) ? sets->nr_chips : 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 if (nmtd->scan_res == 0) {
Ben Dooks71d54f32008-04-15 11:36:19 +0100807 s3c2410_nand_update_chip(info, nmtd);
808 nand_scan_tail(&nmtd->mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 s3c2410_nand_add_partition(info, nmtd, sets);
810 }
811
812 if (sets != NULL)
813 sets++;
814 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000815
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100816 if (allow_clk_stop(info)) {
817 dev_info(&pdev->dev, "clock idle support enabled\n");
818 clk_disable(info->clk);
819 }
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 pr_debug("initialised ok\n");
822 return 0;
823
824 exit_error:
Russell King3ae5eae2005-11-09 22:32:44 +0000825 s3c2410_nand_remove(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 if (err == 0)
828 err = -EINVAL;
829 return err;
830}
831
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100832/* PM Support */
833#ifdef CONFIG_PM
834
835static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
836{
837 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
838
839 if (info) {
Ben Dooks09160832008-04-15 11:36:18 +0100840 info->save_sel = readl(info->sel_reg);
Ben Dooks03680b12007-11-19 23:28:07 +0000841
842 /* For the moment, we must ensure nFCE is high during
843 * the time we are suspended. This really should be
844 * handled by suspending the MTDs we are using, but
845 * that is currently not the case. */
846
Ben Dooks09160832008-04-15 11:36:18 +0100847 writel(info->save_sel | info->sel_bit, info->sel_reg);
Ben Dooks03680b12007-11-19 23:28:07 +0000848
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100849 if (!allow_clk_stop(info))
850 clk_disable(info->clk);
851 }
852
853 return 0;
854}
855
856static int s3c24xx_nand_resume(struct platform_device *dev)
857{
858 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
Ben Dooks09160832008-04-15 11:36:18 +0100859 unsigned long sel;
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100860
861 if (info) {
862 clk_enable(info->clk);
863 s3c2410_nand_inithw(info, dev);
864
Ben Dooks03680b12007-11-19 23:28:07 +0000865 /* Restore the state of the nFCE line. */
866
Ben Dooks09160832008-04-15 11:36:18 +0100867 sel = readl(info->sel_reg);
868 sel &= ~info->sel_bit;
869 sel |= info->save_sel & info->sel_bit;
870 writel(sel, info->sel_reg);
Ben Dooks03680b12007-11-19 23:28:07 +0000871
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100872 if (allow_clk_stop(info))
873 clk_disable(info->clk);
874 }
875
876 return 0;
877}
878
879#else
880#define s3c24xx_nand_suspend NULL
881#define s3c24xx_nand_resume NULL
882#endif
883
Ben Dooksa4f957f2005-06-20 12:48:25 +0100884/* driver device registration */
885
Russell King3ae5eae2005-11-09 22:32:44 +0000886static int s3c2410_nand_probe(struct platform_device *dev)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100887{
Ben Dooks2c06a082006-06-27 14:35:46 +0100888 return s3c24xx_nand_probe(dev, TYPE_S3C2410);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100889}
890
Russell King3ae5eae2005-11-09 22:32:44 +0000891static int s3c2440_nand_probe(struct platform_device *dev)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100892{
Ben Dooks2c06a082006-06-27 14:35:46 +0100893 return s3c24xx_nand_probe(dev, TYPE_S3C2440);
894}
895
896static int s3c2412_nand_probe(struct platform_device *dev)
897{
898 return s3c24xx_nand_probe(dev, TYPE_S3C2412);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100899}
900
Russell King3ae5eae2005-11-09 22:32:44 +0000901static struct platform_driver s3c2410_nand_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 .probe = s3c2410_nand_probe,
903 .remove = s3c2410_nand_remove,
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100904 .suspend = s3c24xx_nand_suspend,
905 .resume = s3c24xx_nand_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000906 .driver = {
907 .name = "s3c2410-nand",
908 .owner = THIS_MODULE,
909 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910};
911
Russell King3ae5eae2005-11-09 22:32:44 +0000912static struct platform_driver s3c2440_nand_driver = {
Ben Dooksa4f957f2005-06-20 12:48:25 +0100913 .probe = s3c2440_nand_probe,
914 .remove = s3c2410_nand_remove,
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100915 .suspend = s3c24xx_nand_suspend,
916 .resume = s3c24xx_nand_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000917 .driver = {
918 .name = "s3c2440-nand",
919 .owner = THIS_MODULE,
920 },
Ben Dooksa4f957f2005-06-20 12:48:25 +0100921};
922
Ben Dooks2c06a082006-06-27 14:35:46 +0100923static struct platform_driver s3c2412_nand_driver = {
924 .probe = s3c2412_nand_probe,
925 .remove = s3c2410_nand_remove,
926 .suspend = s3c24xx_nand_suspend,
927 .resume = s3c24xx_nand_resume,
928 .driver = {
929 .name = "s3c2412-nand",
930 .owner = THIS_MODULE,
931 },
932};
933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934static int __init s3c2410_nand_init(void)
935{
Ben Dooksa4f957f2005-06-20 12:48:25 +0100936 printk("S3C24XX NAND Driver, (c) 2004 Simtec Electronics\n");
937
Ben Dooks2c06a082006-06-27 14:35:46 +0100938 platform_driver_register(&s3c2412_nand_driver);
Russell King3ae5eae2005-11-09 22:32:44 +0000939 platform_driver_register(&s3c2440_nand_driver);
940 return platform_driver_register(&s3c2410_nand_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941}
942
943static void __exit s3c2410_nand_exit(void)
944{
Ben Dooks2c06a082006-06-27 14:35:46 +0100945 platform_driver_unregister(&s3c2412_nand_driver);
Russell King3ae5eae2005-11-09 22:32:44 +0000946 platform_driver_unregister(&s3c2440_nand_driver);
947 platform_driver_unregister(&s3c2410_nand_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948}
949
950module_init(s3c2410_nand_init);
951module_exit(s3c2410_nand_exit);
952
953MODULE_LICENSE("GPL");
954MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
Ben Dooksa4f957f2005-06-20 12:48:25 +0100955MODULE_DESCRIPTION("S3C24XX MTD NAND driver");
Kay Sievers1ff18422008-04-18 13:44:27 -0700956MODULE_ALIAS("platform:s3c2410-nand");
957MODULE_ALIAS("platform:s3c2412-nand");
958MODULE_ALIAS("platform:s3c2440-nand");