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