blob: b7d5a5b9a5434f8ee1d7b0ab7b686aa052f17954 [file] [log] [blame]
Sascha Hauer34f6e152008-09-02 17:16:59 +02001/*
2 * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301, USA.
18 */
19
20#include <linux/delay.h>
21#include <linux/slab.h>
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/mtd/mtd.h>
25#include <linux/mtd/nand.h>
26#include <linux/mtd/partitions.h>
27#include <linux/interrupt.h>
28#include <linux/device.h>
29#include <linux/platform_device.h>
30#include <linux/clk.h>
31#include <linux/err.h>
32#include <linux/io.h>
Sascha Hauer63f14742010-10-18 10:16:26 +020033#include <linux/irq.h>
34#include <linux/completion.h>
Sascha Hauer34f6e152008-09-02 17:16:59 +020035
36#include <asm/mach/flash.h>
37#include <mach/mxc_nand.h>
Sascha Hauer94671142009-10-05 12:14:21 +020038#include <mach/hardware.h>
Sascha Hauer34f6e152008-09-02 17:16:59 +020039
40#define DRIVER_NAME "mxc_nand"
41
Sascha Hauer94671142009-10-05 12:14:21 +020042#define nfc_is_v21() (cpu_is_mx25() || cpu_is_mx35())
Ivo Claryssea47bfd22010-04-08 16:16:51 +020043#define nfc_is_v1() (cpu_is_mx31() || cpu_is_mx27() || cpu_is_mx21())
Sascha Hauer71ec5152010-08-06 15:53:11 +020044#define nfc_is_v3_2() cpu_is_mx51()
45#define nfc_is_v3() nfc_is_v3_2()
Sascha Hauer94671142009-10-05 12:14:21 +020046
Sascha Hauer34f6e152008-09-02 17:16:59 +020047/* Addresses for NFC registers */
Sascha Hauer1bc99182010-08-06 15:53:08 +020048#define NFC_V1_V2_BUF_SIZE (host->regs + 0x00)
49#define NFC_V1_V2_BUF_ADDR (host->regs + 0x04)
50#define NFC_V1_V2_FLASH_ADDR (host->regs + 0x06)
51#define NFC_V1_V2_FLASH_CMD (host->regs + 0x08)
52#define NFC_V1_V2_CONFIG (host->regs + 0x0a)
53#define NFC_V1_V2_ECC_STATUS_RESULT (host->regs + 0x0c)
54#define NFC_V1_V2_RSLTMAIN_AREA (host->regs + 0x0e)
55#define NFC_V1_V2_RSLTSPARE_AREA (host->regs + 0x10)
56#define NFC_V1_V2_WRPROT (host->regs + 0x12)
57#define NFC_V1_UNLOCKSTART_BLKADDR (host->regs + 0x14)
58#define NFC_V1_UNLOCKEND_BLKADDR (host->regs + 0x16)
59#define NFC_V21_UNLOCKSTART_BLKADDR (host->regs + 0x20)
60#define NFC_V21_UNLOCKEND_BLKADDR (host->regs + 0x22)
61#define NFC_V1_V2_NF_WRPRST (host->regs + 0x18)
62#define NFC_V1_V2_CONFIG1 (host->regs + 0x1a)
63#define NFC_V1_V2_CONFIG2 (host->regs + 0x1c)
Sascha Hauer34f6e152008-09-02 17:16:59 +020064
Sascha Hauer6e85dfd2010-08-06 15:53:10 +020065#define NFC_V2_CONFIG1_ECC_MODE_4 (1 << 0)
Sascha Hauer1bc99182010-08-06 15:53:08 +020066#define NFC_V1_V2_CONFIG1_SP_EN (1 << 2)
67#define NFC_V1_V2_CONFIG1_ECC_EN (1 << 3)
68#define NFC_V1_V2_CONFIG1_INT_MSK (1 << 4)
69#define NFC_V1_V2_CONFIG1_BIG (1 << 5)
70#define NFC_V1_V2_CONFIG1_RST (1 << 6)
71#define NFC_V1_V2_CONFIG1_CE (1 << 7)
Sascha Hauerb8db2f52010-08-09 15:04:19 +020072#define NFC_V2_CONFIG1_ONE_CYCLE (1 << 8)
73#define NFC_V2_CONFIG1_PPB(x) (((x) & 0x3) << 9)
74#define NFC_V2_CONFIG1_FP_INT (1 << 11)
Sascha Hauer34f6e152008-09-02 17:16:59 +020075
Sascha Hauer1bc99182010-08-06 15:53:08 +020076#define NFC_V1_V2_CONFIG2_INT (1 << 15)
Sascha Hauer34f6e152008-09-02 17:16:59 +020077
Sascha Hauer1bc99182010-08-06 15:53:08 +020078/*
79 * Operation modes for the NFC. Valid for v1, v2 and v3
80 * type controllers.
81 */
82#define NFC_CMD (1 << 0)
83#define NFC_ADDR (1 << 1)
84#define NFC_INPUT (1 << 2)
85#define NFC_OUTPUT (1 << 3)
86#define NFC_ID (1 << 4)
87#define NFC_STATUS (1 << 5)
Sascha Hauer34f6e152008-09-02 17:16:59 +020088
Sascha Hauer71ec5152010-08-06 15:53:11 +020089#define NFC_V3_FLASH_CMD (host->regs_axi + 0x00)
90#define NFC_V3_FLASH_ADDR0 (host->regs_axi + 0x04)
Sascha Hauer34f6e152008-09-02 17:16:59 +020091
Sascha Hauer71ec5152010-08-06 15:53:11 +020092#define NFC_V3_CONFIG1 (host->regs_axi + 0x34)
93#define NFC_V3_CONFIG1_SP_EN (1 << 0)
94#define NFC_V3_CONFIG1_RBA(x) (((x) & 0x7 ) << 4)
Sascha Hauer34f6e152008-09-02 17:16:59 +020095
Sascha Hauer71ec5152010-08-06 15:53:11 +020096#define NFC_V3_ECC_STATUS_RESULT (host->regs_axi + 0x38)
Sascha Hauer34f6e152008-09-02 17:16:59 +020097
Sascha Hauer71ec5152010-08-06 15:53:11 +020098#define NFC_V3_LAUNCH (host->regs_axi + 0x40)
Sascha Hauer34f6e152008-09-02 17:16:59 +020099
Sascha Hauer71ec5152010-08-06 15:53:11 +0200100#define NFC_V3_WRPROT (host->regs_ip + 0x0)
101#define NFC_V3_WRPROT_LOCK_TIGHT (1 << 0)
102#define NFC_V3_WRPROT_LOCK (1 << 1)
103#define NFC_V3_WRPROT_UNLOCK (1 << 2)
104#define NFC_V3_WRPROT_BLS_UNLOCK (2 << 6)
105
106#define NFC_V3_WRPROT_UNLOCK_BLK_ADD0 (host->regs_ip + 0x04)
107
108#define NFC_V3_CONFIG2 (host->regs_ip + 0x24)
109#define NFC_V3_CONFIG2_PS_512 (0 << 0)
110#define NFC_V3_CONFIG2_PS_2048 (1 << 0)
111#define NFC_V3_CONFIG2_PS_4096 (2 << 0)
112#define NFC_V3_CONFIG2_ONE_CYCLE (1 << 2)
113#define NFC_V3_CONFIG2_ECC_EN (1 << 3)
114#define NFC_V3_CONFIG2_2CMD_PHASES (1 << 4)
115#define NFC_V3_CONFIG2_NUM_ADDR_PHASE0 (1 << 5)
116#define NFC_V3_CONFIG2_ECC_MODE_8 (1 << 6)
117#define NFC_V3_CONFIG2_PPB(x) (((x) & 0x3) << 7)
118#define NFC_V3_CONFIG2_NUM_ADDR_PHASE1(x) (((x) & 0x3) << 12)
119#define NFC_V3_CONFIG2_INT_MSK (1 << 15)
120#define NFC_V3_CONFIG2_ST_CMD(x) (((x) & 0xff) << 24)
121#define NFC_V3_CONFIG2_SPAS(x) (((x) & 0xff) << 16)
122
123#define NFC_V3_CONFIG3 (host->regs_ip + 0x28)
124#define NFC_V3_CONFIG3_ADD_OP(x) (((x) & 0x3) << 0)
125#define NFC_V3_CONFIG3_FW8 (1 << 3)
126#define NFC_V3_CONFIG3_SBB(x) (((x) & 0x7) << 8)
127#define NFC_V3_CONFIG3_NUM_OF_DEVICES(x) (((x) & 0x7) << 12)
128#define NFC_V3_CONFIG3_RBB_MODE (1 << 15)
129#define NFC_V3_CONFIG3_NO_SDMA (1 << 20)
130
131#define NFC_V3_IPC (host->regs_ip + 0x2C)
132#define NFC_V3_IPC_CREQ (1 << 0)
133#define NFC_V3_IPC_INT (1 << 31)
134
135#define NFC_V3_DELAY_LINE (host->regs_ip + 0x34)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200136
137struct mxc_nand_host {
138 struct mtd_info mtd;
139 struct nand_chip nand;
140 struct mtd_partition *parts;
141 struct device *dev;
142
Sascha Hauerc6de7e12009-10-05 11:14:35 +0200143 void *spare0;
144 void *main_area0;
Sascha Hauerc6de7e12009-10-05 11:14:35 +0200145
146 void __iomem *base;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200147 void __iomem *regs;
Sascha Hauer71ec5152010-08-06 15:53:11 +0200148 void __iomem *regs_axi;
149 void __iomem *regs_ip;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200150 int status_request;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200151 struct clk *clk;
152 int clk_act;
153 int irq;
Sascha Hauer94f77e52010-08-06 15:53:09 +0200154 int eccsize;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200155
Sascha Hauer63f14742010-10-18 10:16:26 +0200156 struct completion op_completion;
Sascha Hauerf8f96082009-06-04 17:12:26 +0200157
158 uint8_t *data_buf;
159 unsigned int buf_start;
160 int spare_len;
Sascha Hauer5f973042010-08-06 15:53:06 +0200161
162 void (*preset)(struct mtd_info *);
163 void (*send_cmd)(struct mxc_nand_host *, uint16_t, int);
164 void (*send_addr)(struct mxc_nand_host *, uint16_t, int);
165 void (*send_page)(struct mtd_info *, unsigned int);
166 void (*send_read_id)(struct mxc_nand_host *);
167 uint16_t (*get_dev_status)(struct mxc_nand_host *);
Sascha Hauer7aaf28a2010-08-06 15:53:07 +0200168 int (*check_int)(struct mxc_nand_host *);
Sascha Hauer63f14742010-10-18 10:16:26 +0200169 void (*irq_control)(struct mxc_nand_host *, int);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200170};
171
Sascha Hauer34f6e152008-09-02 17:16:59 +0200172/* OOB placement block for use with hardware ecc generation */
Sascha Hauer94671142009-10-05 12:14:21 +0200173static struct nand_ecclayout nandv1_hw_eccoob_smallpage = {
Sascha Hauer34f6e152008-09-02 17:16:59 +0200174 .eccbytes = 5,
175 .eccpos = {6, 7, 8, 9, 10},
Sascha Hauer8c1fd892009-10-21 10:22:01 +0200176 .oobfree = {{0, 5}, {12, 4}, }
Sascha Hauer34f6e152008-09-02 17:16:59 +0200177};
178
Sascha Hauer94671142009-10-05 12:14:21 +0200179static struct nand_ecclayout nandv1_hw_eccoob_largepage = {
Vladimir Barinovbd3fd622009-05-25 13:06:17 +0400180 .eccbytes = 20,
181 .eccpos = {6, 7, 8, 9, 10, 22, 23, 24, 25, 26,
182 38, 39, 40, 41, 42, 54, 55, 56, 57, 58},
183 .oobfree = {{2, 4}, {11, 10}, {27, 10}, {43, 10}, {59, 5}, }
Sascha Hauer34f6e152008-09-02 17:16:59 +0200184};
185
Sascha Hauer94671142009-10-05 12:14:21 +0200186/* OOB description for 512 byte pages with 16 byte OOB */
187static struct nand_ecclayout nandv2_hw_eccoob_smallpage = {
188 .eccbytes = 1 * 9,
189 .eccpos = {
190 7, 8, 9, 10, 11, 12, 13, 14, 15
191 },
192 .oobfree = {
193 {.offset = 0, .length = 5}
194 }
195};
196
197/* OOB description for 2048 byte pages with 64 byte OOB */
198static struct nand_ecclayout nandv2_hw_eccoob_largepage = {
199 .eccbytes = 4 * 9,
200 .eccpos = {
201 7, 8, 9, 10, 11, 12, 13, 14, 15,
202 23, 24, 25, 26, 27, 28, 29, 30, 31,
203 39, 40, 41, 42, 43, 44, 45, 46, 47,
204 55, 56, 57, 58, 59, 60, 61, 62, 63
205 },
206 .oobfree = {
207 {.offset = 2, .length = 4},
208 {.offset = 16, .length = 7},
209 {.offset = 32, .length = 7},
210 {.offset = 48, .length = 7}
211 }
212};
213
Baruch Siach2c1c5f12011-03-09 16:12:20 +0200214/* OOB description for 4096 byte pages with 128 byte OOB */
215static struct nand_ecclayout nandv2_hw_eccoob_4k = {
216 .eccbytes = 8 * 9,
217 .eccpos = {
218 7, 8, 9, 10, 11, 12, 13, 14, 15,
219 23, 24, 25, 26, 27, 28, 29, 30, 31,
220 39, 40, 41, 42, 43, 44, 45, 46, 47,
221 55, 56, 57, 58, 59, 60, 61, 62, 63,
222 71, 72, 73, 74, 75, 76, 77, 78, 79,
223 87, 88, 89, 90, 91, 92, 93, 94, 95,
224 103, 104, 105, 106, 107, 108, 109, 110, 111,
225 119, 120, 121, 122, 123, 124, 125, 126, 127,
226 },
227 .oobfree = {
228 {.offset = 2, .length = 4},
229 {.offset = 16, .length = 7},
230 {.offset = 32, .length = 7},
231 {.offset = 48, .length = 7},
232 {.offset = 64, .length = 7},
233 {.offset = 80, .length = 7},
234 {.offset = 96, .length = 7},
235 {.offset = 112, .length = 7},
236 }
237};
238
Sascha Hauer34f6e152008-09-02 17:16:59 +0200239#ifdef CONFIG_MTD_PARTITIONS
240static const char *part_probes[] = { "RedBoot", "cmdlinepart", NULL };
241#endif
242
243static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
244{
245 struct mxc_nand_host *host = dev_id;
246
Sascha Hauer63f14742010-10-18 10:16:26 +0200247 if (!host->check_int(host))
248 return IRQ_NONE;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200249
Sascha Hauer63f14742010-10-18 10:16:26 +0200250 host->irq_control(host, 0);
251
252 complete(&host->op_completion);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200253
254 return IRQ_HANDLED;
255}
256
Sascha Hauer71ec5152010-08-06 15:53:11 +0200257static int check_int_v3(struct mxc_nand_host *host)
258{
259 uint32_t tmp;
260
261 tmp = readl(NFC_V3_IPC);
262 if (!(tmp & NFC_V3_IPC_INT))
263 return 0;
264
265 tmp &= ~NFC_V3_IPC_INT;
266 writel(tmp, NFC_V3_IPC);
267
268 return 1;
269}
270
Sascha Hauer7aaf28a2010-08-06 15:53:07 +0200271static int check_int_v1_v2(struct mxc_nand_host *host)
272{
273 uint32_t tmp;
274
Sascha Hauer1bc99182010-08-06 15:53:08 +0200275 tmp = readw(NFC_V1_V2_CONFIG2);
276 if (!(tmp & NFC_V1_V2_CONFIG2_INT))
Sascha Hauer7aaf28a2010-08-06 15:53:07 +0200277 return 0;
278
Sascha Hauer63f14742010-10-18 10:16:26 +0200279 if (!cpu_is_mx21())
280 writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2);
Sascha Hauer7aaf28a2010-08-06 15:53:07 +0200281
282 return 1;
283}
284
Sascha Hauer63f14742010-10-18 10:16:26 +0200285/*
286 * It has been observed that the i.MX21 cannot read the CONFIG2:INT bit
287 * if interrupts are masked (CONFIG1:INT_MSK is set). To handle this, the
288 * driver can enable/disable the irq line rather than simply masking the
289 * interrupts.
290 */
291static void irq_control_mx21(struct mxc_nand_host *host, int activate)
292{
293 if (activate)
294 enable_irq(host->irq);
295 else
296 disable_irq_nosync(host->irq);
297}
298
299static void irq_control_v1_v2(struct mxc_nand_host *host, int activate)
300{
301 uint16_t tmp;
302
303 tmp = readw(NFC_V1_V2_CONFIG1);
304
305 if (activate)
306 tmp &= ~NFC_V1_V2_CONFIG1_INT_MSK;
307 else
308 tmp |= NFC_V1_V2_CONFIG1_INT_MSK;
309
310 writew(tmp, NFC_V1_V2_CONFIG1);
311}
312
313static void irq_control_v3(struct mxc_nand_host *host, int activate)
314{
315 uint32_t tmp;
316
317 tmp = readl(NFC_V3_CONFIG2);
318
319 if (activate)
320 tmp &= ~NFC_V3_CONFIG2_INT_MSK;
321 else
322 tmp |= NFC_V3_CONFIG2_INT_MSK;
323
324 writel(tmp, NFC_V3_CONFIG2);
325}
326
Sascha Hauer34f6e152008-09-02 17:16:59 +0200327/* This function polls the NANDFC to wait for the basic operation to
328 * complete by checking the INT bit of config2 register.
329 */
Sascha Hauerc110eaf2009-10-21 16:01:02 +0200330static void wait_op_done(struct mxc_nand_host *host, int useirq)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200331{
Ivo Claryssea47bfd22010-04-08 16:16:51 +0200332 int max_retries = 8000;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200333
334 if (useirq) {
Sascha Hauer7aaf28a2010-08-06 15:53:07 +0200335 if (!host->check_int(host)) {
Sascha Hauer63f14742010-10-18 10:16:26 +0200336 INIT_COMPLETION(host->op_completion);
337 host->irq_control(host, 1);
338 wait_for_completion(&host->op_completion);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200339 }
340 } else {
341 while (max_retries-- > 0) {
Sascha Hauer7aaf28a2010-08-06 15:53:07 +0200342 if (host->check_int(host))
Sascha Hauer34f6e152008-09-02 17:16:59 +0200343 break;
Sascha Hauer7aaf28a2010-08-06 15:53:07 +0200344
Sascha Hauer34f6e152008-09-02 17:16:59 +0200345 udelay(1);
346 }
Roel Kluin43950a62009-06-04 16:24:59 +0200347 if (max_retries < 0)
Sascha Hauer62465492009-06-04 15:57:20 +0200348 DEBUG(MTD_DEBUG_LEVEL0, "%s: INT not set\n",
349 __func__);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200350 }
351}
352
Sascha Hauer71ec5152010-08-06 15:53:11 +0200353static void send_cmd_v3(struct mxc_nand_host *host, uint16_t cmd, int useirq)
354{
355 /* fill command */
356 writel(cmd, NFC_V3_FLASH_CMD);
357
358 /* send out command */
359 writel(NFC_CMD, NFC_V3_LAUNCH);
360
361 /* Wait for operation to complete */
362 wait_op_done(host, useirq);
363}
364
Sascha Hauer34f6e152008-09-02 17:16:59 +0200365/* This function issues the specified command to the NAND device and
366 * waits for completion. */
Sascha Hauer5f973042010-08-06 15:53:06 +0200367static void send_cmd_v1_v2(struct mxc_nand_host *host, uint16_t cmd, int useirq)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200368{
369 DEBUG(MTD_DEBUG_LEVEL3, "send_cmd(host, 0x%x, %d)\n", cmd, useirq);
370
Sascha Hauer1bc99182010-08-06 15:53:08 +0200371 writew(cmd, NFC_V1_V2_FLASH_CMD);
372 writew(NFC_CMD, NFC_V1_V2_CONFIG2);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200373
Ivo Claryssea47bfd22010-04-08 16:16:51 +0200374 if (cpu_is_mx21() && (cmd == NAND_CMD_RESET)) {
375 int max_retries = 100;
376 /* Reset completion is indicated by NFC_CONFIG2 */
377 /* being set to 0 */
378 while (max_retries-- > 0) {
Sascha Hauer1bc99182010-08-06 15:53:08 +0200379 if (readw(NFC_V1_V2_CONFIG2) == 0) {
Ivo Claryssea47bfd22010-04-08 16:16:51 +0200380 break;
381 }
382 udelay(1);
383 }
384 if (max_retries < 0)
385 DEBUG(MTD_DEBUG_LEVEL0, "%s: RESET failed\n",
386 __func__);
387 } else {
388 /* Wait for operation to complete */
389 wait_op_done(host, useirq);
390 }
Sascha Hauer34f6e152008-09-02 17:16:59 +0200391}
392
Sascha Hauer71ec5152010-08-06 15:53:11 +0200393static void send_addr_v3(struct mxc_nand_host *host, uint16_t addr, int islast)
394{
395 /* fill address */
396 writel(addr, NFC_V3_FLASH_ADDR0);
397
398 /* send out address */
399 writel(NFC_ADDR, NFC_V3_LAUNCH);
400
401 wait_op_done(host, 0);
402}
403
Sascha Hauer34f6e152008-09-02 17:16:59 +0200404/* This function sends an address (or partial address) to the
405 * NAND device. The address is used to select the source/destination for
406 * a NAND command. */
Sascha Hauer5f973042010-08-06 15:53:06 +0200407static void send_addr_v1_v2(struct mxc_nand_host *host, uint16_t addr, int islast)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200408{
409 DEBUG(MTD_DEBUG_LEVEL3, "send_addr(host, 0x%x %d)\n", addr, islast);
410
Sascha Hauer1bc99182010-08-06 15:53:08 +0200411 writew(addr, NFC_V1_V2_FLASH_ADDR);
412 writew(NFC_ADDR, NFC_V1_V2_CONFIG2);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200413
414 /* Wait for operation to complete */
Sascha Hauerc110eaf2009-10-21 16:01:02 +0200415 wait_op_done(host, islast);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200416}
417
Sascha Hauer71ec5152010-08-06 15:53:11 +0200418static void send_page_v3(struct mtd_info *mtd, unsigned int ops)
419{
420 struct nand_chip *nand_chip = mtd->priv;
421 struct mxc_nand_host *host = nand_chip->priv;
422 uint32_t tmp;
423
424 tmp = readl(NFC_V3_CONFIG1);
425 tmp &= ~(7 << 4);
426 writel(tmp, NFC_V3_CONFIG1);
427
428 /* transfer data from NFC ram to nand */
429 writel(ops, NFC_V3_LAUNCH);
430
431 wait_op_done(host, false);
432}
433
Sascha Hauer5f973042010-08-06 15:53:06 +0200434static void send_page_v1_v2(struct mtd_info *mtd, unsigned int ops)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200435{
Sascha Hauer2d69c7f2009-10-05 11:24:02 +0200436 struct nand_chip *nand_chip = mtd->priv;
437 struct mxc_nand_host *host = nand_chip->priv;
Sascha Hauerc5d23f12009-06-04 17:25:53 +0200438 int bufs, i;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200439
Sascha Hauer94671142009-10-05 12:14:21 +0200440 if (nfc_is_v1() && mtd->writesize > 512)
Sascha Hauerc5d23f12009-06-04 17:25:53 +0200441 bufs = 4;
442 else
443 bufs = 1;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200444
Sascha Hauerc5d23f12009-06-04 17:25:53 +0200445 for (i = 0; i < bufs; i++) {
446
447 /* NANDFC buffer 0 is used for page read/write */
Sascha Hauer1bc99182010-08-06 15:53:08 +0200448 writew(i, NFC_V1_V2_BUF_ADDR);
Sascha Hauerc5d23f12009-06-04 17:25:53 +0200449
Sascha Hauer1bc99182010-08-06 15:53:08 +0200450 writew(ops, NFC_V1_V2_CONFIG2);
Sascha Hauerc5d23f12009-06-04 17:25:53 +0200451
452 /* Wait for operation to complete */
Sascha Hauerc110eaf2009-10-21 16:01:02 +0200453 wait_op_done(host, true);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200454 }
Sascha Hauer34f6e152008-09-02 17:16:59 +0200455}
456
Sascha Hauer71ec5152010-08-06 15:53:11 +0200457static void send_read_id_v3(struct mxc_nand_host *host)
458{
459 /* Read ID into main buffer */
460 writel(NFC_ID, NFC_V3_LAUNCH);
461
462 wait_op_done(host, true);
463
464 memcpy(host->data_buf, host->main_area0, 16);
465}
466
Sascha Hauer34f6e152008-09-02 17:16:59 +0200467/* Request the NANDFC to perform a read of the NAND device ID. */
Sascha Hauer5f973042010-08-06 15:53:06 +0200468static void send_read_id_v1_v2(struct mxc_nand_host *host)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200469{
470 struct nand_chip *this = &host->nand;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200471
472 /* NANDFC buffer 0 is used for device ID output */
Sascha Hauer1bc99182010-08-06 15:53:08 +0200473 writew(0x0, NFC_V1_V2_BUF_ADDR);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200474
Sascha Hauer1bc99182010-08-06 15:53:08 +0200475 writew(NFC_ID, NFC_V1_V2_CONFIG2);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200476
477 /* Wait for operation to complete */
Sascha Hauerc110eaf2009-10-21 16:01:02 +0200478 wait_op_done(host, true);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200479
Sascha Hauerc6de7e12009-10-05 11:14:35 +0200480 memcpy(host->data_buf, host->main_area0, 16);
John Ognessf7b66e52010-06-18 18:59:47 +0200481
482 if (this->options & NAND_BUSWIDTH_16) {
483 /* compress the ID info */
484 host->data_buf[1] = host->data_buf[2];
485 host->data_buf[2] = host->data_buf[4];
486 host->data_buf[3] = host->data_buf[6];
487 host->data_buf[4] = host->data_buf[8];
488 host->data_buf[5] = host->data_buf[10];
489 }
Sascha Hauer34f6e152008-09-02 17:16:59 +0200490}
491
Sascha Hauer71ec5152010-08-06 15:53:11 +0200492static uint16_t get_dev_status_v3(struct mxc_nand_host *host)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200493{
Sascha Hauer71ec5152010-08-06 15:53:11 +0200494 writew(NFC_STATUS, NFC_V3_LAUNCH);
Sascha Hauerc110eaf2009-10-21 16:01:02 +0200495 wait_op_done(host, true);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200496
Sascha Hauer71ec5152010-08-06 15:53:11 +0200497 return readl(NFC_V3_CONFIG1) >> 16;
498}
499
Sascha Hauer34f6e152008-09-02 17:16:59 +0200500/* This function requests the NANDFC to perform a read of the
501 * NAND device status and returns the current status. */
Sascha Hauer5f973042010-08-06 15:53:06 +0200502static uint16_t get_dev_status_v1_v2(struct mxc_nand_host *host)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200503{
Sascha Hauerc29c6072010-08-06 15:53:05 +0200504 void __iomem *main_buf = host->main_area0;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200505 uint32_t store;
506 uint16_t ret;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200507
Sascha Hauerc29c6072010-08-06 15:53:05 +0200508 writew(0x0, NFC_V1_V2_BUF_ADDR);
509
510 /*
511 * The device status is stored in main_area0. To
512 * prevent corruption of the buffer save the value
513 * and restore it afterwards.
514 */
Sascha Hauer34f6e152008-09-02 17:16:59 +0200515 store = readl(main_buf);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200516
Sascha Hauer1bc99182010-08-06 15:53:08 +0200517 writew(NFC_STATUS, NFC_V1_V2_CONFIG2);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200518 wait_op_done(host, true);
519
Sascha Hauer34f6e152008-09-02 17:16:59 +0200520 ret = readw(main_buf);
Sascha Hauerc29c6072010-08-06 15:53:05 +0200521
Sascha Hauer34f6e152008-09-02 17:16:59 +0200522 writel(store, main_buf);
523
524 return ret;
525}
526
527/* This functions is used by upper layer to checks if device is ready */
528static int mxc_nand_dev_ready(struct mtd_info *mtd)
529{
530 /*
531 * NFC handles R/B internally. Therefore, this function
532 * always returns status as ready.
533 */
534 return 1;
535}
536
537static void mxc_nand_enable_hwecc(struct mtd_info *mtd, int mode)
538{
539 /*
540 * If HW ECC is enabled, we turn it on during init. There is
541 * no need to enable again here.
542 */
543}
544
Sascha Hauer94f77e52010-08-06 15:53:09 +0200545static int mxc_nand_correct_data_v1(struct mtd_info *mtd, u_char *dat,
Sascha Hauer34f6e152008-09-02 17:16:59 +0200546 u_char *read_ecc, u_char *calc_ecc)
547{
548 struct nand_chip *nand_chip = mtd->priv;
549 struct mxc_nand_host *host = nand_chip->priv;
550
551 /*
552 * 1-Bit errors are automatically corrected in HW. No need for
553 * additional correction. 2-Bit errors cannot be corrected by
554 * HW ECC, so we need to return failure
555 */
Sascha Hauer1bc99182010-08-06 15:53:08 +0200556 uint16_t ecc_status = readw(NFC_V1_V2_ECC_STATUS_RESULT);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200557
558 if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) {
559 DEBUG(MTD_DEBUG_LEVEL0,
560 "MXC_NAND: HWECC uncorrectable 2-bit ECC error\n");
561 return -1;
562 }
563
564 return 0;
565}
566
Sascha Hauer94f77e52010-08-06 15:53:09 +0200567static int mxc_nand_correct_data_v2_v3(struct mtd_info *mtd, u_char *dat,
568 u_char *read_ecc, u_char *calc_ecc)
569{
570 struct nand_chip *nand_chip = mtd->priv;
571 struct mxc_nand_host *host = nand_chip->priv;
572 u32 ecc_stat, err;
573 int no_subpages = 1;
574 int ret = 0;
575 u8 ecc_bit_mask, err_limit;
576
577 ecc_bit_mask = (host->eccsize == 4) ? 0x7 : 0xf;
578 err_limit = (host->eccsize == 4) ? 0x4 : 0x8;
579
580 no_subpages = mtd->writesize >> 9;
581
Sascha Hauer71ec5152010-08-06 15:53:11 +0200582 if (nfc_is_v21())
583 ecc_stat = readl(NFC_V1_V2_ECC_STATUS_RESULT);
584 else
585 ecc_stat = readl(NFC_V3_ECC_STATUS_RESULT);
Sascha Hauer94f77e52010-08-06 15:53:09 +0200586
587 do {
588 err = ecc_stat & ecc_bit_mask;
589 if (err > err_limit) {
590 printk(KERN_WARNING "UnCorrectable RS-ECC Error\n");
591 return -1;
592 } else {
593 ret += err;
594 }
595 ecc_stat >>= 4;
596 } while (--no_subpages);
597
598 mtd->ecc_stats.corrected += ret;
599 pr_debug("%d Symbol Correctable RS-ECC Error\n", ret);
600
601 return ret;
602}
603
Sascha Hauer34f6e152008-09-02 17:16:59 +0200604static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
605 u_char *ecc_code)
606{
607 return 0;
608}
609
610static u_char mxc_nand_read_byte(struct mtd_info *mtd)
611{
612 struct nand_chip *nand_chip = mtd->priv;
613 struct mxc_nand_host *host = nand_chip->priv;
Sascha Hauerf8f96082009-06-04 17:12:26 +0200614 uint8_t ret;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200615
616 /* Check for status request */
617 if (host->status_request)
Sascha Hauer5f973042010-08-06 15:53:06 +0200618 return host->get_dev_status(host) & 0xFF;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200619
Sascha Hauerf8f96082009-06-04 17:12:26 +0200620 ret = *(uint8_t *)(host->data_buf + host->buf_start);
621 host->buf_start++;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200622
623 return ret;
624}
625
626static uint16_t mxc_nand_read_word(struct mtd_info *mtd)
627{
628 struct nand_chip *nand_chip = mtd->priv;
629 struct mxc_nand_host *host = nand_chip->priv;
Sascha Hauerf8f96082009-06-04 17:12:26 +0200630 uint16_t ret;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200631
Sascha Hauerf8f96082009-06-04 17:12:26 +0200632 ret = *(uint16_t *)(host->data_buf + host->buf_start);
633 host->buf_start += 2;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200634
635 return ret;
636}
637
638/* Write data of length len to buffer buf. The data to be
639 * written on NAND Flash is first copied to RAMbuffer. After the Data Input
640 * Operation by the NFC, the data is written to NAND Flash */
641static void mxc_nand_write_buf(struct mtd_info *mtd,
642 const u_char *buf, int len)
643{
644 struct nand_chip *nand_chip = mtd->priv;
645 struct mxc_nand_host *host = nand_chip->priv;
Sascha Hauerf8f96082009-06-04 17:12:26 +0200646 u16 col = host->buf_start;
647 int n = mtd->oobsize + mtd->writesize - col;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200648
Sascha Hauerf8f96082009-06-04 17:12:26 +0200649 n = min(n, len);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200650
Sascha Hauerf8f96082009-06-04 17:12:26 +0200651 memcpy(host->data_buf + col, buf, n);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200652
Sascha Hauerf8f96082009-06-04 17:12:26 +0200653 host->buf_start += n;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200654}
655
656/* Read the data buffer from the NAND Flash. To read the data from NAND
657 * Flash first the data output cycle is initiated by the NFC, which copies
658 * the data to RAMbuffer. This data of length len is then copied to buffer buf.
659 */
660static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
661{
662 struct nand_chip *nand_chip = mtd->priv;
663 struct mxc_nand_host *host = nand_chip->priv;
Sascha Hauerf8f96082009-06-04 17:12:26 +0200664 u16 col = host->buf_start;
665 int n = mtd->oobsize + mtd->writesize - col;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200666
Sascha Hauerf8f96082009-06-04 17:12:26 +0200667 n = min(n, len);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200668
Baruch Siach5d9d9932011-03-02 16:47:55 +0200669 memcpy(buf, host->data_buf + col, n);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200670
Baruch Siach5d9d9932011-03-02 16:47:55 +0200671 host->buf_start += n;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200672}
673
674/* Used by the upper layer to verify the data in NAND Flash
675 * with the data in the buf. */
676static int mxc_nand_verify_buf(struct mtd_info *mtd,
677 const u_char *buf, int len)
678{
679 return -EFAULT;
680}
681
682/* This function is used by upper layer for select and
683 * deselect of the NAND chip */
684static void mxc_nand_select_chip(struct mtd_info *mtd, int chip)
685{
686 struct nand_chip *nand_chip = mtd->priv;
687 struct mxc_nand_host *host = nand_chip->priv;
688
Sascha Hauer34f6e152008-09-02 17:16:59 +0200689 switch (chip) {
690 case -1:
691 /* Disable the NFC clock */
692 if (host->clk_act) {
693 clk_disable(host->clk);
694 host->clk_act = 0;
695 }
696 break;
697 case 0:
698 /* Enable the NFC clock */
699 if (!host->clk_act) {
700 clk_enable(host->clk);
701 host->clk_act = 1;
702 }
703 break;
704
705 default:
706 break;
707 }
708}
709
Sascha Hauerf8f96082009-06-04 17:12:26 +0200710/*
711 * Function to transfer data to/from spare area.
712 */
713static void copy_spare(struct mtd_info *mtd, bool bfrom)
714{
715 struct nand_chip *this = mtd->priv;
716 struct mxc_nand_host *host = this->priv;
717 u16 i, j;
718 u16 n = mtd->writesize >> 9;
719 u8 *d = host->data_buf + mtd->writesize;
Sascha Hauerc6de7e12009-10-05 11:14:35 +0200720 u8 *s = host->spare0;
Sascha Hauerf8f96082009-06-04 17:12:26 +0200721 u16 t = host->spare_len;
722
723 j = (mtd->oobsize / n >> 1) << 1;
724
725 if (bfrom) {
726 for (i = 0; i < n - 1; i++)
727 memcpy(d + i * j, s + i * t, j);
728
729 /* the last section */
730 memcpy(d + i * j, s + i * t, mtd->oobsize - i * j);
731 } else {
732 for (i = 0; i < n - 1; i++)
733 memcpy(&s[i * t], &d[i * j], j);
734
735 /* the last section */
736 memcpy(&s[i * t], &d[i * j], mtd->oobsize - i * j);
737 }
738}
739
Sascha Hauera3e65b62009-06-02 11:47:59 +0200740static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200741{
742 struct nand_chip *nand_chip = mtd->priv;
743 struct mxc_nand_host *host = nand_chip->priv;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200744
745 /* Write out column address, if necessary */
746 if (column != -1) {
747 /*
748 * MXC NANDFC can only perform full page+spare or
749 * spare-only read/write. When the upper layers
750 * layers perform a read/write buf operation,
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800751 * we will used the saved column address to index into
Sascha Hauer34f6e152008-09-02 17:16:59 +0200752 * the full page.
753 */
Sascha Hauer5f973042010-08-06 15:53:06 +0200754 host->send_addr(host, 0, page_addr == -1);
Sascha Hauer2d69c7f2009-10-05 11:24:02 +0200755 if (mtd->writesize > 512)
Sascha Hauer34f6e152008-09-02 17:16:59 +0200756 /* another col addr cycle for 2k page */
Sascha Hauer5f973042010-08-06 15:53:06 +0200757 host->send_addr(host, 0, false);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200758 }
759
760 /* Write out page address, if necessary */
761 if (page_addr != -1) {
762 /* paddr_0 - p_addr_7 */
Sascha Hauer5f973042010-08-06 15:53:06 +0200763 host->send_addr(host, (page_addr & 0xff), false);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200764
Sascha Hauer2d69c7f2009-10-05 11:24:02 +0200765 if (mtd->writesize > 512) {
Vladimir Barinovbd3fd622009-05-25 13:06:17 +0400766 if (mtd->size >= 0x10000000) {
767 /* paddr_8 - paddr_15 */
Sascha Hauer5f973042010-08-06 15:53:06 +0200768 host->send_addr(host, (page_addr >> 8) & 0xff, false);
769 host->send_addr(host, (page_addr >> 16) & 0xff, true);
Vladimir Barinovbd3fd622009-05-25 13:06:17 +0400770 } else
771 /* paddr_8 - paddr_15 */
Sascha Hauer5f973042010-08-06 15:53:06 +0200772 host->send_addr(host, (page_addr >> 8) & 0xff, true);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200773 } else {
774 /* One more address cycle for higher density devices */
775 if (mtd->size >= 0x4000000) {
776 /* paddr_8 - paddr_15 */
Sascha Hauer5f973042010-08-06 15:53:06 +0200777 host->send_addr(host, (page_addr >> 8) & 0xff, false);
778 host->send_addr(host, (page_addr >> 16) & 0xff, true);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200779 } else
780 /* paddr_8 - paddr_15 */
Sascha Hauer5f973042010-08-06 15:53:06 +0200781 host->send_addr(host, (page_addr >> 8) & 0xff, true);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200782 }
783 }
Sascha Hauera3e65b62009-06-02 11:47:59 +0200784}
Sascha Hauer34f6e152008-09-02 17:16:59 +0200785
Sascha Hauer6e85dfd2010-08-06 15:53:10 +0200786/*
787 * v2 and v3 type controllers can do 4bit or 8bit ecc depending
788 * on how much oob the nand chip has. For 8bit ecc we need at least
789 * 26 bytes of oob data per 512 byte block.
790 */
791static int get_eccsize(struct mtd_info *mtd)
792{
793 int oobbytes_per_512 = 0;
794
795 oobbytes_per_512 = mtd->oobsize * 512 / mtd->writesize;
796
797 if (oobbytes_per_512 < 26)
798 return 4;
799 else
800 return 8;
801}
802
Sascha Hauer5f973042010-08-06 15:53:06 +0200803static void preset_v1_v2(struct mtd_info *mtd)
Ivo Claryssed4840182010-04-08 16:14:44 +0200804{
805 struct nand_chip *nand_chip = mtd->priv;
806 struct mxc_nand_host *host = nand_chip->priv;
Sascha Hauerb8db2f52010-08-09 15:04:19 +0200807 uint16_t config1 = 0;
Ivo Claryssed4840182010-04-08 16:14:44 +0200808
Sascha Hauerb8db2f52010-08-09 15:04:19 +0200809 if (nand_chip->ecc.mode == NAND_ECC_HW)
810 config1 |= NFC_V1_V2_CONFIG1_ECC_EN;
811
812 if (nfc_is_v21())
813 config1 |= NFC_V2_CONFIG1_FP_INT;
814
815 if (!cpu_is_mx21())
816 config1 |= NFC_V1_V2_CONFIG1_INT_MSK;
Sascha Hauer6e85dfd2010-08-06 15:53:10 +0200817
818 if (nfc_is_v21() && mtd->writesize) {
Sascha Hauerb8db2f52010-08-09 15:04:19 +0200819 uint16_t pages_per_block = mtd->erasesize / mtd->writesize;
820
Sascha Hauer6e85dfd2010-08-06 15:53:10 +0200821 host->eccsize = get_eccsize(mtd);
822 if (host->eccsize == 4)
Sascha Hauerb8db2f52010-08-09 15:04:19 +0200823 config1 |= NFC_V2_CONFIG1_ECC_MODE_4;
824
825 config1 |= NFC_V2_CONFIG1_PPB(ffs(pages_per_block) - 6);
Sascha Hauer6e85dfd2010-08-06 15:53:10 +0200826 } else {
827 host->eccsize = 1;
828 }
829
Sascha Hauerb8db2f52010-08-09 15:04:19 +0200830 writew(config1, NFC_V1_V2_CONFIG1);
Ivo Claryssed4840182010-04-08 16:14:44 +0200831 /* preset operation */
832
833 /* Unlock the internal RAM Buffer */
Sascha Hauer1bc99182010-08-06 15:53:08 +0200834 writew(0x2, NFC_V1_V2_CONFIG);
Ivo Claryssed4840182010-04-08 16:14:44 +0200835
836 /* Blocks to be unlocked */
837 if (nfc_is_v21()) {
Sascha Hauer1bc99182010-08-06 15:53:08 +0200838 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR);
839 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR);
Ivo Claryssed4840182010-04-08 16:14:44 +0200840 } else if (nfc_is_v1()) {
Sascha Hauer1bc99182010-08-06 15:53:08 +0200841 writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR);
842 writew(0x4000, NFC_V1_UNLOCKEND_BLKADDR);
Ivo Claryssed4840182010-04-08 16:14:44 +0200843 } else
844 BUG();
845
846 /* Unlock Block Command for given address range */
Sascha Hauer1bc99182010-08-06 15:53:08 +0200847 writew(0x4, NFC_V1_V2_WRPROT);
Ivo Claryssed4840182010-04-08 16:14:44 +0200848}
849
Sascha Hauer71ec5152010-08-06 15:53:11 +0200850static void preset_v3(struct mtd_info *mtd)
851{
852 struct nand_chip *chip = mtd->priv;
853 struct mxc_nand_host *host = chip->priv;
854 uint32_t config2, config3;
855 int i, addr_phases;
856
857 writel(NFC_V3_CONFIG1_RBA(0), NFC_V3_CONFIG1);
858 writel(NFC_V3_IPC_CREQ, NFC_V3_IPC);
859
860 /* Unlock the internal RAM Buffer */
861 writel(NFC_V3_WRPROT_BLS_UNLOCK | NFC_V3_WRPROT_UNLOCK,
862 NFC_V3_WRPROT);
863
864 /* Blocks to be unlocked */
865 for (i = 0; i < NAND_MAX_CHIPS; i++)
866 writel(0x0 | (0xffff << 16),
867 NFC_V3_WRPROT_UNLOCK_BLK_ADD0 + (i << 2));
868
869 writel(0, NFC_V3_IPC);
870
871 config2 = NFC_V3_CONFIG2_ONE_CYCLE |
872 NFC_V3_CONFIG2_2CMD_PHASES |
873 NFC_V3_CONFIG2_SPAS(mtd->oobsize >> 1) |
874 NFC_V3_CONFIG2_ST_CMD(0x70) |
Sascha Hauer63f14742010-10-18 10:16:26 +0200875 NFC_V3_CONFIG2_INT_MSK |
Sascha Hauer71ec5152010-08-06 15:53:11 +0200876 NFC_V3_CONFIG2_NUM_ADDR_PHASE0;
877
878 if (chip->ecc.mode == NAND_ECC_HW)
879 config2 |= NFC_V3_CONFIG2_ECC_EN;
880
881 addr_phases = fls(chip->pagemask) >> 3;
882
883 if (mtd->writesize == 2048) {
884 config2 |= NFC_V3_CONFIG2_PS_2048;
885 config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases);
886 } else if (mtd->writesize == 4096) {
887 config2 |= NFC_V3_CONFIG2_PS_4096;
888 config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases);
889 } else {
890 config2 |= NFC_V3_CONFIG2_PS_512;
891 config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases - 1);
892 }
893
894 if (mtd->writesize) {
895 config2 |= NFC_V3_CONFIG2_PPB(ffs(mtd->erasesize / mtd->writesize) - 6);
896 host->eccsize = get_eccsize(mtd);
897 if (host->eccsize == 8)
898 config2 |= NFC_V3_CONFIG2_ECC_MODE_8;
899 }
900
901 writel(config2, NFC_V3_CONFIG2);
902
903 config3 = NFC_V3_CONFIG3_NUM_OF_DEVICES(0) |
904 NFC_V3_CONFIG3_NO_SDMA |
905 NFC_V3_CONFIG3_RBB_MODE |
906 NFC_V3_CONFIG3_SBB(6) | /* Reset default */
907 NFC_V3_CONFIG3_ADD_OP(0);
908
909 if (!(chip->options & NAND_BUSWIDTH_16))
910 config3 |= NFC_V3_CONFIG3_FW8;
911
912 writel(config3, NFC_V3_CONFIG3);
913
914 writel(0, NFC_V3_DELAY_LINE);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200915}
916
Sascha Hauer34f6e152008-09-02 17:16:59 +0200917/* Used by the upper layer to write command to NAND Flash for
918 * different operations to be carried out on NAND Flash */
919static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
920 int column, int page_addr)
921{
922 struct nand_chip *nand_chip = mtd->priv;
923 struct mxc_nand_host *host = nand_chip->priv;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200924
925 DEBUG(MTD_DEBUG_LEVEL3,
926 "mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n",
927 command, column, page_addr);
928
929 /* Reset command state information */
930 host->status_request = false;
931
932 /* Command pre-processing step */
Sascha Hauer34f6e152008-09-02 17:16:59 +0200933 switch (command) {
Ivo Claryssed4840182010-04-08 16:14:44 +0200934 case NAND_CMD_RESET:
Sascha Hauer5f973042010-08-06 15:53:06 +0200935 host->preset(mtd);
936 host->send_cmd(host, command, false);
Ivo Claryssed4840182010-04-08 16:14:44 +0200937 break;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200938
Sascha Hauer34f6e152008-09-02 17:16:59 +0200939 case NAND_CMD_STATUS:
Sascha Hauerf8f96082009-06-04 17:12:26 +0200940 host->buf_start = 0;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200941 host->status_request = true;
Sascha Hauer89121a62009-06-04 17:18:01 +0200942
Sascha Hauer5f973042010-08-06 15:53:06 +0200943 host->send_cmd(host, command, true);
Sascha Hauer89121a62009-06-04 17:18:01 +0200944 mxc_do_addr_cycle(mtd, column, page_addr);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200945 break;
946
Sascha Hauer34f6e152008-09-02 17:16:59 +0200947 case NAND_CMD_READ0:
Sascha Hauer34f6e152008-09-02 17:16:59 +0200948 case NAND_CMD_READOOB:
Sascha Hauer89121a62009-06-04 17:18:01 +0200949 if (command == NAND_CMD_READ0)
950 host->buf_start = column;
951 else
952 host->buf_start = column + mtd->writesize;
Sascha Hauerf8f96082009-06-04 17:12:26 +0200953
Sascha Hauer5ea32022010-04-27 15:24:01 +0200954 command = NAND_CMD_READ0; /* only READ0 is valid */
Sascha Hauer89121a62009-06-04 17:18:01 +0200955
Sascha Hauer5f973042010-08-06 15:53:06 +0200956 host->send_cmd(host, command, false);
Sascha Hauer89121a62009-06-04 17:18:01 +0200957 mxc_do_addr_cycle(mtd, column, page_addr);
958
Sascha Hauer2d69c7f2009-10-05 11:24:02 +0200959 if (mtd->writesize > 512)
Sascha Hauer5f973042010-08-06 15:53:06 +0200960 host->send_cmd(host, NAND_CMD_READSTART, true);
Sascha Hauerc5d23f12009-06-04 17:25:53 +0200961
Sascha Hauer5f973042010-08-06 15:53:06 +0200962 host->send_page(mtd, NFC_OUTPUT);
Sascha Hauer89121a62009-06-04 17:18:01 +0200963
Sascha Hauerc6de7e12009-10-05 11:14:35 +0200964 memcpy(host->data_buf, host->main_area0, mtd->writesize);
Sascha Hauer89121a62009-06-04 17:18:01 +0200965 copy_spare(mtd, true);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200966 break;
967
Sascha Hauer34f6e152008-09-02 17:16:59 +0200968 case NAND_CMD_SEQIN:
Sascha Hauer5ea32022010-04-27 15:24:01 +0200969 if (column >= mtd->writesize)
970 /* call ourself to read a page */
971 mxc_nand_command(mtd, NAND_CMD_READ0, 0, page_addr);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200972
Sascha Hauer5ea32022010-04-27 15:24:01 +0200973 host->buf_start = column;
Sascha Hauer89121a62009-06-04 17:18:01 +0200974
Sascha Hauer5f973042010-08-06 15:53:06 +0200975 host->send_cmd(host, command, false);
Sascha Hauer89121a62009-06-04 17:18:01 +0200976 mxc_do_addr_cycle(mtd, column, page_addr);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200977 break;
978
979 case NAND_CMD_PAGEPROG:
Sascha Hauerc6de7e12009-10-05 11:14:35 +0200980 memcpy(host->main_area0, host->data_buf, mtd->writesize);
Sascha Hauerf8f96082009-06-04 17:12:26 +0200981 copy_spare(mtd, false);
Sascha Hauer5f973042010-08-06 15:53:06 +0200982 host->send_page(mtd, NFC_INPUT);
983 host->send_cmd(host, command, true);
Sascha Hauer89121a62009-06-04 17:18:01 +0200984 mxc_do_addr_cycle(mtd, column, page_addr);
Sascha Hauer34f6e152008-09-02 17:16:59 +0200985 break;
986
Sascha Hauer34f6e152008-09-02 17:16:59 +0200987 case NAND_CMD_READID:
Sascha Hauer5f973042010-08-06 15:53:06 +0200988 host->send_cmd(host, command, true);
Sascha Hauer89121a62009-06-04 17:18:01 +0200989 mxc_do_addr_cycle(mtd, column, page_addr);
Sascha Hauer5f973042010-08-06 15:53:06 +0200990 host->send_read_id(host);
Sascha Hauer94671142009-10-05 12:14:21 +0200991 host->buf_start = column;
Sascha Hauer34f6e152008-09-02 17:16:59 +0200992 break;
993
Sascha Hauer89121a62009-06-04 17:18:01 +0200994 case NAND_CMD_ERASE1:
Sascha Hauer34f6e152008-09-02 17:16:59 +0200995 case NAND_CMD_ERASE2:
Sascha Hauer5f973042010-08-06 15:53:06 +0200996 host->send_cmd(host, command, false);
Sascha Hauer89121a62009-06-04 17:18:01 +0200997 mxc_do_addr_cycle(mtd, column, page_addr);
998
Sascha Hauer34f6e152008-09-02 17:16:59 +0200999 break;
1000 }
1001}
1002
Sascha Hauerf1372052009-10-21 14:25:27 +02001003/*
1004 * The generic flash bbt decriptors overlap with our ecc
1005 * hardware, so define some i.MX specific ones.
1006 */
1007static uint8_t bbt_pattern[] = { 'B', 'b', 't', '0' };
1008static uint8_t mirror_pattern[] = { '1', 't', 'b', 'B' };
1009
1010static struct nand_bbt_descr bbt_main_descr = {
1011 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
1012 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
1013 .offs = 0,
1014 .len = 4,
1015 .veroffs = 4,
1016 .maxblocks = 4,
1017 .pattern = bbt_pattern,
1018};
1019
1020static struct nand_bbt_descr bbt_mirror_descr = {
1021 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
1022 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
1023 .offs = 0,
1024 .len = 4,
1025 .veroffs = 4,
1026 .maxblocks = 4,
1027 .pattern = mirror_pattern,
1028};
1029
Sascha Hauer34f6e152008-09-02 17:16:59 +02001030static int __init mxcnd_probe(struct platform_device *pdev)
1031{
1032 struct nand_chip *this;
1033 struct mtd_info *mtd;
1034 struct mxc_nand_platform_data *pdata = pdev->dev.platform_data;
1035 struct mxc_nand_host *host;
1036 struct resource *res;
Fabio Estevam2ebf0622010-11-23 17:02:13 -02001037 int err = 0, __maybe_unused nr_parts = 0;
Sascha Hauer94671142009-10-05 12:14:21 +02001038 struct nand_ecclayout *oob_smallpage, *oob_largepage;
Sascha Hauer34f6e152008-09-02 17:16:59 +02001039
1040 /* Allocate memory for MTD device structure and private data */
Sascha Hauerf8f96082009-06-04 17:12:26 +02001041 host = kzalloc(sizeof(struct mxc_nand_host) + NAND_MAX_PAGESIZE +
1042 NAND_MAX_OOBSIZE, GFP_KERNEL);
Sascha Hauer34f6e152008-09-02 17:16:59 +02001043 if (!host)
1044 return -ENOMEM;
1045
Sascha Hauerf8f96082009-06-04 17:12:26 +02001046 host->data_buf = (uint8_t *)(host + 1);
Sascha Hauerf8f96082009-06-04 17:12:26 +02001047
Sascha Hauer34f6e152008-09-02 17:16:59 +02001048 host->dev = &pdev->dev;
1049 /* structures must be linked */
1050 this = &host->nand;
1051 mtd = &host->mtd;
1052 mtd->priv = this;
1053 mtd->owner = THIS_MODULE;
David Brownell87f39f02009-03-26 00:42:50 -07001054 mtd->dev.parent = &pdev->dev;
Sascha Hauer1fbff0a2009-10-21 16:06:27 +02001055 mtd->name = DRIVER_NAME;
Sascha Hauer34f6e152008-09-02 17:16:59 +02001056
1057 /* 50 us command delay time */
1058 this->chip_delay = 5;
1059
1060 this->priv = host;
1061 this->dev_ready = mxc_nand_dev_ready;
1062 this->cmdfunc = mxc_nand_command;
1063 this->select_chip = mxc_nand_select_chip;
1064 this->read_byte = mxc_nand_read_byte;
1065 this->read_word = mxc_nand_read_word;
1066 this->write_buf = mxc_nand_write_buf;
1067 this->read_buf = mxc_nand_read_buf;
1068 this->verify_buf = mxc_nand_verify_buf;
1069
Sascha Hauere65fb002009-02-16 14:29:10 +01001070 host->clk = clk_get(&pdev->dev, "nfc");
Vladimir Barinov8541c112009-04-23 15:47:22 +04001071 if (IS_ERR(host->clk)) {
1072 err = PTR_ERR(host->clk);
Sascha Hauer34f6e152008-09-02 17:16:59 +02001073 goto eclk;
Vladimir Barinov8541c112009-04-23 15:47:22 +04001074 }
Sascha Hauer34f6e152008-09-02 17:16:59 +02001075
1076 clk_enable(host->clk);
1077 host->clk_act = 1;
1078
1079 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1080 if (!res) {
1081 err = -ENODEV;
1082 goto eres;
1083 }
1084
Sascha Hauerc6de7e12009-10-05 11:14:35 +02001085 host->base = ioremap(res->start, resource_size(res));
1086 if (!host->base) {
Vladimir Barinov8541c112009-04-23 15:47:22 +04001087 err = -ENOMEM;
Sascha Hauer34f6e152008-09-02 17:16:59 +02001088 goto eres;
1089 }
1090
Sascha Hauerc6de7e12009-10-05 11:14:35 +02001091 host->main_area0 = host->base;
Sascha Hauer94671142009-10-05 12:14:21 +02001092
Sascha Hauer5f973042010-08-06 15:53:06 +02001093 if (nfc_is_v1() || nfc_is_v21()) {
1094 host->preset = preset_v1_v2;
1095 host->send_cmd = send_cmd_v1_v2;
1096 host->send_addr = send_addr_v1_v2;
1097 host->send_page = send_page_v1_v2;
1098 host->send_read_id = send_read_id_v1_v2;
1099 host->get_dev_status = get_dev_status_v1_v2;
Sascha Hauer7aaf28a2010-08-06 15:53:07 +02001100 host->check_int = check_int_v1_v2;
Sascha Hauer63f14742010-10-18 10:16:26 +02001101 if (cpu_is_mx21())
1102 host->irq_control = irq_control_mx21;
1103 else
1104 host->irq_control = irq_control_v1_v2;
Sascha Hauer5f973042010-08-06 15:53:06 +02001105 }
Sascha Hauer94671142009-10-05 12:14:21 +02001106
1107 if (nfc_is_v21()) {
Sascha Hauer938cf992010-08-06 15:53:04 +02001108 host->regs = host->base + 0x1e00;
Sascha Hauer94671142009-10-05 12:14:21 +02001109 host->spare0 = host->base + 0x1000;
1110 host->spare_len = 64;
1111 oob_smallpage = &nandv2_hw_eccoob_smallpage;
1112 oob_largepage = &nandv2_hw_eccoob_largepage;
Ivo Claryssed4840182010-04-08 16:14:44 +02001113 this->ecc.bytes = 9;
Sascha Hauer94671142009-10-05 12:14:21 +02001114 } else if (nfc_is_v1()) {
Sascha Hauer938cf992010-08-06 15:53:04 +02001115 host->regs = host->base + 0xe00;
Sascha Hauer94671142009-10-05 12:14:21 +02001116 host->spare0 = host->base + 0x800;
1117 host->spare_len = 16;
1118 oob_smallpage = &nandv1_hw_eccoob_smallpage;
1119 oob_largepage = &nandv1_hw_eccoob_largepage;
Sascha Hauer94671142009-10-05 12:14:21 +02001120 this->ecc.bytes = 3;
Sascha Hauer71ec5152010-08-06 15:53:11 +02001121 host->eccsize = 1;
1122 } else if (nfc_is_v3_2()) {
1123 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1124 if (!res) {
1125 err = -ENODEV;
1126 goto eirq;
1127 }
1128 host->regs_ip = ioremap(res->start, resource_size(res));
1129 if (!host->regs_ip) {
1130 err = -ENOMEM;
1131 goto eirq;
1132 }
1133 host->regs_axi = host->base + 0x1e00;
1134 host->spare0 = host->base + 0x1000;
1135 host->spare_len = 64;
1136 host->preset = preset_v3;
1137 host->send_cmd = send_cmd_v3;
1138 host->send_addr = send_addr_v3;
1139 host->send_page = send_page_v3;
1140 host->send_read_id = send_read_id_v3;
1141 host->check_int = check_int_v3;
1142 host->get_dev_status = get_dev_status_v3;
Sascha Hauer63f14742010-10-18 10:16:26 +02001143 host->irq_control = irq_control_v3;
Sascha Hauer71ec5152010-08-06 15:53:11 +02001144 oob_smallpage = &nandv2_hw_eccoob_smallpage;
1145 oob_largepage = &nandv2_hw_eccoob_largepage;
Sascha Hauer94671142009-10-05 12:14:21 +02001146 } else
1147 BUG();
Sascha Hauer34f6e152008-09-02 17:16:59 +02001148
Sascha Hauer13e1add2009-10-21 10:39:05 +02001149 this->ecc.size = 512;
Sascha Hauer94671142009-10-05 12:14:21 +02001150 this->ecc.layout = oob_smallpage;
Sascha Hauer13e1add2009-10-21 10:39:05 +02001151
1152 if (pdata->hw_ecc) {
1153 this->ecc.calculate = mxc_nand_calculate_ecc;
1154 this->ecc.hwctl = mxc_nand_enable_hwecc;
Sascha Hauer94f77e52010-08-06 15:53:09 +02001155 if (nfc_is_v1())
1156 this->ecc.correct = mxc_nand_correct_data_v1;
1157 else
1158 this->ecc.correct = mxc_nand_correct_data_v2_v3;
Sascha Hauer13e1add2009-10-21 10:39:05 +02001159 this->ecc.mode = NAND_ECC_HW;
Sascha Hauer13e1add2009-10-21 10:39:05 +02001160 } else {
1161 this->ecc.mode = NAND_ECC_SOFT;
Sascha Hauer34f6e152008-09-02 17:16:59 +02001162 }
1163
Sascha Hauer34f6e152008-09-02 17:16:59 +02001164 /* NAND bus width determines access funtions used by upper layer */
Sascha Hauer13e1add2009-10-21 10:39:05 +02001165 if (pdata->width == 2)
Sascha Hauer34f6e152008-09-02 17:16:59 +02001166 this->options |= NAND_BUSWIDTH_16;
Sascha Hauer13e1add2009-10-21 10:39:05 +02001167
Sascha Hauerf1372052009-10-21 14:25:27 +02001168 if (pdata->flash_bbt) {
1169 this->bbt_td = &bbt_main_descr;
1170 this->bbt_md = &bbt_mirror_descr;
1171 /* update flash based bbt */
1172 this->options |= NAND_USE_FLASH_BBT;
Sascha Hauer34f6e152008-09-02 17:16:59 +02001173 }
1174
Sascha Hauer63f14742010-10-18 10:16:26 +02001175 init_completion(&host->op_completion);
Ivo Claryssed4840182010-04-08 16:14:44 +02001176
1177 host->irq = platform_get_irq(pdev, 0);
1178
Sascha Hauer63f14742010-10-18 10:16:26 +02001179 /*
1180 * mask the interrupt. For i.MX21 explicitely call
1181 * irq_control_v1_v2 to use the mask bit. We can't call
1182 * disable_irq_nosync() for an interrupt we do not own yet.
1183 */
1184 if (cpu_is_mx21())
1185 irq_control_v1_v2(host, 0);
1186 else
1187 host->irq_control(host, 0);
1188
Ivo Claryssea47bfd22010-04-08 16:16:51 +02001189 err = request_irq(host->irq, mxc_nfc_irq, IRQF_DISABLED, DRIVER_NAME, host);
Ivo Claryssed4840182010-04-08 16:14:44 +02001190 if (err)
1191 goto eirq;
1192
Sascha Hauer63f14742010-10-18 10:16:26 +02001193 host->irq_control(host, 0);
1194
1195 /*
1196 * Now that the interrupt is disabled make sure the interrupt
1197 * mask bit is cleared on i.MX21. Otherwise we can't read
1198 * the interrupt status bit on this machine.
1199 */
1200 if (cpu_is_mx21())
1201 irq_control_v1_v2(host, 1);
1202
Vladimir Barinovbd3fd622009-05-25 13:06:17 +04001203 /* first scan to find the device and get the page size */
David Woodhouse5e81e882010-02-26 18:32:56 +00001204 if (nand_scan_ident(mtd, 1, NULL)) {
Vladimir Barinovbd3fd622009-05-25 13:06:17 +04001205 err = -ENXIO;
1206 goto escan;
1207 }
Sascha Hauer34f6e152008-09-02 17:16:59 +02001208
Sascha Hauer6e85dfd2010-08-06 15:53:10 +02001209 /* Call preset again, with correct writesize this time */
1210 host->preset(mtd);
1211
Sascha Hauer2d69c7f2009-10-05 11:24:02 +02001212 if (mtd->writesize == 2048)
Sascha Hauer94671142009-10-05 12:14:21 +02001213 this->ecc.layout = oob_largepage;
Baruch Siach2c1c5f12011-03-09 16:12:20 +02001214 if (nfc_is_v21() && mtd->writesize == 4096)
1215 this->ecc.layout = &nandv2_hw_eccoob_4k;
Vladimir Barinovbd3fd622009-05-25 13:06:17 +04001216
1217 /* second phase scan */
1218 if (nand_scan_tail(mtd)) {
Sascha Hauer34f6e152008-09-02 17:16:59 +02001219 err = -ENXIO;
1220 goto escan;
1221 }
1222
1223 /* Register the partitions */
1224#ifdef CONFIG_MTD_PARTITIONS
1225 nr_parts =
1226 parse_mtd_partitions(mtd, part_probes, &host->parts, 0);
1227 if (nr_parts > 0)
1228 add_mtd_partitions(mtd, host->parts, nr_parts);
Baruch Siachcce02462010-05-31 08:49:40 +03001229 else if (pdata->parts)
1230 add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts);
Sascha Hauer34f6e152008-09-02 17:16:59 +02001231 else
1232#endif
1233 {
1234 pr_info("Registering %s as whole device\n", mtd->name);
1235 add_mtd_device(mtd);
1236 }
1237
1238 platform_set_drvdata(pdev, host);
1239
1240 return 0;
1241
1242escan:
Magnus Liljab258fd82009-05-08 21:57:47 +02001243 free_irq(host->irq, host);
Sascha Hauer34f6e152008-09-02 17:16:59 +02001244eirq:
Sascha Hauer71ec5152010-08-06 15:53:11 +02001245 if (host->regs_ip)
1246 iounmap(host->regs_ip);
Sascha Hauerc6de7e12009-10-05 11:14:35 +02001247 iounmap(host->base);
Sascha Hauer34f6e152008-09-02 17:16:59 +02001248eres:
1249 clk_put(host->clk);
1250eclk:
1251 kfree(host);
1252
1253 return err;
1254}
1255
Uwe Kleine-König51eeb872009-12-07 09:44:05 +00001256static int __devexit mxcnd_remove(struct platform_device *pdev)
Sascha Hauer34f6e152008-09-02 17:16:59 +02001257{
1258 struct mxc_nand_host *host = platform_get_drvdata(pdev);
1259
1260 clk_put(host->clk);
1261
1262 platform_set_drvdata(pdev, NULL);
1263
1264 nand_release(&host->mtd);
Magnus Liljab258fd82009-05-08 21:57:47 +02001265 free_irq(host->irq, host);
Sascha Hauer71ec5152010-08-06 15:53:11 +02001266 if (host->regs_ip)
1267 iounmap(host->regs_ip);
Sascha Hauerc6de7e12009-10-05 11:14:35 +02001268 iounmap(host->base);
Sascha Hauer34f6e152008-09-02 17:16:59 +02001269 kfree(host);
1270
1271 return 0;
1272}
1273
Sascha Hauer34f6e152008-09-02 17:16:59 +02001274static struct platform_driver mxcnd_driver = {
1275 .driver = {
1276 .name = DRIVER_NAME,
Eric Bénard04dd0d32010-06-17 20:59:04 +02001277 },
Uwe Kleine-Königdaa0f152009-11-24 22:07:08 +01001278 .remove = __devexit_p(mxcnd_remove),
Sascha Hauer34f6e152008-09-02 17:16:59 +02001279};
1280
1281static int __init mxc_nd_init(void)
1282{
Vladimir Barinov8541c112009-04-23 15:47:22 +04001283 return platform_driver_probe(&mxcnd_driver, mxcnd_probe);
Sascha Hauer34f6e152008-09-02 17:16:59 +02001284}
1285
1286static void __exit mxc_nd_cleanup(void)
1287{
1288 /* Unregister the device structure */
1289 platform_driver_unregister(&mxcnd_driver);
1290}
1291
1292module_init(mxc_nd_init);
1293module_exit(mxc_nd_cleanup);
1294
1295MODULE_AUTHOR("Freescale Semiconductor, Inc.");
1296MODULE_DESCRIPTION("MXC NAND MTD driver");
1297MODULE_LICENSE("GPL");