blob: c9726bd2c64abd22f94736acfc6e3b9c2b2440ed [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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#ifdef CONFIG_MTD_NAND_S3C2410_DEBUG
39#define DEBUG
40#endif
41
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>
Russell Kingd052d1b2005-10-29 19:07:23 +010048#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/delay.h>
50#include <linux/err.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080051#include <linux/slab.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000052#include <linux/clk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <linux/mtd/mtd.h>
55#include <linux/mtd/nand.h>
56#include <linux/mtd/nand_ecc.h>
57#include <linux/mtd/partitions.h>
58
59#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Ben Dooksb7a70182007-07-24 13:37:27 +010061#include <asm/plat-s3c/regs-nand.h>
62#include <asm/plat-s3c/nand.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#ifdef CONFIG_MTD_NAND_S3C2410_HWECC
65static int hardware_ecc = 1;
66#else
67static int hardware_ecc = 0;
68#endif
69
Ben Dooksd1fef3c2006-06-19 09:29:38 +010070#ifdef CONFIG_MTD_NAND_S3C2410_CLKSTOP
71static int clock_stop = 1;
72#else
73static const int clock_stop = 0;
74#endif
75
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/* new oob placement block for use with hardware ecc generation
78 */
79
Thomas Gleixner5bd34c02006-05-27 22:16:10 +020080static struct nand_ecclayout nand_hw_eccoob = {
David Woodhousee0c7d762006-05-13 18:07:53 +010081 .eccbytes = 3,
82 .eccpos = {0, 1, 2},
83 .oobfree = {{8, 8}}
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
85
86/* controller and mtd information */
87
88struct s3c2410_nand_info;
89
90struct s3c2410_nand_mtd {
91 struct mtd_info mtd;
92 struct nand_chip chip;
93 struct s3c2410_nand_set *set;
94 struct s3c2410_nand_info *info;
95 int scan_res;
96};
97
Ben Dooks2c06a082006-06-27 14:35:46 +010098enum s3c_cpu_type {
99 TYPE_S3C2410,
100 TYPE_S3C2412,
101 TYPE_S3C2440,
102};
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104/* overview of the s3c2410 nand state */
105
106struct s3c2410_nand_info {
107 /* mtd info */
108 struct nand_hw_control controller;
109 struct s3c2410_nand_mtd *mtds;
110 struct s3c2410_platform_nand *platform;
111
112 /* device info */
113 struct device *device;
114 struct resource *area;
115 struct clk *clk;
Ben Dooksfdf2fd52005-02-18 14:46:15 +0000116 void __iomem *regs;
Ben Dooks2c06a082006-06-27 14:35:46 +0100117 void __iomem *sel_reg;
118 int sel_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 int mtd_count;
Ben Dooks09160832008-04-15 11:36:18 +0100120 unsigned long save_sel;
Ben Dooks03680b12007-11-19 23:28:07 +0000121
Ben Dooks2c06a082006-06-27 14:35:46 +0100122 enum s3c_cpu_type cpu_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123};
124
125/* conversion functions */
126
127static struct s3c2410_nand_mtd *s3c2410_nand_mtd_toours(struct mtd_info *mtd)
128{
129 return container_of(mtd, struct s3c2410_nand_mtd, mtd);
130}
131
132static struct s3c2410_nand_info *s3c2410_nand_mtd_toinfo(struct mtd_info *mtd)
133{
134 return s3c2410_nand_mtd_toours(mtd)->info;
135}
136
Russell King3ae5eae2005-11-09 22:32:44 +0000137static struct s3c2410_nand_info *to_nand_info(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Russell King3ae5eae2005-11-09 22:32:44 +0000139 return platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Russell King3ae5eae2005-11-09 22:32:44 +0000142static struct s3c2410_platform_nand *to_nand_plat(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Russell King3ae5eae2005-11-09 22:32:44 +0000144 return dev->dev.platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100147static inline int allow_clk_stop(struct s3c2410_nand_info *info)
148{
149 return clock_stop;
150}
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/* timing calculations */
153
Ben Dookscfd320f2005-10-20 22:22:58 +0100154#define NS_IN_KHZ 1000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Ben Dooks2c06a082006-06-27 14:35:46 +0100156static int s3c_nand_calc_rate(int wanted, unsigned long clk, int max)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158 int result;
159
Ben Dookscfd320f2005-10-20 22:22:58 +0100160 result = (wanted * clk) / NS_IN_KHZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 result++;
162
163 pr_debug("result %d from %ld, %d\n", result, clk, wanted);
164
165 if (result > max) {
David Woodhousee0c7d762006-05-13 18:07:53 +0100166 printk("%d ns is too big for current clock rate %ld\n", wanted, clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 return -1;
168 }
169
170 if (result < 1)
171 result = 1;
172
173 return result;
174}
175
Ben Dookscfd320f2005-10-20 22:22:58 +0100176#define to_ns(ticks,clk) (((ticks) * NS_IN_KHZ) / (unsigned int)(clk))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178/* controller setup */
179
Ben Dooks2c06a082006-06-27 14:35:46 +0100180static int s3c2410_nand_inithw(struct s3c2410_nand_info *info,
181 struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
Russell King3ae5eae2005-11-09 22:32:44 +0000183 struct s3c2410_platform_nand *plat = to_nand_plat(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 unsigned long clkrate = clk_get_rate(info->clk);
Ben Dooks2c06a082006-06-27 14:35:46 +0100185 int tacls_max = (info->cpu_type == TYPE_S3C2412) ? 8 : 4;
Ben Dookscfd320f2005-10-20 22:22:58 +0100186 int tacls, twrph0, twrph1;
Ben Dooks2c06a082006-06-27 14:35:46 +0100187 unsigned long cfg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 /* calculate the timing information for the controller */
190
Ben Dookscfd320f2005-10-20 22:22:58 +0100191 clkrate /= 1000; /* turn clock into kHz for ease of use */
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 if (plat != NULL) {
Ben Dooks2c06a082006-06-27 14:35:46 +0100194 tacls = s3c_nand_calc_rate(plat->tacls, clkrate, tacls_max);
195 twrph0 = s3c_nand_calc_rate(plat->twrph0, clkrate, 8);
196 twrph1 = s3c_nand_calc_rate(plat->twrph1, clkrate, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 } else {
198 /* default timings */
Ben Dooks2c06a082006-06-27 14:35:46 +0100199 tacls = tacls_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 twrph0 = 8;
201 twrph1 = 8;
202 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 if (tacls < 0 || twrph0 < 0 || twrph1 < 0) {
Ben Dooks99974c62006-06-21 15:43:05 +0100205 dev_err(info->device, "cannot get suitable timings\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return -EINVAL;
207 }
208
Ben Dooks99974c62006-06-21 15:43:05 +0100209 dev_info(info->device, "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n",
David Woodhousee0c7d762006-05-13 18:07:53 +0100210 tacls, to_ns(tacls, clkrate), twrph0, to_ns(twrph0, clkrate), twrph1, to_ns(twrph1, clkrate));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Ben Dooks2c06a082006-06-27 14:35:46 +0100212 switch (info->cpu_type) {
213 case TYPE_S3C2410:
David Woodhousee0c7d762006-05-13 18:07:53 +0100214 cfg = S3C2410_NFCONF_EN;
215 cfg |= S3C2410_NFCONF_TACLS(tacls - 1);
216 cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1);
217 cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1);
Ben Dooks2c06a082006-06-27 14:35:46 +0100218 break;
219
220 case TYPE_S3C2440:
221 case TYPE_S3C2412:
David Woodhousee0c7d762006-05-13 18:07:53 +0100222 cfg = S3C2440_NFCONF_TACLS(tacls - 1);
223 cfg |= S3C2440_NFCONF_TWRPH0(twrph0 - 1);
224 cfg |= S3C2440_NFCONF_TWRPH1(twrph1 - 1);
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100225
226 /* enable the controller and de-assert nFCE */
227
Ben Dooks2c06a082006-06-27 14:35:46 +0100228 writel(S3C2440_NFCONT_ENABLE, info->regs + S3C2440_NFCONT);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100229 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Ben Dooks99974c62006-06-21 15:43:05 +0100231 dev_dbg(info->device, "NF_CONF is 0x%lx\n", cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 writel(cfg, info->regs + S3C2410_NFCONF);
234 return 0;
235}
236
237/* select chip */
238
239static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
240{
241 struct s3c2410_nand_info *info;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000242 struct s3c2410_nand_mtd *nmtd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 struct nand_chip *this = mtd->priv;
244 unsigned long cur;
245
246 nmtd = this->priv;
247 info = nmtd->info;
248
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100249 if (chip != -1 && allow_clk_stop(info))
250 clk_enable(info->clk);
251
Ben Dooks2c06a082006-06-27 14:35:46 +0100252 cur = readl(info->sel_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 if (chip == -1) {
Ben Dooks2c06a082006-06-27 14:35:46 +0100255 cur |= info->sel_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 } else {
Ben Dooksfb8d82a2005-07-06 21:05:10 +0100257 if (nmtd->set != NULL && chip > nmtd->set->nr_chips) {
Ben Dooks99974c62006-06-21 15:43:05 +0100258 dev_err(info->device, "invalid chip %d\n", chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return;
260 }
261
262 if (info->platform != NULL) {
263 if (info->platform->select_chip != NULL)
David Woodhousee0c7d762006-05-13 18:07:53 +0100264 (info->platform->select_chip) (nmtd->set, chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 }
266
Ben Dooks2c06a082006-06-27 14:35:46 +0100267 cur &= ~info->sel_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
Ben Dooks2c06a082006-06-27 14:35:46 +0100270 writel(cur, info->sel_reg);
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100271
272 if (chip == -1 && allow_clk_stop(info))
273 clk_disable(info->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274}
275
Ben Dooksad3b5fb2006-06-19 09:43:23 +0100276/* s3c2410_nand_hwcontrol
Ben Dooksa4f957f2005-06-20 12:48:25 +0100277 *
Ben Dooksad3b5fb2006-06-19 09:43:23 +0100278 * Issue command and address cycles to the chip
Ben Dooksa4f957f2005-06-20 12:48:25 +0100279*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200281static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd,
David Woodhousef9068872006-06-10 00:53:16 +0100282 unsigned int ctrl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
284 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
David Woodhousec9ac5972006-11-30 08:17:38 +0000285
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200286 if (cmd == NAND_CMD_NONE)
287 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
David Woodhousef9068872006-06-10 00:53:16 +0100289 if (ctrl & NAND_CLE)
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200290 writeb(cmd, info->regs + S3C2410_NFCMD);
291 else
292 writeb(cmd, info->regs + S3C2410_NFADDR);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100293}
294
295/* command and control functions */
296
David Woodhousef9068872006-06-10 00:53:16 +0100297static void s3c2440_nand_hwcontrol(struct mtd_info *mtd, int cmd,
298 unsigned int ctrl)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100299{
300 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100301
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200302 if (cmd == NAND_CMD_NONE)
303 return;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100304
David Woodhousef9068872006-06-10 00:53:16 +0100305 if (ctrl & NAND_CLE)
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200306 writeb(cmd, info->regs + S3C2440_NFCMD);
307 else
308 writeb(cmd, info->regs + S3C2440_NFADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/* s3c2410_nand_devready()
312 *
313 * returns 0 if the nand is busy, 1 if it is ready
314*/
315
316static int s3c2410_nand_devready(struct mtd_info *mtd)
317{
318 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY;
320}
321
Ben Dooks2c06a082006-06-27 14:35:46 +0100322static int s3c2440_nand_devready(struct mtd_info *mtd)
323{
324 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
325 return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY;
326}
327
328static int s3c2412_nand_devready(struct mtd_info *mtd)
329{
330 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
331 return readb(info->regs + S3C2412_NFSTAT) & S3C2412_NFSTAT_READY;
332}
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334/* ECC handling functions */
335
Ben Dooks2c06a082006-06-27 14:35:46 +0100336static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
337 u_char *read_ecc, u_char *calc_ecc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Ben Dooksa2593242007-02-02 16:59:33 +0000339 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
340 unsigned int diff0, diff1, diff2;
341 unsigned int bit, byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Ben Dooksa2593242007-02-02 16:59:33 +0000343 pr_debug("%s(%p,%p,%p,%p)\n", __func__, mtd, dat, read_ecc, calc_ecc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Ben Dooksa2593242007-02-02 16:59:33 +0000345 diff0 = read_ecc[0] ^ calc_ecc[0];
346 diff1 = read_ecc[1] ^ calc_ecc[1];
347 diff2 = read_ecc[2] ^ calc_ecc[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Ben Dooksa2593242007-02-02 16:59:33 +0000349 pr_debug("%s: rd %02x%02x%02x calc %02x%02x%02x diff %02x%02x%02x\n",
350 __func__,
351 read_ecc[0], read_ecc[1], read_ecc[2],
352 calc_ecc[0], calc_ecc[1], calc_ecc[2],
353 diff0, diff1, diff2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Ben Dooksa2593242007-02-02 16:59:33 +0000355 if (diff0 == 0 && diff1 == 0 && diff2 == 0)
356 return 0; /* ECC is ok */
357
Ben Dooksc45c6c62008-04-15 11:36:20 +0100358 /* sometimes people do not think about using the ECC, so check
359 * to see if we have an 0xff,0xff,0xff read ECC and then ignore
360 * the error, on the assumption that this is an un-eccd page.
361 */
362 if (read_ecc[0] == 0xff && read_ecc[1] == 0xff && read_ecc[2] == 0xff
363 && info->platform->ignore_unset_ecc)
364 return 0;
365
Ben Dooksa2593242007-02-02 16:59:33 +0000366 /* Can we correct this ECC (ie, one row and column change).
367 * Note, this is similar to the 256 error code on smartmedia */
368
369 if (((diff0 ^ (diff0 >> 1)) & 0x55) == 0x55 &&
370 ((diff1 ^ (diff1 >> 1)) & 0x55) == 0x55 &&
371 ((diff2 ^ (diff2 >> 1)) & 0x55) == 0x55) {
372 /* calculate the bit position of the error */
373
Matt Reimerd0bf3792007-10-18 18:02:43 -0700374 bit = ((diff2 >> 3) & 1) |
375 ((diff2 >> 4) & 2) |
376 ((diff2 >> 5) & 4);
Ben Dooksa2593242007-02-02 16:59:33 +0000377
378 /* calculate the byte position of the error */
379
Matt Reimerd0bf3792007-10-18 18:02:43 -0700380 byte = ((diff2 << 7) & 0x100) |
381 ((diff1 << 0) & 0x80) |
382 ((diff1 << 1) & 0x40) |
383 ((diff1 << 2) & 0x20) |
384 ((diff1 << 3) & 0x10) |
385 ((diff0 >> 4) & 0x08) |
386 ((diff0 >> 3) & 0x04) |
387 ((diff0 >> 2) & 0x02) |
388 ((diff0 >> 1) & 0x01);
Ben Dooksa2593242007-02-02 16:59:33 +0000389
390 dev_dbg(info->device, "correcting error bit %d, byte %d\n",
391 bit, byte);
392
393 dat[byte] ^= (1 << bit);
394 return 1;
395 }
396
397 /* if there is only one bit difference in the ECC, then
398 * one of only a row or column parity has changed, which
399 * means the error is most probably in the ECC itself */
400
401 diff0 |= (diff1 << 8);
402 diff0 |= (diff2 << 16);
403
404 if ((diff0 & ~(1<<fls(diff0))) == 0)
405 return 1;
406
Matt Reimer4fac9f62007-10-18 18:02:44 -0700407 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
Ben Dooksa4f957f2005-06-20 12:48:25 +0100410/* ECC functions
411 *
412 * These allow the s3c2410 and s3c2440 to use the controller's ECC
413 * generator block to ECC the data as it passes through]
414*/
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode)
417{
418 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
419 unsigned long ctrl;
420
421 ctrl = readl(info->regs + S3C2410_NFCONF);
422 ctrl |= S3C2410_NFCONF_INITECC;
423 writel(ctrl, info->regs + S3C2410_NFCONF);
424}
425
Matthieu CASTET4f659922007-02-13 12:30:38 +0100426static void s3c2412_nand_enable_hwecc(struct mtd_info *mtd, int mode)
427{
428 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
429 unsigned long ctrl;
430
431 ctrl = readl(info->regs + S3C2440_NFCONT);
432 writel(ctrl | S3C2412_NFCONT_INIT_MAIN_ECC, info->regs + S3C2440_NFCONT);
433}
434
Ben Dooksa4f957f2005-06-20 12:48:25 +0100435static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
436{
437 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
438 unsigned long ctrl;
439
440 ctrl = readl(info->regs + S3C2440_NFCONT);
441 writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT);
442}
443
David Woodhousee0c7d762006-05-13 18:07:53 +0100444static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
446 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
447
448 ecc_code[0] = readb(info->regs + S3C2410_NFECC + 0);
449 ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1);
450 ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2);
451
Ben Dooksa2593242007-02-02 16:59:33 +0000452 pr_debug("%s: returning ecc %02x%02x%02x\n", __func__,
453 ecc_code[0], ecc_code[1], ecc_code[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 return 0;
456}
457
Matthieu CASTET4f659922007-02-13 12:30:38 +0100458static int s3c2412_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
459{
460 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
461 unsigned long ecc = readl(info->regs + S3C2412_NFMECC0);
462
463 ecc_code[0] = ecc;
464 ecc_code[1] = ecc >> 8;
465 ecc_code[2] = ecc >> 16;
466
467 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]);
468
469 return 0;
470}
471
David Woodhousee0c7d762006-05-13 18:07:53 +0100472static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100473{
474 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
475 unsigned long ecc = readl(info->regs + S3C2440_NFMECC0);
476
477 ecc_code[0] = ecc;
478 ecc_code[1] = ecc >> 8;
479 ecc_code[2] = ecc >> 16;
480
Ben Dooks71d54f32008-04-15 11:36:19 +0100481 pr_debug("%s: returning ecc %06lx\n", __func__, ecc & 0xffffff);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100482
483 return 0;
484}
485
Ben Dooksa4f957f2005-06-20 12:48:25 +0100486/* over-ride the standard functions for a little more speed. We can
487 * use read/write block to move the data buffers to/from the controller
488*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
491{
492 struct nand_chip *this = mtd->priv;
493 readsb(this->IO_ADDR_R, buf, len);
494}
495
Matt Reimerb773bb22007-10-18 17:43:07 -0700496static void s3c2440_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
497{
498 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
499 readsl(info->regs + S3C2440_NFDATA, buf, len / 4);
500}
501
David Woodhousee0c7d762006-05-13 18:07:53 +0100502static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
504 struct nand_chip *this = mtd->priv;
505 writesb(this->IO_ADDR_W, buf, len);
506}
507
Matt Reimerb773bb22007-10-18 17:43:07 -0700508static void s3c2440_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
509{
510 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
511 writesl(info->regs + S3C2440_NFDATA, buf, len / 4);
512}
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514/* device management functions */
515
Russell King3ae5eae2005-11-09 22:32:44 +0000516static int s3c2410_nand_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
Russell King3ae5eae2005-11-09 22:32:44 +0000518 struct s3c2410_nand_info *info = to_nand_info(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Russell King3ae5eae2005-11-09 22:32:44 +0000520 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000522 if (info == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 return 0;
524
525 /* first thing we need to do is release all our mtds
526 * and their partitions, then go through freeing the
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000527 * resources used
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 */
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (info->mtds != NULL) {
531 struct s3c2410_nand_mtd *ptr = info->mtds;
532 int mtdno;
533
534 for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) {
535 pr_debug("releasing mtd %d (%p)\n", mtdno, ptr);
536 nand_release(&ptr->mtd);
537 }
538
539 kfree(info->mtds);
540 }
541
542 /* free the common resources */
543
544 if (info->clk != NULL && !IS_ERR(info->clk)) {
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100545 if (!allow_clk_stop(info))
546 clk_disable(info->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 clk_put(info->clk);
548 }
549
550 if (info->regs != NULL) {
551 iounmap(info->regs);
552 info->regs = NULL;
553 }
554
555 if (info->area != NULL) {
556 release_resource(info->area);
557 kfree(info->area);
558 info->area = NULL;
559 }
560
561 kfree(info);
562
563 return 0;
564}
565
566#ifdef CONFIG_MTD_PARTITIONS
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 if (set == NULL)
572 return add_mtd_device(&mtd->mtd);
573
574 if (set->nr_partitions > 0 && set->partitions != NULL) {
David Woodhousee0c7d762006-05-13 18:07:53 +0100575 return add_mtd_partitions(&mtd->mtd, set->partitions, set->nr_partitions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577
578 return add_mtd_device(&mtd->mtd);
579}
580#else
581static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
582 struct s3c2410_nand_mtd *mtd,
583 struct s3c2410_nand_set *set)
584{
585 return add_mtd_device(&mtd->mtd);
586}
587#endif
588
589/* s3c2410_nand_init_chip
590 *
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000591 * init a single instance of an chip
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592*/
593
594static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
595 struct s3c2410_nand_mtd *nmtd,
596 struct s3c2410_nand_set *set)
597{
598 struct nand_chip *chip = &nmtd->chip;
Ben Dooks2c06a082006-06-27 14:35:46 +0100599 void __iomem *regs = info->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 chip->write_buf = s3c2410_nand_write_buf;
602 chip->read_buf = s3c2410_nand_read_buf;
603 chip->select_chip = s3c2410_nand_select_chip;
604 chip->chip_delay = 50;
605 chip->priv = nmtd;
606 chip->options = 0;
607 chip->controller = &info->controller;
608
Ben Dooks2c06a082006-06-27 14:35:46 +0100609 switch (info->cpu_type) {
610 case TYPE_S3C2410:
611 chip->IO_ADDR_W = regs + S3C2410_NFDATA;
612 info->sel_reg = regs + S3C2410_NFCONF;
613 info->sel_bit = S3C2410_NFCONF_nFCE;
614 chip->cmd_ctrl = s3c2410_nand_hwcontrol;
615 chip->dev_ready = s3c2410_nand_devready;
616 break;
617
618 case TYPE_S3C2440:
619 chip->IO_ADDR_W = regs + S3C2440_NFDATA;
620 info->sel_reg = regs + S3C2440_NFCONT;
621 info->sel_bit = S3C2440_NFCONT_nFCE;
622 chip->cmd_ctrl = s3c2440_nand_hwcontrol;
623 chip->dev_ready = s3c2440_nand_devready;
Matt Reimerb773bb22007-10-18 17:43:07 -0700624 chip->read_buf = s3c2440_nand_read_buf;
625 chip->write_buf = s3c2440_nand_write_buf;
Ben Dooks2c06a082006-06-27 14:35:46 +0100626 break;
627
628 case TYPE_S3C2412:
629 chip->IO_ADDR_W = regs + S3C2440_NFDATA;
630 info->sel_reg = regs + S3C2440_NFCONT;
631 info->sel_bit = S3C2412_NFCONT_nFCE0;
632 chip->cmd_ctrl = s3c2440_nand_hwcontrol;
633 chip->dev_ready = s3c2412_nand_devready;
634
635 if (readl(regs + S3C2410_NFCONF) & S3C2412_NFCONF_NANDBOOT)
636 dev_info(info->device, "System booted from NAND\n");
637
638 break;
639 }
640
641 chip->IO_ADDR_R = chip->IO_ADDR_W;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 nmtd->info = info;
644 nmtd->mtd.priv = chip;
David Woodhouse552d9202006-05-14 01:20:46 +0100645 nmtd->mtd.owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 nmtd->set = set;
647
648 if (hardware_ecc) {
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200649 chip->ecc.calculate = s3c2410_nand_calculate_ecc;
Ben Dooks2c06a082006-06-27 14:35:46 +0100650 chip->ecc.correct = s3c2410_nand_correct_data;
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200651 chip->ecc.mode = NAND_ECC_HW;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100652
Ben Dooks2c06a082006-06-27 14:35:46 +0100653 switch (info->cpu_type) {
654 case TYPE_S3C2410:
655 chip->ecc.hwctl = s3c2410_nand_enable_hwecc;
656 chip->ecc.calculate = s3c2410_nand_calculate_ecc;
657 break;
658
659 case TYPE_S3C2412:
Matthieu CASTET4f659922007-02-13 12:30:38 +0100660 chip->ecc.hwctl = s3c2412_nand_enable_hwecc;
661 chip->ecc.calculate = s3c2412_nand_calculate_ecc;
662 break;
663
Ben Dooks2c06a082006-06-27 14:35:46 +0100664 case TYPE_S3C2440:
665 chip->ecc.hwctl = s3c2440_nand_enable_hwecc;
666 chip->ecc.calculate = s3c2440_nand_calculate_ecc;
667 break;
668
Ben Dooksa4f957f2005-06-20 12:48:25 +0100669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 } else {
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200671 chip->ecc.mode = NAND_ECC_SOFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 }
Ben Dooks1c21ab62008-04-15 11:36:21 +0100673
674 if (set->ecc_layout != NULL)
675 chip->ecc.layout = set->ecc_layout;
Ben Dooks37e5ffa2008-04-15 11:36:22 +0100676
677 if (set->disable_ecc)
678 chip->ecc.mode = NAND_ECC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
680
Ben Dooks71d54f32008-04-15 11:36:19 +0100681/* s3c2410_nand_update_chip
682 *
683 * post-probe chip update, to change any items, such as the
684 * layout for large page nand
685 */
686
687static void s3c2410_nand_update_chip(struct s3c2410_nand_info *info,
688 struct s3c2410_nand_mtd *nmtd)
689{
690 struct nand_chip *chip = &nmtd->chip;
691
Ben Dooks451d3392008-05-20 17:32:14 +0100692 dev_dbg(info->device, "chip %p => page shift %d\n",
693 chip, chip->page_shift);
Ben Dooks71d54f32008-04-15 11:36:19 +0100694
695 if (hardware_ecc) {
696 /* change the behaviour depending on wether we are using
697 * the large or small page nand device */
698
699 if (chip->page_shift > 10) {
700 chip->ecc.size = 256;
701 chip->ecc.bytes = 3;
702 } else {
703 chip->ecc.size = 512;
704 chip->ecc.bytes = 3;
705 chip->ecc.layout = &nand_hw_eccoob;
706 }
707 }
708}
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710/* s3c2410_nand_probe
711 *
712 * called by device layer when it finds a device matching
713 * one our driver can handled. This code checks to see if
714 * it can allocate all necessary resources then calls the
715 * nand layer to look for devices
716*/
717
Ben Dooks2c06a082006-06-27 14:35:46 +0100718static int s3c24xx_nand_probe(struct platform_device *pdev,
719 enum s3c_cpu_type cpu_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
Russell King3ae5eae2005-11-09 22:32:44 +0000721 struct s3c2410_platform_nand *plat = to_nand_plat(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 struct s3c2410_nand_info *info;
723 struct s3c2410_nand_mtd *nmtd;
724 struct s3c2410_nand_set *sets;
725 struct resource *res;
726 int err = 0;
727 int size;
728 int nr_sets;
729 int setno;
730
Russell King3ae5eae2005-11-09 22:32:44 +0000731 pr_debug("s3c2410_nand_probe(%p)\n", pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 info = kmalloc(sizeof(*info), GFP_KERNEL);
734 if (info == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000735 dev_err(&pdev->dev, "no memory for flash info\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 err = -ENOMEM;
737 goto exit_error;
738 }
739
740 memzero(info, sizeof(*info));
Russell King3ae5eae2005-11-09 22:32:44 +0000741 platform_set_drvdata(pdev, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743 spin_lock_init(&info->controller.lock);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100744 init_waitqueue_head(&info->controller.wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 /* get the clock source and enable it */
747
Russell King3ae5eae2005-11-09 22:32:44 +0000748 info->clk = clk_get(&pdev->dev, "nand");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 if (IS_ERR(info->clk)) {
Joe Perches898eb712007-10-18 03:06:30 -0700750 dev_err(&pdev->dev, "failed to get clock\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 err = -ENOENT;
752 goto exit_error;
753 }
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 clk_enable(info->clk);
756
757 /* allocate and map the resource */
758
Ben Dooksa4f957f2005-06-20 12:48:25 +0100759 /* currently we assume we have the one resource */
760 res = pdev->resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 size = res->end - res->start + 1;
762
763 info->area = request_mem_region(res->start, size, pdev->name);
764
765 if (info->area == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000766 dev_err(&pdev->dev, "cannot reserve register region\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 err = -ENOENT;
768 goto exit_error;
769 }
770
Russell King3ae5eae2005-11-09 22:32:44 +0000771 info->device = &pdev->dev;
Ben Dooksa4f957f2005-06-20 12:48:25 +0100772 info->platform = plat;
773 info->regs = ioremap(res->start, size);
Ben Dooks2c06a082006-06-27 14:35:46 +0100774 info->cpu_type = cpu_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 if (info->regs == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000777 dev_err(&pdev->dev, "cannot reserve register region\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 err = -EIO;
779 goto exit_error;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Russell King3ae5eae2005-11-09 22:32:44 +0000782 dev_dbg(&pdev->dev, "mapped registers at %p\n", info->regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
784 /* initialise the hardware */
785
Russell King3ae5eae2005-11-09 22:32:44 +0000786 err = s3c2410_nand_inithw(info, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 if (err != 0)
788 goto exit_error;
789
790 sets = (plat != NULL) ? plat->sets : NULL;
791 nr_sets = (plat != NULL) ? plat->nr_sets : 1;
792
793 info->mtd_count = nr_sets;
794
795 /* allocate our information */
796
797 size = nr_sets * sizeof(*info->mtds);
798 info->mtds = kmalloc(size, GFP_KERNEL);
799 if (info->mtds == NULL) {
Russell King3ae5eae2005-11-09 22:32:44 +0000800 dev_err(&pdev->dev, "failed to allocate mtd storage\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 err = -ENOMEM;
802 goto exit_error;
803 }
804
805 memzero(info->mtds, size);
806
807 /* initialise all possible chips */
808
809 nmtd = info->mtds;
810
811 for (setno = 0; setno < nr_sets; setno++, nmtd++) {
David Woodhousee0c7d762006-05-13 18:07:53 +0100812 pr_debug("initialising set %d (%p, info %p)\n", setno, nmtd, info);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 s3c2410_nand_init_chip(info, nmtd, sets);
815
Ben Dooks71d54f32008-04-15 11:36:19 +0100816 nmtd->scan_res = nand_scan_ident(&nmtd->mtd,
817 (sets) ? sets->nr_chips : 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 if (nmtd->scan_res == 0) {
Ben Dooks71d54f32008-04-15 11:36:19 +0100820 s3c2410_nand_update_chip(info, nmtd);
821 nand_scan_tail(&nmtd->mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 s3c2410_nand_add_partition(info, nmtd, sets);
823 }
824
825 if (sets != NULL)
826 sets++;
827 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000828
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100829 if (allow_clk_stop(info)) {
830 dev_info(&pdev->dev, "clock idle support enabled\n");
831 clk_disable(info->clk);
832 }
833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 pr_debug("initialised ok\n");
835 return 0;
836
837 exit_error:
Russell King3ae5eae2005-11-09 22:32:44 +0000838 s3c2410_nand_remove(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 if (err == 0)
841 err = -EINVAL;
842 return err;
843}
844
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100845/* PM Support */
846#ifdef CONFIG_PM
847
848static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
849{
850 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
851
852 if (info) {
Ben Dooks09160832008-04-15 11:36:18 +0100853 info->save_sel = readl(info->sel_reg);
Ben Dooks03680b12007-11-19 23:28:07 +0000854
855 /* For the moment, we must ensure nFCE is high during
856 * the time we are suspended. This really should be
857 * handled by suspending the MTDs we are using, but
858 * that is currently not the case. */
859
Ben Dooks09160832008-04-15 11:36:18 +0100860 writel(info->save_sel | info->sel_bit, info->sel_reg);
Ben Dooks03680b12007-11-19 23:28:07 +0000861
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100862 if (!allow_clk_stop(info))
863 clk_disable(info->clk);
864 }
865
866 return 0;
867}
868
869static int s3c24xx_nand_resume(struct platform_device *dev)
870{
871 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
Ben Dooks09160832008-04-15 11:36:18 +0100872 unsigned long sel;
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100873
874 if (info) {
875 clk_enable(info->clk);
876 s3c2410_nand_inithw(info, dev);
877
Ben Dooks03680b12007-11-19 23:28:07 +0000878 /* Restore the state of the nFCE line. */
879
Ben Dooks09160832008-04-15 11:36:18 +0100880 sel = readl(info->sel_reg);
881 sel &= ~info->sel_bit;
882 sel |= info->save_sel & info->sel_bit;
883 writel(sel, info->sel_reg);
Ben Dooks03680b12007-11-19 23:28:07 +0000884
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100885 if (allow_clk_stop(info))
886 clk_disable(info->clk);
887 }
888
889 return 0;
890}
891
892#else
893#define s3c24xx_nand_suspend NULL
894#define s3c24xx_nand_resume NULL
895#endif
896
Ben Dooksa4f957f2005-06-20 12:48:25 +0100897/* driver device registration */
898
Russell King3ae5eae2005-11-09 22:32:44 +0000899static int s3c2410_nand_probe(struct platform_device *dev)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100900{
Ben Dooks2c06a082006-06-27 14:35:46 +0100901 return s3c24xx_nand_probe(dev, TYPE_S3C2410);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100902}
903
Russell King3ae5eae2005-11-09 22:32:44 +0000904static int s3c2440_nand_probe(struct platform_device *dev)
Ben Dooksa4f957f2005-06-20 12:48:25 +0100905{
Ben Dooks2c06a082006-06-27 14:35:46 +0100906 return s3c24xx_nand_probe(dev, TYPE_S3C2440);
907}
908
909static int s3c2412_nand_probe(struct platform_device *dev)
910{
911 return s3c24xx_nand_probe(dev, TYPE_S3C2412);
Ben Dooksa4f957f2005-06-20 12:48:25 +0100912}
913
Russell King3ae5eae2005-11-09 22:32:44 +0000914static struct platform_driver s3c2410_nand_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 .probe = s3c2410_nand_probe,
916 .remove = s3c2410_nand_remove,
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100917 .suspend = s3c24xx_nand_suspend,
918 .resume = s3c24xx_nand_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000919 .driver = {
920 .name = "s3c2410-nand",
921 .owner = THIS_MODULE,
922 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923};
924
Russell King3ae5eae2005-11-09 22:32:44 +0000925static struct platform_driver s3c2440_nand_driver = {
Ben Dooksa4f957f2005-06-20 12:48:25 +0100926 .probe = s3c2440_nand_probe,
927 .remove = s3c2410_nand_remove,
Ben Dooksd1fef3c2006-06-19 09:29:38 +0100928 .suspend = s3c24xx_nand_suspend,
929 .resume = s3c24xx_nand_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000930 .driver = {
931 .name = "s3c2440-nand",
932 .owner = THIS_MODULE,
933 },
Ben Dooksa4f957f2005-06-20 12:48:25 +0100934};
935
Ben Dooks2c06a082006-06-27 14:35:46 +0100936static struct platform_driver s3c2412_nand_driver = {
937 .probe = s3c2412_nand_probe,
938 .remove = s3c2410_nand_remove,
939 .suspend = s3c24xx_nand_suspend,
940 .resume = s3c24xx_nand_resume,
941 .driver = {
942 .name = "s3c2412-nand",
943 .owner = THIS_MODULE,
944 },
945};
946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947static int __init s3c2410_nand_init(void)
948{
Ben Dooksa4f957f2005-06-20 12:48:25 +0100949 printk("S3C24XX NAND Driver, (c) 2004 Simtec Electronics\n");
950
Ben Dooks2c06a082006-06-27 14:35:46 +0100951 platform_driver_register(&s3c2412_nand_driver);
Russell King3ae5eae2005-11-09 22:32:44 +0000952 platform_driver_register(&s3c2440_nand_driver);
953 return platform_driver_register(&s3c2410_nand_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954}
955
956static void __exit s3c2410_nand_exit(void)
957{
Ben Dooks2c06a082006-06-27 14:35:46 +0100958 platform_driver_unregister(&s3c2412_nand_driver);
Russell King3ae5eae2005-11-09 22:32:44 +0000959 platform_driver_unregister(&s3c2440_nand_driver);
960 platform_driver_unregister(&s3c2410_nand_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961}
962
963module_init(s3c2410_nand_init);
964module_exit(s3c2410_nand_exit);
965
966MODULE_LICENSE("GPL");
967MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
Ben Dooksa4f957f2005-06-20 12:48:25 +0100968MODULE_DESCRIPTION("S3C24XX MTD NAND driver");
Kay Sievers1ff18422008-04-18 13:44:27 -0700969MODULE_ALIAS("platform:s3c2410-nand");
970MODULE_ALIAS("platform:s3c2412-nand");
971MODULE_ALIAS("platform:s3c2440-nand");