Boris Brezillon | 43a0a45 | 2018-02-05 23:01:59 +0100 | [diff] [blame^] | 1 | /* |
Ben Dooks | 7e74a50 | 2008-05-20 17:32:27 +0100 | [diff] [blame] | 2 | * Copyright © 2004-2008 Simtec Electronics |
| 3 | * http://armlinux.simtec.co.uk/ |
Ben Dooks | fdf2fd5 | 2005-02-18 14:46:15 +0000 | [diff] [blame] | 4 | * Ben Dooks <ben@simtec.co.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Ben Dooks | 7e74a50 | 2008-05-20 17:32:27 +0100 | [diff] [blame] | 6 | * Samsung S3C2410/S3C2440/S3C2412 NAND driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
Sachin Kamat | 92aeb5d | 2012-07-16 16:02:23 +0530 | [diff] [blame] | 23 | #define pr_fmt(fmt) "nand-s3c2410: " fmt |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #ifdef CONFIG_MTD_NAND_S3C2410_DEBUG |
| 26 | #define DEBUG |
| 27 | #endif |
| 28 | |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/kernel.h> |
| 32 | #include <linux/string.h> |
Sachin Kamat | d2a89be | 2012-07-16 16:02:24 +0530 | [diff] [blame] | 33 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/ioport.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 35 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/delay.h> |
| 37 | #include <linux/err.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 38 | #include <linux/slab.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 39 | #include <linux/clk.h> |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 40 | #include <linux/cpufreq.h> |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 41 | #include <linux/of.h> |
| 42 | #include <linux/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #include <linux/mtd/mtd.h> |
Boris Brezillon | d4092d7 | 2017-08-04 17:29:10 +0200 | [diff] [blame] | 45 | #include <linux/mtd/rawnand.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/mtd/nand_ecc.h> |
| 47 | #include <linux/mtd/partitions.h> |
| 48 | |
Arnd Bergmann | 436d42c | 2012-08-24 15:22:12 +0200 | [diff] [blame] | 49 | #include <linux/platform_data/mtd-nand-s3c2410.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Sachin Kamat | 02d0186 | 2014-01-10 11:24:13 +0530 | [diff] [blame] | 51 | #define S3C2410_NFREG(x) (x) |
| 52 | |
| 53 | #define S3C2410_NFCONF S3C2410_NFREG(0x00) |
| 54 | #define S3C2410_NFCMD S3C2410_NFREG(0x04) |
| 55 | #define S3C2410_NFADDR S3C2410_NFREG(0x08) |
| 56 | #define S3C2410_NFDATA S3C2410_NFREG(0x0C) |
| 57 | #define S3C2410_NFSTAT S3C2410_NFREG(0x10) |
| 58 | #define S3C2410_NFECC S3C2410_NFREG(0x14) |
| 59 | #define S3C2440_NFCONT S3C2410_NFREG(0x04) |
| 60 | #define S3C2440_NFCMD S3C2410_NFREG(0x08) |
| 61 | #define S3C2440_NFADDR S3C2410_NFREG(0x0C) |
| 62 | #define S3C2440_NFDATA S3C2410_NFREG(0x10) |
| 63 | #define S3C2440_NFSTAT S3C2410_NFREG(0x20) |
| 64 | #define S3C2440_NFMECC0 S3C2410_NFREG(0x2C) |
| 65 | #define S3C2412_NFSTAT S3C2410_NFREG(0x28) |
| 66 | #define S3C2412_NFMECC0 S3C2410_NFREG(0x34) |
| 67 | #define S3C2410_NFCONF_EN (1<<15) |
| 68 | #define S3C2410_NFCONF_INITECC (1<<12) |
| 69 | #define S3C2410_NFCONF_nFCE (1<<11) |
| 70 | #define S3C2410_NFCONF_TACLS(x) ((x)<<8) |
| 71 | #define S3C2410_NFCONF_TWRPH0(x) ((x)<<4) |
| 72 | #define S3C2410_NFCONF_TWRPH1(x) ((x)<<0) |
| 73 | #define S3C2410_NFSTAT_BUSY (1<<0) |
| 74 | #define S3C2440_NFCONF_TACLS(x) ((x)<<12) |
| 75 | #define S3C2440_NFCONF_TWRPH0(x) ((x)<<8) |
| 76 | #define S3C2440_NFCONF_TWRPH1(x) ((x)<<4) |
| 77 | #define S3C2440_NFCONT_INITECC (1<<4) |
| 78 | #define S3C2440_NFCONT_nFCE (1<<1) |
| 79 | #define S3C2440_NFCONT_ENABLE (1<<0) |
| 80 | #define S3C2440_NFSTAT_READY (1<<0) |
| 81 | #define S3C2412_NFCONF_NANDBOOT (1<<31) |
| 82 | #define S3C2412_NFCONT_INIT_MAIN_ECC (1<<5) |
| 83 | #define S3C2412_NFCONT_nFCE0 (1<<1) |
| 84 | #define S3C2412_NFSTAT_READY (1<<0) |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* new oob placement block for use with hardware ecc generation |
| 87 | */ |
Boris Brezillon | bf01e06b | 2016-02-03 20:03:30 +0100 | [diff] [blame] | 88 | static int s3c2410_ooblayout_ecc(struct mtd_info *mtd, int section, |
| 89 | struct mtd_oob_region *oobregion) |
| 90 | { |
| 91 | if (section) |
| 92 | return -ERANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Boris Brezillon | bf01e06b | 2016-02-03 20:03:30 +0100 | [diff] [blame] | 94 | oobregion->offset = 0; |
| 95 | oobregion->length = 3; |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int s3c2410_ooblayout_free(struct mtd_info *mtd, int section, |
| 101 | struct mtd_oob_region *oobregion) |
| 102 | { |
| 103 | if (section) |
| 104 | return -ERANGE; |
| 105 | |
| 106 | oobregion->offset = 8; |
| 107 | oobregion->length = 8; |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static const struct mtd_ooblayout_ops s3c2410_ooblayout_ops = { |
| 113 | .ecc = s3c2410_ooblayout_ecc, |
| 114 | .free = s3c2410_ooblayout_free, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | /* controller and mtd information */ |
| 118 | |
| 119 | struct s3c2410_nand_info; |
| 120 | |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 121 | /** |
| 122 | * struct s3c2410_nand_mtd - driver MTD structure |
| 123 | * @mtd: The MTD instance to pass to the MTD layer. |
| 124 | * @chip: The NAND chip information. |
| 125 | * @set: The platform information supplied for this set of NAND chips. |
| 126 | * @info: Link back to the hardware information. |
| 127 | * @scan_res: The result from calling nand_scan_ident(). |
| 128 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | struct s3c2410_nand_mtd { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | struct nand_chip chip; |
| 131 | struct s3c2410_nand_set *set; |
| 132 | struct s3c2410_nand_info *info; |
| 133 | int scan_res; |
| 134 | }; |
| 135 | |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 136 | enum s3c_cpu_type { |
| 137 | TYPE_S3C2410, |
| 138 | TYPE_S3C2412, |
| 139 | TYPE_S3C2440, |
| 140 | }; |
| 141 | |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 142 | enum s3c_nand_clk_state { |
| 143 | CLOCK_DISABLE = 0, |
| 144 | CLOCK_ENABLE, |
| 145 | CLOCK_SUSPEND, |
| 146 | }; |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | /* overview of the s3c2410 nand state */ |
| 149 | |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 150 | /** |
| 151 | * struct s3c2410_nand_info - NAND controller state. |
| 152 | * @mtds: An array of MTD instances on this controoler. |
| 153 | * @platform: The platform data for this board. |
| 154 | * @device: The platform device we bound to. |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 155 | * @clk: The clock resource for this controller. |
Sachin Kamat | 6f32a3e | 2012-08-21 14:24:09 +0530 | [diff] [blame] | 156 | * @regs: The area mapped for the hardware registers. |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 157 | * @sel_reg: Pointer to the register controlling the NAND selection. |
| 158 | * @sel_bit: The bit in @sel_reg to select the NAND chip. |
| 159 | * @mtd_count: The number of MTDs created from this controller. |
| 160 | * @save_sel: The contents of @sel_reg to be saved over suspend. |
| 161 | * @clk_rate: The clock rate from @clk. |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 162 | * @clk_state: The current clock state. |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 163 | * @cpu_type: The exact type of this controller. |
| 164 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | struct s3c2410_nand_info { |
| 166 | /* mtd info */ |
| 167 | struct nand_hw_control controller; |
| 168 | struct s3c2410_nand_mtd *mtds; |
| 169 | struct s3c2410_platform_nand *platform; |
| 170 | |
| 171 | /* device info */ |
| 172 | struct device *device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | struct clk *clk; |
Ben Dooks | fdf2fd5 | 2005-02-18 14:46:15 +0000 | [diff] [blame] | 174 | void __iomem *regs; |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 175 | void __iomem *sel_reg; |
| 176 | int sel_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | int mtd_count; |
Ben Dooks | 0916083 | 2008-04-15 11:36:18 +0100 | [diff] [blame] | 178 | unsigned long save_sel; |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 179 | unsigned long clk_rate; |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 180 | enum s3c_nand_clk_state clk_state; |
Ben Dooks | 03680b1 | 2007-11-19 23:28:07 +0000 | [diff] [blame] | 181 | |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 182 | enum s3c_cpu_type cpu_type; |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 183 | |
Krzysztof Kozlowski | d9ca77f | 2016-06-27 14:51:38 +0200 | [diff] [blame] | 184 | #ifdef CONFIG_ARM_S3C24XX_CPUFREQ |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 185 | struct notifier_block freq_transition; |
| 186 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 189 | struct s3c24XX_nand_devtype_data { |
| 190 | enum s3c_cpu_type type; |
| 191 | }; |
| 192 | |
| 193 | static const struct s3c24XX_nand_devtype_data s3c2410_nand_devtype_data = { |
| 194 | .type = TYPE_S3C2410, |
| 195 | }; |
| 196 | |
| 197 | static const struct s3c24XX_nand_devtype_data s3c2412_nand_devtype_data = { |
| 198 | .type = TYPE_S3C2412, |
| 199 | }; |
| 200 | |
| 201 | static const struct s3c24XX_nand_devtype_data s3c2440_nand_devtype_data = { |
| 202 | .type = TYPE_S3C2440, |
| 203 | }; |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | /* conversion functions */ |
| 206 | |
| 207 | static struct s3c2410_nand_mtd *s3c2410_nand_mtd_toours(struct mtd_info *mtd) |
| 208 | { |
Boris BREZILLON | 7208b99 | 2015-12-10 09:00:22 +0100 | [diff] [blame] | 209 | return container_of(mtd_to_nand(mtd), struct s3c2410_nand_mtd, |
| 210 | chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | static struct s3c2410_nand_info *s3c2410_nand_mtd_toinfo(struct mtd_info *mtd) |
| 214 | { |
| 215 | return s3c2410_nand_mtd_toours(mtd)->info; |
| 216 | } |
| 217 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 218 | static struct s3c2410_nand_info *to_nand_info(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 220 | return platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 223 | static struct s3c2410_platform_nand *to_nand_plat(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
Jingoo Han | 453810b | 2013-07-30 17:18:33 +0900 | [diff] [blame] | 225 | return dev_get_platdata(&dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 228 | static inline int allow_clk_suspend(struct s3c2410_nand_info *info) |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 229 | { |
Sachin Kamat | a68c5ec | 2012-07-16 16:02:25 +0530 | [diff] [blame] | 230 | #ifdef CONFIG_MTD_NAND_S3C2410_CLKSTOP |
| 231 | return 1; |
| 232 | #else |
| 233 | return 0; |
| 234 | #endif |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 237 | /** |
| 238 | * s3c2410_nand_clk_set_state - Enable, disable or suspend NAND clock. |
| 239 | * @info: The controller instance. |
| 240 | * @new_state: State to which clock should be set. |
| 241 | */ |
| 242 | static void s3c2410_nand_clk_set_state(struct s3c2410_nand_info *info, |
| 243 | enum s3c_nand_clk_state new_state) |
| 244 | { |
| 245 | if (!allow_clk_suspend(info) && new_state == CLOCK_SUSPEND) |
| 246 | return; |
| 247 | |
| 248 | if (info->clk_state == CLOCK_ENABLE) { |
| 249 | if (new_state != CLOCK_ENABLE) |
Vasily Khoruzhick | 887957b | 2014-06-30 22:12:16 +0300 | [diff] [blame] | 250 | clk_disable_unprepare(info->clk); |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 251 | } else { |
| 252 | if (new_state == CLOCK_ENABLE) |
Vasily Khoruzhick | 887957b | 2014-06-30 22:12:16 +0300 | [diff] [blame] | 253 | clk_prepare_enable(info->clk); |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | info->clk_state = new_state; |
| 257 | } |
| 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | /* timing calculations */ |
| 260 | |
Ben Dooks | cfd320f | 2005-10-20 22:22:58 +0100 | [diff] [blame] | 261 | #define NS_IN_KHZ 1000000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 263 | /** |
| 264 | * s3c_nand_calc_rate - calculate timing data. |
| 265 | * @wanted: The cycle time in nanoseconds. |
| 266 | * @clk: The clock rate in kHz. |
| 267 | * @max: The maximum divider value. |
| 268 | * |
| 269 | * Calculate the timing value from the given parameters. |
| 270 | */ |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 271 | static int s3c_nand_calc_rate(int wanted, unsigned long clk, int max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
| 273 | int result; |
| 274 | |
Ben Dooks | 947391c | 2009-05-30 18:34:16 +0100 | [diff] [blame] | 275 | result = DIV_ROUND_UP((wanted * clk), NS_IN_KHZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | pr_debug("result %d from %ld, %d\n", result, clk, wanted); |
| 278 | |
| 279 | if (result > max) { |
Sachin Kamat | 92aeb5d | 2012-07-16 16:02:23 +0530 | [diff] [blame] | 280 | pr_err("%d ns is too big for current clock rate %ld\n", |
| 281 | wanted, clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | return -1; |
| 283 | } |
| 284 | |
| 285 | if (result < 1) |
| 286 | result = 1; |
| 287 | |
| 288 | return result; |
| 289 | } |
| 290 | |
Sachin Kamat | 54cd020 | 2012-07-16 16:02:26 +0530 | [diff] [blame] | 291 | #define to_ns(ticks, clk) (((ticks) * NS_IN_KHZ) / (unsigned int)(clk)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
| 293 | /* controller setup */ |
| 294 | |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 295 | /** |
| 296 | * s3c2410_nand_setrate - setup controller timing information. |
| 297 | * @info: The controller instance. |
| 298 | * |
| 299 | * Given the information supplied by the platform, calculate and set |
| 300 | * the necessary timing registers in the hardware to generate the |
| 301 | * necessary timing cycles to the hardware. |
| 302 | */ |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 303 | static int s3c2410_nand_setrate(struct s3c2410_nand_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 305 | struct s3c2410_platform_nand *plat = info->platform; |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 306 | int tacls_max = (info->cpu_type == TYPE_S3C2412) ? 8 : 4; |
Ben Dooks | cfd320f | 2005-10-20 22:22:58 +0100 | [diff] [blame] | 307 | int tacls, twrph0, twrph1; |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 308 | unsigned long clkrate = clk_get_rate(info->clk); |
Nelson Castillo | 2612e52 | 2009-05-10 15:41:54 -0500 | [diff] [blame] | 309 | unsigned long uninitialized_var(set), cfg, uninitialized_var(mask); |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 310 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | /* calculate the timing information for the controller */ |
| 313 | |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 314 | info->clk_rate = clkrate; |
Ben Dooks | cfd320f | 2005-10-20 22:22:58 +0100 | [diff] [blame] | 315 | clkrate /= 1000; /* turn clock into kHz for ease of use */ |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (plat != NULL) { |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 318 | tacls = s3c_nand_calc_rate(plat->tacls, clkrate, tacls_max); |
| 319 | twrph0 = s3c_nand_calc_rate(plat->twrph0, clkrate, 8); |
| 320 | twrph1 = s3c_nand_calc_rate(plat->twrph1, clkrate, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } else { |
| 322 | /* default timings */ |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 323 | tacls = tacls_max; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | twrph0 = 8; |
| 325 | twrph1 = 8; |
| 326 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | if (tacls < 0 || twrph0 < 0 || twrph1 < 0) { |
Ben Dooks | 99974c6 | 2006-06-21 15:43:05 +0100 | [diff] [blame] | 329 | dev_err(info->device, "cannot get suitable timings\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | return -EINVAL; |
| 331 | } |
| 332 | |
Ben Dooks | 99974c6 | 2006-06-21 15:43:05 +0100 | [diff] [blame] | 333 | dev_info(info->device, "Tacls=%d, %dns Twrph0=%d %dns, Twrph1=%d %dns\n", |
Sachin Kamat | 54cd020 | 2012-07-16 16:02:26 +0530 | [diff] [blame] | 334 | tacls, to_ns(tacls, clkrate), twrph0, to_ns(twrph0, clkrate), |
| 335 | twrph1, to_ns(twrph1, clkrate)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 337 | switch (info->cpu_type) { |
| 338 | case TYPE_S3C2410: |
| 339 | mask = (S3C2410_NFCONF_TACLS(3) | |
| 340 | S3C2410_NFCONF_TWRPH0(7) | |
| 341 | S3C2410_NFCONF_TWRPH1(7)); |
| 342 | set = S3C2410_NFCONF_EN; |
| 343 | set |= S3C2410_NFCONF_TACLS(tacls - 1); |
| 344 | set |= S3C2410_NFCONF_TWRPH0(twrph0 - 1); |
| 345 | set |= S3C2410_NFCONF_TWRPH1(twrph1 - 1); |
| 346 | break; |
| 347 | |
| 348 | case TYPE_S3C2440: |
| 349 | case TYPE_S3C2412: |
Peter Korsgaard | a755a38 | 2009-06-03 13:46:54 +0200 | [diff] [blame] | 350 | mask = (S3C2440_NFCONF_TACLS(tacls_max - 1) | |
| 351 | S3C2440_NFCONF_TWRPH0(7) | |
| 352 | S3C2440_NFCONF_TWRPH1(7)); |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 353 | |
| 354 | set = S3C2440_NFCONF_TACLS(tacls - 1); |
| 355 | set |= S3C2440_NFCONF_TWRPH0(twrph0 - 1); |
| 356 | set |= S3C2440_NFCONF_TWRPH1(twrph1 - 1); |
| 357 | break; |
| 358 | |
| 359 | default: |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 360 | BUG(); |
| 361 | } |
| 362 | |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 363 | local_irq_save(flags); |
| 364 | |
| 365 | cfg = readl(info->regs + S3C2410_NFCONF); |
| 366 | cfg &= ~mask; |
| 367 | cfg |= set; |
| 368 | writel(cfg, info->regs + S3C2410_NFCONF); |
| 369 | |
| 370 | local_irq_restore(flags); |
| 371 | |
Andy Green | ae7304e | 2009-05-10 15:42:02 -0500 | [diff] [blame] | 372 | dev_dbg(info->device, "NF_CONF is 0x%lx\n", cfg); |
| 373 | |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 374 | return 0; |
| 375 | } |
| 376 | |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 377 | /** |
| 378 | * s3c2410_nand_inithw - basic hardware initialisation |
| 379 | * @info: The hardware state. |
| 380 | * |
| 381 | * Do the basic initialisation of the hardware, using s3c2410_nand_setrate() |
| 382 | * to setup the hardware access speeds and set the controller to be enabled. |
| 383 | */ |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 384 | static int s3c2410_nand_inithw(struct s3c2410_nand_info *info) |
| 385 | { |
| 386 | int ret; |
| 387 | |
| 388 | ret = s3c2410_nand_setrate(info); |
| 389 | if (ret < 0) |
| 390 | return ret; |
| 391 | |
Sachin Kamat | 54cd020 | 2012-07-16 16:02:26 +0530 | [diff] [blame] | 392 | switch (info->cpu_type) { |
| 393 | case TYPE_S3C2410: |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 394 | default: |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 395 | break; |
| 396 | |
Sachin Kamat | 54cd020 | 2012-07-16 16:02:26 +0530 | [diff] [blame] | 397 | case TYPE_S3C2440: |
| 398 | case TYPE_S3C2412: |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 399 | /* enable the controller and de-assert nFCE */ |
| 400 | |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 401 | writel(S3C2440_NFCONT_ENABLE, info->regs + S3C2440_NFCONT); |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 407 | /** |
| 408 | * s3c2410_nand_select_chip - select the given nand chip |
| 409 | * @mtd: The MTD instance for this chip. |
| 410 | * @chip: The chip number. |
| 411 | * |
| 412 | * This is called by the MTD layer to either select a given chip for the |
| 413 | * @mtd instance, or to indicate that the access has finished and the |
| 414 | * chip can be de-selected. |
| 415 | * |
| 416 | * The routine ensures that the nFCE line is correctly setup, and any |
| 417 | * platform specific selection code is called to route nFCE to the specific |
| 418 | * chip. |
| 419 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip) |
| 421 | { |
| 422 | struct s3c2410_nand_info *info; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 423 | struct s3c2410_nand_mtd *nmtd; |
Boris BREZILLON | 4bd4ebc | 2015-12-01 12:03:04 +0100 | [diff] [blame] | 424 | struct nand_chip *this = mtd_to_nand(mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | unsigned long cur; |
| 426 | |
Boris BREZILLON | d699ed2 | 2015-12-10 09:00:41 +0100 | [diff] [blame] | 427 | nmtd = nand_get_controller_data(this); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | info = nmtd->info; |
| 429 | |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 430 | if (chip != -1) |
| 431 | s3c2410_nand_clk_set_state(info, CLOCK_ENABLE); |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 432 | |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 433 | cur = readl(info->sel_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | if (chip == -1) { |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 436 | cur |= info->sel_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } else { |
Ben Dooks | fb8d82a | 2005-07-06 21:05:10 +0100 | [diff] [blame] | 438 | if (nmtd->set != NULL && chip > nmtd->set->nr_chips) { |
Ben Dooks | 99974c6 | 2006-06-21 15:43:05 +0100 | [diff] [blame] | 439 | dev_err(info->device, "invalid chip %d\n", chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | return; |
| 441 | } |
| 442 | |
| 443 | if (info->platform != NULL) { |
| 444 | if (info->platform->select_chip != NULL) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 445 | (info->platform->select_chip) (nmtd->set, chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 448 | cur &= ~info->sel_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 451 | writel(cur, info->sel_reg); |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 452 | |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 453 | if (chip == -1) |
| 454 | s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Ben Dooks | ad3b5fb | 2006-06-19 09:43:23 +0100 | [diff] [blame] | 457 | /* s3c2410_nand_hwcontrol |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 458 | * |
Ben Dooks | ad3b5fb | 2006-06-19 09:43:23 +0100 | [diff] [blame] | 459 | * Issue command and address cycles to the chip |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 460 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 462 | static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd, |
David Woodhouse | f906887 | 2006-06-10 00:53:16 +0100 | [diff] [blame] | 463 | unsigned int ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { |
| 465 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
David Woodhouse | c9ac597 | 2006-11-30 08:17:38 +0000 | [diff] [blame] | 466 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 467 | if (cmd == NAND_CMD_NONE) |
| 468 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
David Woodhouse | f906887 | 2006-06-10 00:53:16 +0100 | [diff] [blame] | 470 | if (ctrl & NAND_CLE) |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 471 | writeb(cmd, info->regs + S3C2410_NFCMD); |
| 472 | else |
| 473 | writeb(cmd, info->regs + S3C2410_NFADDR); |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /* command and control functions */ |
| 477 | |
David Woodhouse | f906887 | 2006-06-10 00:53:16 +0100 | [diff] [blame] | 478 | static void s3c2440_nand_hwcontrol(struct mtd_info *mtd, int cmd, |
| 479 | unsigned int ctrl) |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 480 | { |
| 481 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 482 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 483 | if (cmd == NAND_CMD_NONE) |
| 484 | return; |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 485 | |
David Woodhouse | f906887 | 2006-06-10 00:53:16 +0100 | [diff] [blame] | 486 | if (ctrl & NAND_CLE) |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 487 | writeb(cmd, info->regs + S3C2440_NFCMD); |
| 488 | else |
| 489 | writeb(cmd, info->regs + S3C2440_NFADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | /* s3c2410_nand_devready() |
| 493 | * |
| 494 | * returns 0 if the nand is busy, 1 if it is ready |
| 495 | */ |
| 496 | |
| 497 | static int s3c2410_nand_devready(struct mtd_info *mtd) |
| 498 | { |
| 499 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY; |
| 501 | } |
| 502 | |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 503 | static int s3c2440_nand_devready(struct mtd_info *mtd) |
| 504 | { |
| 505 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 506 | return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY; |
| 507 | } |
| 508 | |
| 509 | static int s3c2412_nand_devready(struct mtd_info *mtd) |
| 510 | { |
| 511 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 512 | return readb(info->regs + S3C2412_NFSTAT) & S3C2412_NFSTAT_READY; |
| 513 | } |
| 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | /* ECC handling functions */ |
| 516 | |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 517 | static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat, |
| 518 | u_char *read_ecc, u_char *calc_ecc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
Ben Dooks | a259324 | 2007-02-02 16:59:33 +0000 | [diff] [blame] | 520 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 521 | unsigned int diff0, diff1, diff2; |
| 522 | unsigned int bit, byte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Ben Dooks | a259324 | 2007-02-02 16:59:33 +0000 | [diff] [blame] | 524 | pr_debug("%s(%p,%p,%p,%p)\n", __func__, mtd, dat, read_ecc, calc_ecc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Ben Dooks | a259324 | 2007-02-02 16:59:33 +0000 | [diff] [blame] | 526 | diff0 = read_ecc[0] ^ calc_ecc[0]; |
| 527 | diff1 = read_ecc[1] ^ calc_ecc[1]; |
| 528 | diff2 = read_ecc[2] ^ calc_ecc[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Andy Shevchenko | 13e8597 | 2012-08-02 16:06:47 +0300 | [diff] [blame] | 530 | pr_debug("%s: rd %*phN calc %*phN diff %02x%02x%02x\n", |
| 531 | __func__, 3, read_ecc, 3, calc_ecc, |
Ben Dooks | a259324 | 2007-02-02 16:59:33 +0000 | [diff] [blame] | 532 | diff0, diff1, diff2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Ben Dooks | a259324 | 2007-02-02 16:59:33 +0000 | [diff] [blame] | 534 | if (diff0 == 0 && diff1 == 0 && diff2 == 0) |
| 535 | return 0; /* ECC is ok */ |
| 536 | |
Ben Dooks | c45c6c6 | 2008-04-15 11:36:20 +0100 | [diff] [blame] | 537 | /* sometimes people do not think about using the ECC, so check |
| 538 | * to see if we have an 0xff,0xff,0xff read ECC and then ignore |
| 539 | * the error, on the assumption that this is an un-eccd page. |
| 540 | */ |
| 541 | if (read_ecc[0] == 0xff && read_ecc[1] == 0xff && read_ecc[2] == 0xff |
| 542 | && info->platform->ignore_unset_ecc) |
| 543 | return 0; |
| 544 | |
Ben Dooks | a259324 | 2007-02-02 16:59:33 +0000 | [diff] [blame] | 545 | /* Can we correct this ECC (ie, one row and column change). |
| 546 | * Note, this is similar to the 256 error code on smartmedia */ |
| 547 | |
| 548 | if (((diff0 ^ (diff0 >> 1)) & 0x55) == 0x55 && |
| 549 | ((diff1 ^ (diff1 >> 1)) & 0x55) == 0x55 && |
| 550 | ((diff2 ^ (diff2 >> 1)) & 0x55) == 0x55) { |
| 551 | /* calculate the bit position of the error */ |
| 552 | |
Matt Reimer | d0bf379 | 2007-10-18 18:02:43 -0700 | [diff] [blame] | 553 | bit = ((diff2 >> 3) & 1) | |
| 554 | ((diff2 >> 4) & 2) | |
| 555 | ((diff2 >> 5) & 4); |
Ben Dooks | a259324 | 2007-02-02 16:59:33 +0000 | [diff] [blame] | 556 | |
| 557 | /* calculate the byte position of the error */ |
| 558 | |
Matt Reimer | d0bf379 | 2007-10-18 18:02:43 -0700 | [diff] [blame] | 559 | byte = ((diff2 << 7) & 0x100) | |
| 560 | ((diff1 << 0) & 0x80) | |
| 561 | ((diff1 << 1) & 0x40) | |
| 562 | ((diff1 << 2) & 0x20) | |
| 563 | ((diff1 << 3) & 0x10) | |
| 564 | ((diff0 >> 4) & 0x08) | |
| 565 | ((diff0 >> 3) & 0x04) | |
| 566 | ((diff0 >> 2) & 0x02) | |
| 567 | ((diff0 >> 1) & 0x01); |
Ben Dooks | a259324 | 2007-02-02 16:59:33 +0000 | [diff] [blame] | 568 | |
| 569 | dev_dbg(info->device, "correcting error bit %d, byte %d\n", |
| 570 | bit, byte); |
| 571 | |
| 572 | dat[byte] ^= (1 << bit); |
| 573 | return 1; |
| 574 | } |
| 575 | |
| 576 | /* if there is only one bit difference in the ECC, then |
| 577 | * one of only a row or column parity has changed, which |
| 578 | * means the error is most probably in the ECC itself */ |
| 579 | |
| 580 | diff0 |= (diff1 << 8); |
| 581 | diff0 |= (diff2 << 16); |
| 582 | |
Zhaoxiu Zeng | 03a9755 | 2016-04-12 15:30:35 +0800 | [diff] [blame] | 583 | /* equal to "(diff0 & ~(1 << __ffs(diff0)))" */ |
| 584 | if ((diff0 & (diff0 - 1)) == 0) |
Ben Dooks | a259324 | 2007-02-02 16:59:33 +0000 | [diff] [blame] | 585 | return 1; |
| 586 | |
Matt Reimer | 4fac9f6 | 2007-10-18 18:02:44 -0700 | [diff] [blame] | 587 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 590 | /* ECC functions |
| 591 | * |
| 592 | * These allow the s3c2410 and s3c2440 to use the controller's ECC |
| 593 | * generator block to ECC the data as it passes through] |
| 594 | */ |
| 595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode) |
| 597 | { |
| 598 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 599 | unsigned long ctrl; |
| 600 | |
| 601 | ctrl = readl(info->regs + S3C2410_NFCONF); |
| 602 | ctrl |= S3C2410_NFCONF_INITECC; |
| 603 | writel(ctrl, info->regs + S3C2410_NFCONF); |
| 604 | } |
| 605 | |
Matthieu CASTET | 4f65992 | 2007-02-13 12:30:38 +0100 | [diff] [blame] | 606 | static void s3c2412_nand_enable_hwecc(struct mtd_info *mtd, int mode) |
| 607 | { |
| 608 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 609 | unsigned long ctrl; |
| 610 | |
| 611 | ctrl = readl(info->regs + S3C2440_NFCONT); |
Sachin Kamat | f938bc5 | 2012-08-21 10:21:15 +0530 | [diff] [blame] | 612 | writel(ctrl | S3C2412_NFCONT_INIT_MAIN_ECC, |
| 613 | info->regs + S3C2440_NFCONT); |
Matthieu CASTET | 4f65992 | 2007-02-13 12:30:38 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 616 | static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode) |
| 617 | { |
| 618 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 619 | unsigned long ctrl; |
| 620 | |
| 621 | ctrl = readl(info->regs + S3C2440_NFCONT); |
| 622 | writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT); |
| 623 | } |
| 624 | |
Sachin Kamat | f938bc5 | 2012-08-21 10:21:15 +0530 | [diff] [blame] | 625 | static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, |
| 626 | u_char *ecc_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
| 628 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 629 | |
| 630 | ecc_code[0] = readb(info->regs + S3C2410_NFECC + 0); |
| 631 | ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1); |
| 632 | ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2); |
| 633 | |
Andy Shevchenko | 13e8597 | 2012-08-02 16:06:47 +0300 | [diff] [blame] | 634 | pr_debug("%s: returning ecc %*phN\n", __func__, 3, ecc_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
Sachin Kamat | f938bc5 | 2012-08-21 10:21:15 +0530 | [diff] [blame] | 639 | static int s3c2412_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, |
| 640 | u_char *ecc_code) |
Matthieu CASTET | 4f65992 | 2007-02-13 12:30:38 +0100 | [diff] [blame] | 641 | { |
| 642 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 643 | unsigned long ecc = readl(info->regs + S3C2412_NFMECC0); |
| 644 | |
| 645 | ecc_code[0] = ecc; |
| 646 | ecc_code[1] = ecc >> 8; |
| 647 | ecc_code[2] = ecc >> 16; |
| 648 | |
Andy Shevchenko | 13e8597 | 2012-08-02 16:06:47 +0300 | [diff] [blame] | 649 | pr_debug("%s: returning ecc %*phN\n", __func__, 3, ecc_code); |
Matthieu CASTET | 4f65992 | 2007-02-13 12:30:38 +0100 | [diff] [blame] | 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
Sachin Kamat | f938bc5 | 2012-08-21 10:21:15 +0530 | [diff] [blame] | 654 | static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, |
| 655 | u_char *ecc_code) |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 656 | { |
| 657 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 658 | unsigned long ecc = readl(info->regs + S3C2440_NFMECC0); |
| 659 | |
| 660 | ecc_code[0] = ecc; |
| 661 | ecc_code[1] = ecc >> 8; |
| 662 | ecc_code[2] = ecc >> 16; |
| 663 | |
Ben Dooks | 71d54f3 | 2008-04-15 11:36:19 +0100 | [diff] [blame] | 664 | pr_debug("%s: returning ecc %06lx\n", __func__, ecc & 0xffffff); |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 665 | |
| 666 | return 0; |
| 667 | } |
| 668 | |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 669 | /* over-ride the standard functions for a little more speed. We can |
| 670 | * use read/write block to move the data buffers to/from the controller |
| 671 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
| 673 | static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) |
| 674 | { |
Boris BREZILLON | 4bd4ebc | 2015-12-01 12:03:04 +0100 | [diff] [blame] | 675 | struct nand_chip *this = mtd_to_nand(mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | readsb(this->IO_ADDR_R, buf, len); |
| 677 | } |
| 678 | |
Matt Reimer | b773bb2 | 2007-10-18 17:43:07 -0700 | [diff] [blame] | 679 | static void s3c2440_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) |
| 680 | { |
| 681 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
Ben Dooks | dea2aa6 | 2009-05-30 18:30:18 +0100 | [diff] [blame] | 682 | |
| 683 | readsl(info->regs + S3C2440_NFDATA, buf, len >> 2); |
| 684 | |
| 685 | /* cleanup if we've got less than a word to do */ |
| 686 | if (len & 3) { |
| 687 | buf += len & ~3; |
| 688 | |
| 689 | for (; len & 3; len--) |
| 690 | *buf++ = readb(info->regs + S3C2440_NFDATA); |
| 691 | } |
Matt Reimer | b773bb2 | 2007-10-18 17:43:07 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Sachin Kamat | f938bc5 | 2012-08-21 10:21:15 +0530 | [diff] [blame] | 694 | static void s3c2410_nand_write_buf(struct mtd_info *mtd, const u_char *buf, |
| 695 | int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
Boris BREZILLON | 4bd4ebc | 2015-12-01 12:03:04 +0100 | [diff] [blame] | 697 | struct nand_chip *this = mtd_to_nand(mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | writesb(this->IO_ADDR_W, buf, len); |
| 699 | } |
| 700 | |
Sachin Kamat | f938bc5 | 2012-08-21 10:21:15 +0530 | [diff] [blame] | 701 | static void s3c2440_nand_write_buf(struct mtd_info *mtd, const u_char *buf, |
| 702 | int len) |
Matt Reimer | b773bb2 | 2007-10-18 17:43:07 -0700 | [diff] [blame] | 703 | { |
| 704 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
Ben Dooks | dea2aa6 | 2009-05-30 18:30:18 +0100 | [diff] [blame] | 705 | |
| 706 | writesl(info->regs + S3C2440_NFDATA, buf, len >> 2); |
| 707 | |
| 708 | /* cleanup any fractional write */ |
| 709 | if (len & 3) { |
| 710 | buf += len & ~3; |
| 711 | |
| 712 | for (; len & 3; len--, buf++) |
| 713 | writeb(*buf, info->regs + S3C2440_NFDATA); |
| 714 | } |
Matt Reimer | b773bb2 | 2007-10-18 17:43:07 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 717 | /* cpufreq driver support */ |
| 718 | |
Krzysztof Kozlowski | d9ca77f | 2016-06-27 14:51:38 +0200 | [diff] [blame] | 719 | #ifdef CONFIG_ARM_S3C24XX_CPUFREQ |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 720 | |
| 721 | static int s3c2410_nand_cpufreq_transition(struct notifier_block *nb, |
| 722 | unsigned long val, void *data) |
| 723 | { |
| 724 | struct s3c2410_nand_info *info; |
| 725 | unsigned long newclk; |
| 726 | |
| 727 | info = container_of(nb, struct s3c2410_nand_info, freq_transition); |
| 728 | newclk = clk_get_rate(info->clk); |
| 729 | |
| 730 | if ((val == CPUFREQ_POSTCHANGE && newclk < info->clk_rate) || |
| 731 | (val == CPUFREQ_PRECHANGE && newclk > info->clk_rate)) { |
| 732 | s3c2410_nand_setrate(info); |
| 733 | } |
| 734 | |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | static inline int s3c2410_nand_cpufreq_register(struct s3c2410_nand_info *info) |
| 739 | { |
| 740 | info->freq_transition.notifier_call = s3c2410_nand_cpufreq_transition; |
| 741 | |
| 742 | return cpufreq_register_notifier(&info->freq_transition, |
| 743 | CPUFREQ_TRANSITION_NOTIFIER); |
| 744 | } |
| 745 | |
Sachin Kamat | f938bc5 | 2012-08-21 10:21:15 +0530 | [diff] [blame] | 746 | static inline void |
| 747 | s3c2410_nand_cpufreq_deregister(struct s3c2410_nand_info *info) |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 748 | { |
| 749 | cpufreq_unregister_notifier(&info->freq_transition, |
| 750 | CPUFREQ_TRANSITION_NOTIFIER); |
| 751 | } |
| 752 | |
| 753 | #else |
| 754 | static inline int s3c2410_nand_cpufreq_register(struct s3c2410_nand_info *info) |
| 755 | { |
| 756 | return 0; |
| 757 | } |
| 758 | |
Sachin Kamat | f938bc5 | 2012-08-21 10:21:15 +0530 | [diff] [blame] | 759 | static inline void |
| 760 | s3c2410_nand_cpufreq_deregister(struct s3c2410_nand_info *info) |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 761 | { |
| 762 | } |
| 763 | #endif |
| 764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | /* device management functions */ |
| 766 | |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 767 | static int s3c24xx_nand_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 769 | struct s3c2410_nand_info *info = to_nand_info(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 771 | if (info == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | return 0; |
| 773 | |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 774 | s3c2410_nand_cpufreq_deregister(info); |
| 775 | |
| 776 | /* Release all our mtds and their partitions, then go through |
| 777 | * freeing the resources used |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | */ |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | if (info->mtds != NULL) { |
| 781 | struct s3c2410_nand_mtd *ptr = info->mtds; |
| 782 | int mtdno; |
| 783 | |
| 784 | for (mtdno = 0; mtdno < info->mtd_count; mtdno++, ptr++) { |
| 785 | pr_debug("releasing mtd %d (%p)\n", mtdno, ptr); |
Boris BREZILLON | 7208b99 | 2015-12-10 09:00:22 +0100 | [diff] [blame] | 786 | nand_release(nand_to_mtd(&ptr->chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /* free the common resources */ |
| 791 | |
Sachin Kamat | 6f32a3e | 2012-08-21 14:24:09 +0530 | [diff] [blame] | 792 | if (!IS_ERR(info->clk)) |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 793 | s3c2410_nand_clk_set_state(info, CLOCK_DISABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | return 0; |
| 796 | } |
| 797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info, |
| 799 | struct s3c2410_nand_mtd *mtd, |
| 800 | struct s3c2410_nand_set *set) |
| 801 | { |
Sachin Kamat | ded4c55 | 2012-11-16 16:08:22 +0530 | [diff] [blame] | 802 | if (set) { |
Boris BREZILLON | 7208b99 | 2015-12-10 09:00:22 +0100 | [diff] [blame] | 803 | struct mtd_info *mtdinfo = nand_to_mtd(&mtd->chip); |
Andy Green | ed27f02 | 2009-05-10 15:42:09 -0500 | [diff] [blame] | 804 | |
Boris BREZILLON | 7208b99 | 2015-12-10 09:00:22 +0100 | [diff] [blame] | 805 | mtdinfo->name = set->name; |
| 806 | |
| 807 | return mtd_device_parse_register(mtdinfo, NULL, NULL, |
Artem Bityutskiy | 42d7fbe | 2012-03-09 19:24:26 +0200 | [diff] [blame] | 808 | set->partitions, set->nr_partitions); |
Sachin Kamat | ded4c55 | 2012-11-16 16:08:22 +0530 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | |
Boris Brezillon | 104e442 | 2017-03-16 09:35:58 +0100 | [diff] [blame] | 814 | static int s3c2410_nand_setup_data_interface(struct mtd_info *mtd, int csline, |
| 815 | const struct nand_data_interface *conf) |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 816 | { |
| 817 | struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); |
| 818 | struct s3c2410_platform_nand *pdata = info->platform; |
| 819 | const struct nand_sdr_timings *timings; |
| 820 | int tacls; |
| 821 | |
| 822 | timings = nand_get_sdr_timings(conf); |
| 823 | if (IS_ERR(timings)) |
| 824 | return -ENOTSUPP; |
| 825 | |
| 826 | tacls = timings->tCLS_min - timings->tWP_min; |
| 827 | if (tacls < 0) |
| 828 | tacls = 0; |
| 829 | |
| 830 | pdata->tacls = DIV_ROUND_UP(tacls, 1000); |
| 831 | pdata->twrph0 = DIV_ROUND_UP(timings->tWP_min, 1000); |
| 832 | pdata->twrph1 = DIV_ROUND_UP(timings->tCLH_min, 1000); |
| 833 | |
| 834 | return s3c2410_nand_setrate(info); |
| 835 | } |
| 836 | |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 837 | /** |
| 838 | * s3c2410_nand_init_chip - initialise a single instance of an chip |
| 839 | * @info: The base NAND controller the chip is on. |
| 840 | * @nmtd: The new controller MTD instance to fill in. |
| 841 | * @set: The information passed from the board specific platform data. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | * |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 843 | * Initialise the given @nmtd from the information in @info and @set. This |
| 844 | * readies the structure for use with the MTD layer functions by ensuring |
| 845 | * all pointers are setup and the necessary control routines selected. |
| 846 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info, |
| 848 | struct s3c2410_nand_mtd *nmtd, |
| 849 | struct s3c2410_nand_set *set) |
| 850 | { |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 851 | struct device_node *np = info->device->of_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | struct nand_chip *chip = &nmtd->chip; |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 853 | void __iomem *regs = info->regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 855 | nand_set_flash_node(chip, set->of_node); |
| 856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | chip->write_buf = s3c2410_nand_write_buf; |
| 858 | chip->read_buf = s3c2410_nand_read_buf; |
| 859 | chip->select_chip = s3c2410_nand_select_chip; |
| 860 | chip->chip_delay = 50; |
Boris BREZILLON | d699ed2 | 2015-12-10 09:00:41 +0100 | [diff] [blame] | 861 | nand_set_controller_data(chip, nmtd); |
Ben Dooks | 74218fe | 2009-11-02 18:12:51 +0000 | [diff] [blame] | 862 | chip->options = set->options; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | chip->controller = &info->controller; |
| 864 | |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 865 | /* |
| 866 | * let's keep behavior unchanged for legacy boards booting via pdata and |
| 867 | * auto-detect timings only when booting with a device tree. |
| 868 | */ |
| 869 | if (np) |
| 870 | chip->setup_data_interface = s3c2410_nand_setup_data_interface; |
| 871 | |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 872 | switch (info->cpu_type) { |
| 873 | case TYPE_S3C2410: |
| 874 | chip->IO_ADDR_W = regs + S3C2410_NFDATA; |
| 875 | info->sel_reg = regs + S3C2410_NFCONF; |
| 876 | info->sel_bit = S3C2410_NFCONF_nFCE; |
| 877 | chip->cmd_ctrl = s3c2410_nand_hwcontrol; |
| 878 | chip->dev_ready = s3c2410_nand_devready; |
| 879 | break; |
| 880 | |
| 881 | case TYPE_S3C2440: |
| 882 | chip->IO_ADDR_W = regs + S3C2440_NFDATA; |
| 883 | info->sel_reg = regs + S3C2440_NFCONT; |
| 884 | info->sel_bit = S3C2440_NFCONT_nFCE; |
| 885 | chip->cmd_ctrl = s3c2440_nand_hwcontrol; |
| 886 | chip->dev_ready = s3c2440_nand_devready; |
Matt Reimer | b773bb2 | 2007-10-18 17:43:07 -0700 | [diff] [blame] | 887 | chip->read_buf = s3c2440_nand_read_buf; |
| 888 | chip->write_buf = s3c2440_nand_write_buf; |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case TYPE_S3C2412: |
| 892 | chip->IO_ADDR_W = regs + S3C2440_NFDATA; |
| 893 | info->sel_reg = regs + S3C2440_NFCONT; |
| 894 | info->sel_bit = S3C2412_NFCONT_nFCE0; |
| 895 | chip->cmd_ctrl = s3c2440_nand_hwcontrol; |
| 896 | chip->dev_ready = s3c2412_nand_devready; |
| 897 | |
| 898 | if (readl(regs + S3C2410_NFCONF) & S3C2412_NFCONF_NANDBOOT) |
| 899 | dev_info(info->device, "System booted from NAND\n"); |
| 900 | |
| 901 | break; |
Sachin Kamat | 54cd020 | 2012-07-16 16:02:26 +0530 | [diff] [blame] | 902 | } |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 903 | |
| 904 | chip->IO_ADDR_R = chip->IO_ADDR_W; |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | nmtd->info = info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | nmtd->set = set; |
| 908 | |
Sergio Prado | e9f66ae | 2016-10-20 19:42:44 -0200 | [diff] [blame] | 909 | chip->ecc.mode = info->platform->ecc_mode; |
Michel Pollet | 9db41f9 | 2009-05-13 16:54:14 +0100 | [diff] [blame] | 910 | |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 911 | /* |
| 912 | * If you use u-boot BBT creation code, specifying this flag will |
| 913 | * let the kernel fish out the BBT from the NAND. |
| 914 | */ |
| 915 | if (set->flash_bbt) |
Brian Norris | bb9ebd4 | 2011-05-31 16:31:23 -0700 | [diff] [blame] | 916 | chip->bbt_options |= NAND_BBT_USE_FLASH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 919 | /** |
| 920 | * s3c2410_nand_update_chip - post probe update |
| 921 | * @info: The controller instance. |
| 922 | * @nmtd: The driver version of the MTD instance. |
Ben Dooks | 71d54f3 | 2008-04-15 11:36:19 +0100 | [diff] [blame] | 923 | * |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 924 | * This routine is called after the chip probe has successfully completed |
Ben Dooks | 3db7215 | 2009-05-30 17:18:15 +0100 | [diff] [blame] | 925 | * and the relevant per-chip information updated. This call ensure that |
| 926 | * we update the internal state accordingly. |
| 927 | * |
| 928 | * The internal state is currently limited to the ECC state information. |
| 929 | */ |
Sergio Prado | e9f66ae | 2016-10-20 19:42:44 -0200 | [diff] [blame] | 930 | static int s3c2410_nand_update_chip(struct s3c2410_nand_info *info, |
| 931 | struct s3c2410_nand_mtd *nmtd) |
Ben Dooks | 71d54f3 | 2008-04-15 11:36:19 +0100 | [diff] [blame] | 932 | { |
| 933 | struct nand_chip *chip = &nmtd->chip; |
| 934 | |
Sergio Prado | e9f66ae | 2016-10-20 19:42:44 -0200 | [diff] [blame] | 935 | switch (chip->ecc.mode) { |
Ben Dooks | 71d54f3 | 2008-04-15 11:36:19 +0100 | [diff] [blame] | 936 | |
Sergio Prado | e9f66ae | 2016-10-20 19:42:44 -0200 | [diff] [blame] | 937 | case NAND_ECC_NONE: |
| 938 | dev_info(info->device, "ECC disabled\n"); |
| 939 | break; |
| 940 | |
| 941 | case NAND_ECC_SOFT: |
| 942 | /* |
| 943 | * This driver expects Hamming based ECC when ecc_mode is set |
| 944 | * to NAND_ECC_SOFT. Force ecc.algo to NAND_ECC_HAMMING to |
| 945 | * avoid adding an extra ecc_algo field to |
| 946 | * s3c2410_platform_nand. |
| 947 | */ |
| 948 | chip->ecc.algo = NAND_ECC_HAMMING; |
| 949 | dev_info(info->device, "soft ECC\n"); |
| 950 | break; |
| 951 | |
| 952 | case NAND_ECC_HW: |
| 953 | chip->ecc.calculate = s3c2410_nand_calculate_ecc; |
| 954 | chip->ecc.correct = s3c2410_nand_correct_data; |
| 955 | chip->ecc.strength = 1; |
| 956 | |
| 957 | switch (info->cpu_type) { |
| 958 | case TYPE_S3C2410: |
| 959 | chip->ecc.hwctl = s3c2410_nand_enable_hwecc; |
| 960 | chip->ecc.calculate = s3c2410_nand_calculate_ecc; |
| 961 | break; |
| 962 | |
| 963 | case TYPE_S3C2412: |
| 964 | chip->ecc.hwctl = s3c2412_nand_enable_hwecc; |
| 965 | chip->ecc.calculate = s3c2412_nand_calculate_ecc; |
| 966 | break; |
| 967 | |
| 968 | case TYPE_S3C2440: |
| 969 | chip->ecc.hwctl = s3c2440_nand_enable_hwecc; |
| 970 | chip->ecc.calculate = s3c2440_nand_calculate_ecc; |
| 971 | break; |
| 972 | } |
| 973 | |
| 974 | dev_dbg(info->device, "chip %p => page shift %d\n", |
| 975 | chip, chip->page_shift); |
Andy Green | 8c3e843 | 2009-05-10 15:41:25 -0500 | [diff] [blame] | 976 | |
Adam Buchbinder | 48fc7f7 | 2012-09-19 21:48:00 -0400 | [diff] [blame] | 977 | /* change the behaviour depending on whether we are using |
Ben Dooks | 71d54f3 | 2008-04-15 11:36:19 +0100 | [diff] [blame] | 978 | * the large or small page nand device */ |
Sergio Prado | e9f66ae | 2016-10-20 19:42:44 -0200 | [diff] [blame] | 979 | if (chip->page_shift > 10) { |
| 980 | chip->ecc.size = 256; |
| 981 | chip->ecc.bytes = 3; |
| 982 | } else { |
| 983 | chip->ecc.size = 512; |
| 984 | chip->ecc.bytes = 3; |
| 985 | mtd_set_ooblayout(nand_to_mtd(chip), |
| 986 | &s3c2410_ooblayout_ops); |
| 987 | } |
Ben Dooks | 71d54f3 | 2008-04-15 11:36:19 +0100 | [diff] [blame] | 988 | |
Sergio Prado | e9f66ae | 2016-10-20 19:42:44 -0200 | [diff] [blame] | 989 | dev_info(info->device, "hardware ECC\n"); |
| 990 | break; |
| 991 | |
| 992 | default: |
| 993 | dev_err(info->device, "invalid ECC mode!\n"); |
| 994 | return -EINVAL; |
Ben Dooks | 71d54f3 | 2008-04-15 11:36:19 +0100 | [diff] [blame] | 995 | } |
Sergio Prado | e9f66ae | 2016-10-20 19:42:44 -0200 | [diff] [blame] | 996 | |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 997 | if (chip->bbt_options & NAND_BBT_USE_FLASH) |
| 998 | chip->options |= NAND_SKIP_BBTSCAN; |
| 999 | |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
| 1003 | static const struct of_device_id s3c24xx_nand_dt_ids[] = { |
| 1004 | { |
| 1005 | .compatible = "samsung,s3c2410-nand", |
| 1006 | .data = &s3c2410_nand_devtype_data, |
| 1007 | }, { |
| 1008 | /* also compatible with s3c6400 */ |
| 1009 | .compatible = "samsung,s3c2412-nand", |
| 1010 | .data = &s3c2412_nand_devtype_data, |
| 1011 | }, { |
| 1012 | .compatible = "samsung,s3c2440-nand", |
| 1013 | .data = &s3c2440_nand_devtype_data, |
| 1014 | }, |
| 1015 | { /* sentinel */ } |
| 1016 | }; |
| 1017 | MODULE_DEVICE_TABLE(of, s3c24xx_nand_dt_ids); |
| 1018 | |
| 1019 | static int s3c24xx_nand_probe_dt(struct platform_device *pdev) |
| 1020 | { |
| 1021 | const struct s3c24XX_nand_devtype_data *devtype_data; |
| 1022 | struct s3c2410_platform_nand *pdata; |
| 1023 | struct s3c2410_nand_info *info = platform_get_drvdata(pdev); |
| 1024 | struct device_node *np = pdev->dev.of_node, *child; |
| 1025 | struct s3c2410_nand_set *sets; |
| 1026 | |
| 1027 | devtype_data = of_device_get_match_data(&pdev->dev); |
| 1028 | if (!devtype_data) |
| 1029 | return -ENODEV; |
| 1030 | |
| 1031 | info->cpu_type = devtype_data->type; |
| 1032 | |
| 1033 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 1034 | if (!pdata) |
| 1035 | return -ENOMEM; |
| 1036 | |
| 1037 | pdev->dev.platform_data = pdata; |
| 1038 | |
| 1039 | pdata->nr_sets = of_get_child_count(np); |
| 1040 | if (!pdata->nr_sets) |
| 1041 | return 0; |
| 1042 | |
| 1043 | sets = devm_kzalloc(&pdev->dev, sizeof(*sets) * pdata->nr_sets, |
| 1044 | GFP_KERNEL); |
| 1045 | if (!sets) |
| 1046 | return -ENOMEM; |
| 1047 | |
| 1048 | pdata->sets = sets; |
| 1049 | |
| 1050 | for_each_available_child_of_node(np, child) { |
| 1051 | sets->name = (char *)child->name; |
| 1052 | sets->of_node = child; |
| 1053 | sets->nr_chips = 1; |
| 1054 | |
| 1055 | of_node_get(child); |
| 1056 | |
| 1057 | sets++; |
| 1058 | } |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | static int s3c24xx_nand_probe_pdata(struct platform_device *pdev) |
| 1064 | { |
| 1065 | struct s3c2410_nand_info *info = platform_get_drvdata(pdev); |
| 1066 | |
| 1067 | info->cpu_type = platform_get_device_id(pdev)->driver_data; |
| 1068 | |
Sergio Prado | e9f66ae | 2016-10-20 19:42:44 -0200 | [diff] [blame] | 1069 | return 0; |
Ben Dooks | 71d54f3 | 2008-04-15 11:36:19 +0100 | [diff] [blame] | 1070 | } |
| 1071 | |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 1072 | /* s3c24xx_nand_probe |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | * |
| 1074 | * called by device layer when it finds a device matching |
| 1075 | * one our driver can handled. This code checks to see if |
| 1076 | * it can allocate all necessary resources then calls the |
| 1077 | * nand layer to look for devices |
| 1078 | */ |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 1079 | static int s3c24xx_nand_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | { |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 1081 | struct s3c2410_platform_nand *plat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | struct s3c2410_nand_info *info; |
| 1083 | struct s3c2410_nand_mtd *nmtd; |
| 1084 | struct s3c2410_nand_set *sets; |
| 1085 | struct resource *res; |
| 1086 | int err = 0; |
| 1087 | int size; |
| 1088 | int nr_sets; |
| 1089 | int setno; |
| 1090 | |
Sachin Kamat | 6f32a3e | 2012-08-21 14:24:09 +0530 | [diff] [blame] | 1091 | info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | if (info == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | err = -ENOMEM; |
| 1094 | goto exit_error; |
| 1095 | } |
| 1096 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1097 | platform_set_drvdata(pdev, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
Marc Gonzalez | d45bc58 | 2016-07-27 11:23:52 +0200 | [diff] [blame] | 1099 | nand_hw_control_init(&info->controller); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | |
| 1101 | /* get the clock source and enable it */ |
| 1102 | |
Sachin Kamat | 6f32a3e | 2012-08-21 14:24:09 +0530 | [diff] [blame] | 1103 | info->clk = devm_clk_get(&pdev->dev, "nand"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | if (IS_ERR(info->clk)) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1105 | dev_err(&pdev->dev, "failed to get clock\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | err = -ENOENT; |
| 1107 | goto exit_error; |
| 1108 | } |
| 1109 | |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 1110 | s3c2410_nand_clk_set_state(info, CLOCK_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 1112 | if (pdev->dev.of_node) |
| 1113 | err = s3c24xx_nand_probe_dt(pdev); |
| 1114 | else |
| 1115 | err = s3c24xx_nand_probe_pdata(pdev); |
| 1116 | |
| 1117 | if (err) |
| 1118 | goto exit_error; |
| 1119 | |
| 1120 | plat = to_nand_plat(pdev); |
| 1121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | /* allocate and map the resource */ |
| 1123 | |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 1124 | /* currently we assume we have the one resource */ |
Sachin Kamat | 6f32a3e | 2012-08-21 14:24:09 +0530 | [diff] [blame] | 1125 | res = pdev->resource; |
H Hartley Sweeten | fc161c4 | 2009-12-14 16:56:22 -0500 | [diff] [blame] | 1126 | size = resource_size(res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | |
Sachin Kamat | 6f32a3e | 2012-08-21 14:24:09 +0530 | [diff] [blame] | 1128 | info->device = &pdev->dev; |
| 1129 | info->platform = plat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
Thierry Reding | b0de774 | 2013-01-21 11:09:12 +0100 | [diff] [blame] | 1131 | info->regs = devm_ioremap_resource(&pdev->dev, res); |
| 1132 | if (IS_ERR(info->regs)) { |
| 1133 | err = PTR_ERR(info->regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | goto exit_error; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1137 | dev_dbg(&pdev->dev, "mapped registers at %p\n", info->regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | sets = (plat != NULL) ? plat->sets : NULL; |
| 1140 | nr_sets = (plat != NULL) ? plat->nr_sets : 1; |
| 1141 | |
| 1142 | info->mtd_count = nr_sets; |
| 1143 | |
| 1144 | /* allocate our information */ |
| 1145 | |
| 1146 | size = nr_sets * sizeof(*info->mtds); |
Sachin Kamat | 6f32a3e | 2012-08-21 14:24:09 +0530 | [diff] [blame] | 1147 | info->mtds = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | if (info->mtds == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | err = -ENOMEM; |
| 1150 | goto exit_error; |
| 1151 | } |
| 1152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | /* initialise all possible chips */ |
| 1154 | |
| 1155 | nmtd = info->mtds; |
| 1156 | |
| 1157 | for (setno = 0; setno < nr_sets; setno++, nmtd++) { |
Boris BREZILLON | 7208b99 | 2015-12-10 09:00:22 +0100 | [diff] [blame] | 1158 | struct mtd_info *mtd = nand_to_mtd(&nmtd->chip); |
| 1159 | |
Sachin Kamat | f938bc5 | 2012-08-21 10:21:15 +0530 | [diff] [blame] | 1160 | pr_debug("initialising set %d (%p, info %p)\n", |
| 1161 | setno, nmtd, info); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1162 | |
Boris BREZILLON | 7208b99 | 2015-12-10 09:00:22 +0100 | [diff] [blame] | 1163 | mtd->dev.parent = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | s3c2410_nand_init_chip(info, nmtd, sets); |
| 1165 | |
Boris BREZILLON | 7208b99 | 2015-12-10 09:00:22 +0100 | [diff] [blame] | 1166 | nmtd->scan_res = nand_scan_ident(mtd, |
David Woodhouse | 5e81e88 | 2010-02-26 18:32:56 +0000 | [diff] [blame] | 1167 | (sets) ? sets->nr_chips : 1, |
| 1168 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
| 1170 | if (nmtd->scan_res == 0) { |
Sergio Prado | e9f66ae | 2016-10-20 19:42:44 -0200 | [diff] [blame] | 1171 | err = s3c2410_nand_update_chip(info, nmtd); |
| 1172 | if (err < 0) |
| 1173 | goto exit_error; |
Boris BREZILLON | 7208b99 | 2015-12-10 09:00:22 +0100 | [diff] [blame] | 1174 | nand_scan_tail(mtd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | s3c2410_nand_add_partition(info, nmtd, sets); |
| 1176 | } |
| 1177 | |
| 1178 | if (sets != NULL) |
| 1179 | sets++; |
| 1180 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1181 | |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 1182 | /* initialise the hardware */ |
| 1183 | err = s3c2410_nand_inithw(info); |
| 1184 | if (err != 0) |
| 1185 | goto exit_error; |
| 1186 | |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 1187 | err = s3c2410_nand_cpufreq_register(info); |
| 1188 | if (err < 0) { |
| 1189 | dev_err(&pdev->dev, "failed to init cpufreq support\n"); |
| 1190 | goto exit_error; |
| 1191 | } |
| 1192 | |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 1193 | if (allow_clk_suspend(info)) { |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 1194 | dev_info(&pdev->dev, "clock idle support enabled\n"); |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 1195 | s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND); |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | return 0; |
| 1199 | |
| 1200 | exit_error: |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 1201 | s3c24xx_nand_remove(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | |
| 1203 | if (err == 0) |
| 1204 | err = -EINVAL; |
| 1205 | return err; |
| 1206 | } |
| 1207 | |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 1208 | /* PM Support */ |
| 1209 | #ifdef CONFIG_PM |
| 1210 | |
| 1211 | static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm) |
| 1212 | { |
| 1213 | struct s3c2410_nand_info *info = platform_get_drvdata(dev); |
| 1214 | |
| 1215 | if (info) { |
Ben Dooks | 0916083 | 2008-04-15 11:36:18 +0100 | [diff] [blame] | 1216 | info->save_sel = readl(info->sel_reg); |
Ben Dooks | 03680b1 | 2007-11-19 23:28:07 +0000 | [diff] [blame] | 1217 | |
| 1218 | /* For the moment, we must ensure nFCE is high during |
| 1219 | * the time we are suspended. This really should be |
| 1220 | * handled by suspending the MTDs we are using, but |
| 1221 | * that is currently not the case. */ |
| 1222 | |
Ben Dooks | 0916083 | 2008-04-15 11:36:18 +0100 | [diff] [blame] | 1223 | writel(info->save_sel | info->sel_bit, info->sel_reg); |
Ben Dooks | 03680b1 | 2007-11-19 23:28:07 +0000 | [diff] [blame] | 1224 | |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 1225 | s3c2410_nand_clk_set_state(info, CLOCK_DISABLE); |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
| 1231 | static int s3c24xx_nand_resume(struct platform_device *dev) |
| 1232 | { |
| 1233 | struct s3c2410_nand_info *info = platform_get_drvdata(dev); |
Ben Dooks | 0916083 | 2008-04-15 11:36:18 +0100 | [diff] [blame] | 1234 | unsigned long sel; |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 1235 | |
| 1236 | if (info) { |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 1237 | s3c2410_nand_clk_set_state(info, CLOCK_ENABLE); |
Ben Dooks | 30821fe | 2008-07-15 11:58:31 +0100 | [diff] [blame] | 1238 | s3c2410_nand_inithw(info); |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 1239 | |
Ben Dooks | 03680b1 | 2007-11-19 23:28:07 +0000 | [diff] [blame] | 1240 | /* Restore the state of the nFCE line. */ |
| 1241 | |
Ben Dooks | 0916083 | 2008-04-15 11:36:18 +0100 | [diff] [blame] | 1242 | sel = readl(info->sel_reg); |
| 1243 | sel &= ~info->sel_bit; |
| 1244 | sel |= info->save_sel & info->sel_bit; |
| 1245 | writel(sel, info->sel_reg); |
Ben Dooks | 03680b1 | 2007-11-19 23:28:07 +0000 | [diff] [blame] | 1246 | |
Jiri Pinkava | ac497c1 | 2011-04-13 11:59:30 +0200 | [diff] [blame] | 1247 | s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND); |
Ben Dooks | d1fef3c | 2006-06-19 09:29:38 +0100 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | #else |
| 1254 | #define s3c24xx_nand_suspend NULL |
| 1255 | #define s3c24xx_nand_resume NULL |
| 1256 | #endif |
| 1257 | |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 1258 | /* driver device registration */ |
| 1259 | |
Krzysztof Kozlowski | 0abe75d | 2015-05-02 00:50:02 +0900 | [diff] [blame] | 1260 | static const struct platform_device_id s3c24xx_driver_ids[] = { |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 1261 | { |
| 1262 | .name = "s3c2410-nand", |
| 1263 | .driver_data = TYPE_S3C2410, |
| 1264 | }, { |
| 1265 | .name = "s3c2440-nand", |
| 1266 | .driver_data = TYPE_S3C2440, |
| 1267 | }, { |
| 1268 | .name = "s3c2412-nand", |
| 1269 | .driver_data = TYPE_S3C2412, |
Peter Korsgaard | 9dbc090 | 2009-06-07 06:04:23 -0700 | [diff] [blame] | 1270 | }, { |
| 1271 | .name = "s3c6400-nand", |
| 1272 | .driver_data = TYPE_S3C2412, /* compatible with 2412 */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1273 | }, |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 1274 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | }; |
| 1276 | |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 1277 | MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 1278 | |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 1279 | static struct platform_driver s3c24xx_nand_driver = { |
| 1280 | .probe = s3c24xx_nand_probe, |
| 1281 | .remove = s3c24xx_nand_remove, |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 1282 | .suspend = s3c24xx_nand_suspend, |
| 1283 | .resume = s3c24xx_nand_resume, |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 1284 | .id_table = s3c24xx_driver_ids, |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 1285 | .driver = { |
Ben Dooks | ec0482e | 2009-05-30 16:55:29 +0100 | [diff] [blame] | 1286 | .name = "s3c24xx-nand", |
Sergio Prado | 1c825ad | 2016-10-26 21:59:55 -0200 | [diff] [blame] | 1287 | .of_match_table = s3c24xx_nand_dt_ids, |
Ben Dooks | 2c06a08 | 2006-06-27 14:35:46 +0100 | [diff] [blame] | 1288 | }, |
| 1289 | }; |
| 1290 | |
Sachin Kamat | 056fcab | 2012-07-16 16:02:22 +0530 | [diff] [blame] | 1291 | module_platform_driver(s3c24xx_nand_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
| 1293 | MODULE_LICENSE("GPL"); |
| 1294 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); |
Ben Dooks | a4f957f | 2005-06-20 12:48:25 +0100 | [diff] [blame] | 1295 | MODULE_DESCRIPTION("S3C24XX MTD NAND driver"); |