blob: 2912d6c93635a97101212b308cc09246fd0f4593 [file] [log] [blame]
Vimal Singh67ce04b2009-05-12 13:47:03 -07001/*
2 * Copyright © 2004 Texas Instruments, Jian Zhang <jzhang@ti.com>
3 * Copyright © 2004 Micron Technology Inc.
4 * Copyright © 2004 David Brownell
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/platform_device.h>
Russell King763e7352012-04-25 00:16:00 +010012#include <linux/dmaengine.h>
Vimal Singh67ce04b2009-05-12 13:47:03 -070013#include <linux/dma-mapping.h>
14#include <linux/delay.h>
Paul Gortmakera0e5cc52011-07-03 15:17:31 -040015#include <linux/module.h>
Sukumar Ghorai4e070372011-01-28 15:42:06 +053016#include <linux/interrupt.h>
vimal singhc276aca2009-06-27 11:07:06 +053017#include <linux/jiffies.h>
18#include <linux/sched.h>
Vimal Singh67ce04b2009-05-12 13:47:03 -070019#include <linux/mtd/mtd.h>
20#include <linux/mtd/nand.h>
21#include <linux/mtd/partitions.h>
Russell King763e7352012-04-25 00:16:00 +010022#include <linux/omap-dma.h>
Vimal Singh67ce04b2009-05-12 13:47:03 -070023#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Vimal Singh67ce04b2009-05-12 13:47:03 -070025
Ivan Djelic0e618ef2012-04-30 12:17:18 +020026#ifdef CONFIG_MTD_NAND_OMAP_BCH
27#include <linux/bch.h>
28#endif
29
Tony Lindgrence491cf2009-10-20 09:40:47 -070030#include <plat/dma.h>
31#include <plat/gpmc.h>
32#include <plat/nand.h>
Vimal Singh67ce04b2009-05-12 13:47:03 -070033
Vimal Singh67ce04b2009-05-12 13:47:03 -070034#define DRIVER_NAME "omap2-nand"
Sukumar Ghorai4e070372011-01-28 15:42:06 +053035#define OMAP_NAND_TIMEOUT_MS 5000
Vimal Singh67ce04b2009-05-12 13:47:03 -070036
Vimal Singh67ce04b2009-05-12 13:47:03 -070037#define NAND_Ecc_P1e (1 << 0)
38#define NAND_Ecc_P2e (1 << 1)
39#define NAND_Ecc_P4e (1 << 2)
40#define NAND_Ecc_P8e (1 << 3)
41#define NAND_Ecc_P16e (1 << 4)
42#define NAND_Ecc_P32e (1 << 5)
43#define NAND_Ecc_P64e (1 << 6)
44#define NAND_Ecc_P128e (1 << 7)
45#define NAND_Ecc_P256e (1 << 8)
46#define NAND_Ecc_P512e (1 << 9)
47#define NAND_Ecc_P1024e (1 << 10)
48#define NAND_Ecc_P2048e (1 << 11)
49
50#define NAND_Ecc_P1o (1 << 16)
51#define NAND_Ecc_P2o (1 << 17)
52#define NAND_Ecc_P4o (1 << 18)
53#define NAND_Ecc_P8o (1 << 19)
54#define NAND_Ecc_P16o (1 << 20)
55#define NAND_Ecc_P32o (1 << 21)
56#define NAND_Ecc_P64o (1 << 22)
57#define NAND_Ecc_P128o (1 << 23)
58#define NAND_Ecc_P256o (1 << 24)
59#define NAND_Ecc_P512o (1 << 25)
60#define NAND_Ecc_P1024o (1 << 26)
61#define NAND_Ecc_P2048o (1 << 27)
62
63#define TF(value) (value ? 1 : 0)
64
65#define P2048e(a) (TF(a & NAND_Ecc_P2048e) << 0)
66#define P2048o(a) (TF(a & NAND_Ecc_P2048o) << 1)
67#define P1e(a) (TF(a & NAND_Ecc_P1e) << 2)
68#define P1o(a) (TF(a & NAND_Ecc_P1o) << 3)
69#define P2e(a) (TF(a & NAND_Ecc_P2e) << 4)
70#define P2o(a) (TF(a & NAND_Ecc_P2o) << 5)
71#define P4e(a) (TF(a & NAND_Ecc_P4e) << 6)
72#define P4o(a) (TF(a & NAND_Ecc_P4o) << 7)
73
74#define P8e(a) (TF(a & NAND_Ecc_P8e) << 0)
75#define P8o(a) (TF(a & NAND_Ecc_P8o) << 1)
76#define P16e(a) (TF(a & NAND_Ecc_P16e) << 2)
77#define P16o(a) (TF(a & NAND_Ecc_P16o) << 3)
78#define P32e(a) (TF(a & NAND_Ecc_P32e) << 4)
79#define P32o(a) (TF(a & NAND_Ecc_P32o) << 5)
80#define P64e(a) (TF(a & NAND_Ecc_P64e) << 6)
81#define P64o(a) (TF(a & NAND_Ecc_P64o) << 7)
82
83#define P128e(a) (TF(a & NAND_Ecc_P128e) << 0)
84#define P128o(a) (TF(a & NAND_Ecc_P128o) << 1)
85#define P256e(a) (TF(a & NAND_Ecc_P256e) << 2)
86#define P256o(a) (TF(a & NAND_Ecc_P256o) << 3)
87#define P512e(a) (TF(a & NAND_Ecc_P512e) << 4)
88#define P512o(a) (TF(a & NAND_Ecc_P512o) << 5)
89#define P1024e(a) (TF(a & NAND_Ecc_P1024e) << 6)
90#define P1024o(a) (TF(a & NAND_Ecc_P1024o) << 7)
91
92#define P8e_s(a) (TF(a & NAND_Ecc_P8e) << 0)
93#define P8o_s(a) (TF(a & NAND_Ecc_P8o) << 1)
94#define P16e_s(a) (TF(a & NAND_Ecc_P16e) << 2)
95#define P16o_s(a) (TF(a & NAND_Ecc_P16o) << 3)
96#define P1e_s(a) (TF(a & NAND_Ecc_P1e) << 4)
97#define P1o_s(a) (TF(a & NAND_Ecc_P1o) << 5)
98#define P2e_s(a) (TF(a & NAND_Ecc_P2e) << 6)
99#define P2o_s(a) (TF(a & NAND_Ecc_P2o) << 7)
100
101#define P4e_s(a) (TF(a & NAND_Ecc_P4e) << 0)
102#define P4o_s(a) (TF(a & NAND_Ecc_P4o) << 1)
103
Sukumar Ghoraif040d332011-01-28 15:42:09 +0530104/* oob info generated runtime depending on ecc algorithm and layout selected */
105static struct nand_ecclayout omap_oobinfo;
106/* Define some generic bad / good block scan pattern which are used
107 * while scanning a device for factory marked good / bad blocks
108 */
109static uint8_t scan_ff_pattern[] = { 0xff };
110static struct nand_bbt_descr bb_descrip_flashbased = {
111 .options = NAND_BBT_SCANEMPTY | NAND_BBT_SCANALLPAGES,
112 .offs = 0,
113 .len = 1,
114 .pattern = scan_ff_pattern,
115};
vimal singh59e9c5a2009-07-13 16:26:24 +0530116
vimal singh59e9c5a2009-07-13 16:26:24 +0530117
Vimal Singh67ce04b2009-05-12 13:47:03 -0700118struct omap_nand_info {
119 struct nand_hw_control controller;
120 struct omap_nand_platform_data *pdata;
121 struct mtd_info mtd;
Vimal Singh67ce04b2009-05-12 13:47:03 -0700122 struct nand_chip nand;
123 struct platform_device *pdev;
124
125 int gpmc_cs;
126 unsigned long phys_base;
vimal singhdfe32892009-07-13 16:29:16 +0530127 struct completion comp;
Russell King763e7352012-04-25 00:16:00 +0100128 struct dma_chan *dma;
vimal singhdfe32892009-07-13 16:29:16 +0530129 int dma_ch;
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530130 int gpmc_irq;
131 enum {
132 OMAP_NAND_IO_READ = 0, /* read */
133 OMAP_NAND_IO_WRITE, /* write */
134 } iomode;
135 u_char *buf;
136 int buf_len;
Ivan Djelic0e618ef2012-04-30 12:17:18 +0200137
138#ifdef CONFIG_MTD_NAND_OMAP_BCH
139 struct bch_control *bch;
140 struct nand_ecclayout ecclayout;
141#endif
Vimal Singh67ce04b2009-05-12 13:47:03 -0700142};
143
144/**
Vimal Singh67ce04b2009-05-12 13:47:03 -0700145 * omap_hwcontrol - hardware specific access to control-lines
146 * @mtd: MTD device structure
147 * @cmd: command to device
148 * @ctrl:
149 * NAND_NCE: bit 0 -> don't care
150 * NAND_CLE: bit 1 -> Command Latch
151 * NAND_ALE: bit 2 -> Address Latch
152 *
153 * NOTE: boards may use different bits for these!!
154 */
155static void omap_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
156{
157 struct omap_nand_info *info = container_of(mtd,
158 struct omap_nand_info, mtd);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700159
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000160 if (cmd != NAND_CMD_NONE) {
161 if (ctrl & NAND_CLE)
162 gpmc_nand_write(info->gpmc_cs, GPMC_NAND_COMMAND, cmd);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700163
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000164 else if (ctrl & NAND_ALE)
165 gpmc_nand_write(info->gpmc_cs, GPMC_NAND_ADDRESS, cmd);
166
167 else /* NAND_NCE */
168 gpmc_nand_write(info->gpmc_cs, GPMC_NAND_DATA, cmd);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700169 }
Vimal Singh67ce04b2009-05-12 13:47:03 -0700170}
171
172/**
vimal singh59e9c5a2009-07-13 16:26:24 +0530173 * omap_read_buf8 - read data from NAND controller into buffer
174 * @mtd: MTD device structure
175 * @buf: buffer to store date
176 * @len: number of bytes to read
177 */
178static void omap_read_buf8(struct mtd_info *mtd, u_char *buf, int len)
179{
180 struct nand_chip *nand = mtd->priv;
181
182 ioread8_rep(nand->IO_ADDR_R, buf, len);
183}
184
185/**
186 * omap_write_buf8 - write buffer to NAND controller
187 * @mtd: MTD device structure
188 * @buf: data buffer
189 * @len: number of bytes to write
190 */
191static void omap_write_buf8(struct mtd_info *mtd, const u_char *buf, int len)
192{
193 struct omap_nand_info *info = container_of(mtd,
194 struct omap_nand_info, mtd);
195 u_char *p = (u_char *)buf;
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000196 u32 status = 0;
vimal singh59e9c5a2009-07-13 16:26:24 +0530197
198 while (len--) {
199 iowrite8(*p++, info->nand.IO_ADDR_W);
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000200 /* wait until buffer is available for write */
201 do {
202 status = gpmc_read_status(GPMC_STATUS_BUFFER);
203 } while (!status);
vimal singh59e9c5a2009-07-13 16:26:24 +0530204 }
205}
206
207/**
Vimal Singh67ce04b2009-05-12 13:47:03 -0700208 * omap_read_buf16 - read data from NAND controller into buffer
209 * @mtd: MTD device structure
210 * @buf: buffer to store date
211 * @len: number of bytes to read
212 */
213static void omap_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
214{
215 struct nand_chip *nand = mtd->priv;
216
vimal singh59e9c5a2009-07-13 16:26:24 +0530217 ioread16_rep(nand->IO_ADDR_R, buf, len / 2);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700218}
219
220/**
221 * omap_write_buf16 - write buffer to NAND controller
222 * @mtd: MTD device structure
223 * @buf: data buffer
224 * @len: number of bytes to write
225 */
226static void omap_write_buf16(struct mtd_info *mtd, const u_char * buf, int len)
227{
228 struct omap_nand_info *info = container_of(mtd,
229 struct omap_nand_info, mtd);
230 u16 *p = (u16 *) buf;
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000231 u32 status = 0;
Vimal Singh67ce04b2009-05-12 13:47:03 -0700232 /* FIXME try bursts of writesw() or DMA ... */
233 len >>= 1;
234
235 while (len--) {
vimal singh59e9c5a2009-07-13 16:26:24 +0530236 iowrite16(*p++, info->nand.IO_ADDR_W);
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000237 /* wait until buffer is available for write */
238 do {
239 status = gpmc_read_status(GPMC_STATUS_BUFFER);
240 } while (!status);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700241 }
242}
vimal singh59e9c5a2009-07-13 16:26:24 +0530243
244/**
245 * omap_read_buf_pref - read data from NAND controller into buffer
246 * @mtd: MTD device structure
247 * @buf: buffer to store date
248 * @len: number of bytes to read
249 */
250static void omap_read_buf_pref(struct mtd_info *mtd, u_char *buf, int len)
251{
252 struct omap_nand_info *info = container_of(mtd,
253 struct omap_nand_info, mtd);
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000254 uint32_t r_count = 0;
vimal singh59e9c5a2009-07-13 16:26:24 +0530255 int ret = 0;
256 u32 *p = (u32 *)buf;
257
258 /* take care of subpage reads */
Vimal Singhc3341d02010-01-07 12:16:26 +0530259 if (len % 4) {
260 if (info->nand.options & NAND_BUSWIDTH_16)
261 omap_read_buf16(mtd, buf, len % 4);
262 else
263 omap_read_buf8(mtd, buf, len % 4);
264 p = (u32 *) (buf + len % 4);
265 len -= len % 4;
vimal singh59e9c5a2009-07-13 16:26:24 +0530266 }
vimal singh59e9c5a2009-07-13 16:26:24 +0530267
268 /* configure and start prefetch transfer */
Sukumar Ghorai317379a2011-01-28 15:42:07 +0530269 ret = gpmc_prefetch_enable(info->gpmc_cs,
270 PREFETCH_FIFOTHRESHOLD_MAX, 0x0, len, 0x0);
vimal singh59e9c5a2009-07-13 16:26:24 +0530271 if (ret) {
272 /* PFPW engine is busy, use cpu copy method */
273 if (info->nand.options & NAND_BUSWIDTH_16)
Kishore Kadiyalac5d8c0c2011-05-11 21:17:27 +0530274 omap_read_buf16(mtd, (u_char *)p, len);
vimal singh59e9c5a2009-07-13 16:26:24 +0530275 else
Kishore Kadiyalac5d8c0c2011-05-11 21:17:27 +0530276 omap_read_buf8(mtd, (u_char *)p, len);
vimal singh59e9c5a2009-07-13 16:26:24 +0530277 } else {
278 do {
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000279 r_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
280 r_count = r_count >> 2;
281 ioread32_rep(info->nand.IO_ADDR_R, p, r_count);
vimal singh59e9c5a2009-07-13 16:26:24 +0530282 p += r_count;
283 len -= r_count << 2;
284 } while (len);
vimal singh59e9c5a2009-07-13 16:26:24 +0530285 /* disable and stop the PFPW engine */
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000286 gpmc_prefetch_reset(info->gpmc_cs);
vimal singh59e9c5a2009-07-13 16:26:24 +0530287 }
288}
289
290/**
291 * omap_write_buf_pref - write buffer to NAND controller
292 * @mtd: MTD device structure
293 * @buf: data buffer
294 * @len: number of bytes to write
295 */
296static void omap_write_buf_pref(struct mtd_info *mtd,
297 const u_char *buf, int len)
298{
299 struct omap_nand_info *info = container_of(mtd,
300 struct omap_nand_info, mtd);
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530301 uint32_t w_count = 0;
vimal singh59e9c5a2009-07-13 16:26:24 +0530302 int i = 0, ret = 0;
Kishore Kadiyalac5d8c0c2011-05-11 21:17:27 +0530303 u16 *p = (u16 *)buf;
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530304 unsigned long tim, limit;
vimal singh59e9c5a2009-07-13 16:26:24 +0530305
306 /* take care of subpage writes */
307 if (len % 2 != 0) {
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000308 writeb(*buf, info->nand.IO_ADDR_W);
vimal singh59e9c5a2009-07-13 16:26:24 +0530309 p = (u16 *)(buf + 1);
310 len--;
311 }
312
313 /* configure and start prefetch transfer */
Sukumar Ghorai317379a2011-01-28 15:42:07 +0530314 ret = gpmc_prefetch_enable(info->gpmc_cs,
315 PREFETCH_FIFOTHRESHOLD_MAX, 0x0, len, 0x1);
vimal singh59e9c5a2009-07-13 16:26:24 +0530316 if (ret) {
317 /* PFPW engine is busy, use cpu copy method */
318 if (info->nand.options & NAND_BUSWIDTH_16)
Kishore Kadiyalac5d8c0c2011-05-11 21:17:27 +0530319 omap_write_buf16(mtd, (u_char *)p, len);
vimal singh59e9c5a2009-07-13 16:26:24 +0530320 else
Kishore Kadiyalac5d8c0c2011-05-11 21:17:27 +0530321 omap_write_buf8(mtd, (u_char *)p, len);
vimal singh59e9c5a2009-07-13 16:26:24 +0530322 } else {
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000323 while (len) {
324 w_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
325 w_count = w_count >> 1;
vimal singh59e9c5a2009-07-13 16:26:24 +0530326 for (i = 0; (i < w_count) && len; i++, len -= 2)
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000327 iowrite16(*p++, info->nand.IO_ADDR_W);
vimal singh59e9c5a2009-07-13 16:26:24 +0530328 }
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000329 /* wait for data to flushed-out before reset the prefetch */
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530330 tim = 0;
331 limit = (loops_per_jiffy *
332 msecs_to_jiffies(OMAP_NAND_TIMEOUT_MS));
333 while (gpmc_read_status(GPMC_PREFETCH_COUNT) && (tim++ < limit))
334 cpu_relax();
335
vimal singh59e9c5a2009-07-13 16:26:24 +0530336 /* disable and stop the PFPW engine */
Sukumar Ghorai948d38e2010-07-09 09:14:44 +0000337 gpmc_prefetch_reset(info->gpmc_cs);
vimal singh59e9c5a2009-07-13 16:26:24 +0530338 }
339}
340
vimal singhdfe32892009-07-13 16:29:16 +0530341/*
342 * omap_nand_dma_cb: callback on the completion of dma transfer
343 * @lch: logical channel
344 * @ch_satuts: channel status
345 * @data: pointer to completion data structure
346 */
347static void omap_nand_dma_cb(int lch, u16 ch_status, void *data)
348{
349 complete((struct completion *) data);
350}
Russell King763e7352012-04-25 00:16:00 +0100351static void omap_nand_dma_callback(void *data)
352{
353 complete((struct completion *) data);
354}
vimal singhdfe32892009-07-13 16:29:16 +0530355
356/*
357 * omap_nand_dma_transfer: configer and start dma transfer
358 * @mtd: MTD device structure
359 * @addr: virtual address in RAM of source/destination
360 * @len: number of data bytes to be transferred
361 * @is_write: flag for read/write operation
362 */
363static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
364 unsigned int len, int is_write)
365{
366 struct omap_nand_info *info = container_of(mtd,
367 struct omap_nand_info, mtd);
vimal singhdfe32892009-07-13 16:29:16 +0530368 enum dma_data_direction dir = is_write ? DMA_TO_DEVICE :
369 DMA_FROM_DEVICE;
370 dma_addr_t dma_addr;
371 int ret;
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530372 unsigned long tim, limit;
vimal singhdfe32892009-07-13 16:29:16 +0530373
Sukumar Ghorai317379a2011-01-28 15:42:07 +0530374 /* The fifo depth is 64 bytes max.
375 * But configure the FIFO-threahold to 32 to get a sync at each frame
376 * and frame length is 32 bytes.
vimal singhdfe32892009-07-13 16:29:16 +0530377 */
378 int buf_len = len >> 6;
379
380 if (addr >= high_memory) {
381 struct page *p1;
382
383 if (((size_t)addr & PAGE_MASK) !=
384 ((size_t)(addr + len - 1) & PAGE_MASK))
385 goto out_copy;
386 p1 = vmalloc_to_page(addr);
387 if (!p1)
388 goto out_copy;
389 addr = page_address(p1) + ((size_t)addr & ~PAGE_MASK);
390 }
391
Russell King763e7352012-04-25 00:16:00 +0100392 if (info->dma) {
393 struct dma_async_tx_descriptor *tx;
394 struct scatterlist sg;
395 unsigned n;
396
397 sg_init_one(&sg, addr, len);
398 n = dma_map_sg(info->dma->device->dev, &sg, 1, dir);
399 if (n == 0) {
400 dev_err(&info->pdev->dev,
401 "Couldn't DMA map a %d byte buffer\n", len);
402 goto out_copy;
403 }
404
405 tx = dmaengine_prep_slave_sg(info->dma, &sg, n,
406 is_write ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM,
407 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
408 if (!tx) {
409 dma_unmap_sg(info->dma->device->dev, &sg, 1, dir);
410 goto out_copy;
411 }
412 tx->callback = omap_nand_dma_callback;
413 tx->callback_param = &info->comp;
414 dmaengine_submit(tx);
415
416 /* configure and start prefetch transfer */
417 ret = gpmc_prefetch_enable(info->gpmc_cs,
418 PREFETCH_FIFOTHRESHOLD_MAX, 0x1, len, is_write);
419 if (ret) {
420 /* PFPW engine is busy, use cpu copy method */
421 dma_unmap_sg(info->dma->device->dev, &sg, 1, dir);
422 goto out_copy;
423 }
424
425 init_completion(&info->comp);
426 dma_async_issue_pending(info->dma);
427
428 /* setup and start DMA using dma_addr */
429 wait_for_completion(&info->comp);
430 tim = 0;
431 limit = (loops_per_jiffy * msecs_to_jiffies(OMAP_NAND_TIMEOUT_MS));
432 while (gpmc_read_status(GPMC_PREFETCH_COUNT) && (tim++ < limit))
433 cpu_relax();
434
435 /* disable and stop the PFPW engine */
436 gpmc_prefetch_reset(info->gpmc_cs);
437
438 dma_unmap_sg(info->dma->device->dev, &sg, 1, dir);
439 return 0;
440 }
441
vimal singhdfe32892009-07-13 16:29:16 +0530442 dma_addr = dma_map_single(&info->pdev->dev, addr, len, dir);
443 if (dma_mapping_error(&info->pdev->dev, dma_addr)) {
444 dev_err(&info->pdev->dev,
445 "Couldn't DMA map a %d byte buffer\n", len);
446 goto out_copy;
447 }
448
449 if (is_write) {
450 omap_set_dma_dest_params(info->dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
451 info->phys_base, 0, 0);
452 omap_set_dma_src_params(info->dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
453 dma_addr, 0, 0);
454 omap_set_dma_transfer_params(info->dma_ch, OMAP_DMA_DATA_TYPE_S32,
455 0x10, buf_len, OMAP_DMA_SYNC_FRAME,
456 OMAP24XX_DMA_GPMC, OMAP_DMA_DST_SYNC);
457 } else {
458 omap_set_dma_src_params(info->dma_ch, 0, OMAP_DMA_AMODE_CONSTANT,
459 info->phys_base, 0, 0);
460 omap_set_dma_dest_params(info->dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
461 dma_addr, 0, 0);
462 omap_set_dma_transfer_params(info->dma_ch, OMAP_DMA_DATA_TYPE_S32,
463 0x10, buf_len, OMAP_DMA_SYNC_FRAME,
464 OMAP24XX_DMA_GPMC, OMAP_DMA_SRC_SYNC);
465 }
466 /* configure and start prefetch transfer */
Sukumar Ghorai317379a2011-01-28 15:42:07 +0530467 ret = gpmc_prefetch_enable(info->gpmc_cs,
468 PREFETCH_FIFOTHRESHOLD_MAX, 0x1, len, is_write);
vimal singhdfe32892009-07-13 16:29:16 +0530469 if (ret)
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530470 /* PFPW engine is busy, use cpu copy method */
Grazvydas Ignotasd7efe222012-04-11 04:04:34 +0300471 goto out_copy_unmap;
vimal singhdfe32892009-07-13 16:29:16 +0530472
473 init_completion(&info->comp);
vimal singhdfe32892009-07-13 16:29:16 +0530474 omap_start_dma(info->dma_ch);
475
476 /* setup and start DMA using dma_addr */
477 wait_for_completion(&info->comp);
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530478 tim = 0;
479 limit = (loops_per_jiffy * msecs_to_jiffies(OMAP_NAND_TIMEOUT_MS));
480 while (gpmc_read_status(GPMC_PREFETCH_COUNT) && (tim++ < limit))
481 cpu_relax();
vimal singhdfe32892009-07-13 16:29:16 +0530482
vimal singhdfe32892009-07-13 16:29:16 +0530483 /* disable and stop the PFPW engine */
Daniel J Bluemanf12f6622010-09-29 21:01:55 +0100484 gpmc_prefetch_reset(info->gpmc_cs);
vimal singhdfe32892009-07-13 16:29:16 +0530485
486 dma_unmap_single(&info->pdev->dev, dma_addr, len, dir);
487 return 0;
488
Grazvydas Ignotasd7efe222012-04-11 04:04:34 +0300489out_copy_unmap:
490 dma_unmap_single(&info->pdev->dev, dma_addr, len, dir);
vimal singhdfe32892009-07-13 16:29:16 +0530491out_copy:
492 if (info->nand.options & NAND_BUSWIDTH_16)
493 is_write == 0 ? omap_read_buf16(mtd, (u_char *) addr, len)
494 : omap_write_buf16(mtd, (u_char *) addr, len);
495 else
496 is_write == 0 ? omap_read_buf8(mtd, (u_char *) addr, len)
497 : omap_write_buf8(mtd, (u_char *) addr, len);
498 return 0;
499}
vimal singhdfe32892009-07-13 16:29:16 +0530500
501/**
502 * omap_read_buf_dma_pref - read data from NAND controller into buffer
503 * @mtd: MTD device structure
504 * @buf: buffer to store date
505 * @len: number of bytes to read
506 */
507static void omap_read_buf_dma_pref(struct mtd_info *mtd, u_char *buf, int len)
508{
509 if (len <= mtd->oobsize)
510 omap_read_buf_pref(mtd, buf, len);
511 else
512 /* start transfer in DMA mode */
513 omap_nand_dma_transfer(mtd, buf, len, 0x0);
514}
515
516/**
517 * omap_write_buf_dma_pref - write buffer to NAND controller
518 * @mtd: MTD device structure
519 * @buf: data buffer
520 * @len: number of bytes to write
521 */
522static void omap_write_buf_dma_pref(struct mtd_info *mtd,
523 const u_char *buf, int len)
524{
525 if (len <= mtd->oobsize)
526 omap_write_buf_pref(mtd, buf, len);
527 else
528 /* start transfer in DMA mode */
Vimal Singhbdaefc42010-01-05 12:49:24 +0530529 omap_nand_dma_transfer(mtd, (u_char *) buf, len, 0x1);
vimal singhdfe32892009-07-13 16:29:16 +0530530}
531
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530532/*
533 * omap_nand_irq - GMPC irq handler
534 * @this_irq: gpmc irq number
535 * @dev: omap_nand_info structure pointer is passed here
536 */
537static irqreturn_t omap_nand_irq(int this_irq, void *dev)
538{
539 struct omap_nand_info *info = (struct omap_nand_info *) dev;
540 u32 bytes;
541 u32 irq_stat;
542
543 irq_stat = gpmc_read_status(GPMC_GET_IRQ_STATUS);
544 bytes = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
545 bytes = bytes & 0xFFFC; /* io in multiple of 4 bytes */
546 if (info->iomode == OMAP_NAND_IO_WRITE) { /* checks for write io */
547 if (irq_stat & 0x2)
548 goto done;
549
550 if (info->buf_len && (info->buf_len < bytes))
551 bytes = info->buf_len;
552 else if (!info->buf_len)
553 bytes = 0;
554 iowrite32_rep(info->nand.IO_ADDR_W,
555 (u32 *)info->buf, bytes >> 2);
556 info->buf = info->buf + bytes;
557 info->buf_len -= bytes;
558
559 } else {
560 ioread32_rep(info->nand.IO_ADDR_R,
561 (u32 *)info->buf, bytes >> 2);
562 info->buf = info->buf + bytes;
563
564 if (irq_stat & 0x2)
565 goto done;
566 }
567 gpmc_cs_configure(info->gpmc_cs, GPMC_SET_IRQ_STATUS, irq_stat);
568
569 return IRQ_HANDLED;
570
571done:
572 complete(&info->comp);
573 /* disable irq */
574 gpmc_cs_configure(info->gpmc_cs, GPMC_ENABLE_IRQ, 0);
575
576 /* clear status */
577 gpmc_cs_configure(info->gpmc_cs, GPMC_SET_IRQ_STATUS, irq_stat);
578
579 return IRQ_HANDLED;
580}
581
582/*
583 * omap_read_buf_irq_pref - read data from NAND controller into buffer
584 * @mtd: MTD device structure
585 * @buf: buffer to store date
586 * @len: number of bytes to read
587 */
588static void omap_read_buf_irq_pref(struct mtd_info *mtd, u_char *buf, int len)
589{
590 struct omap_nand_info *info = container_of(mtd,
591 struct omap_nand_info, mtd);
592 int ret = 0;
593
594 if (len <= mtd->oobsize) {
595 omap_read_buf_pref(mtd, buf, len);
596 return;
597 }
598
599 info->iomode = OMAP_NAND_IO_READ;
600 info->buf = buf;
601 init_completion(&info->comp);
602
603 /* configure and start prefetch transfer */
Sukumar Ghorai317379a2011-01-28 15:42:07 +0530604 ret = gpmc_prefetch_enable(info->gpmc_cs,
605 PREFETCH_FIFOTHRESHOLD_MAX/2, 0x0, len, 0x0);
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530606 if (ret)
607 /* PFPW engine is busy, use cpu copy method */
608 goto out_copy;
609
610 info->buf_len = len;
611 /* enable irq */
612 gpmc_cs_configure(info->gpmc_cs, GPMC_ENABLE_IRQ,
613 (GPMC_IRQ_FIFOEVENTENABLE | GPMC_IRQ_COUNT_EVENT));
614
615 /* waiting for read to complete */
616 wait_for_completion(&info->comp);
617
618 /* disable and stop the PFPW engine */
619 gpmc_prefetch_reset(info->gpmc_cs);
620 return;
621
622out_copy:
623 if (info->nand.options & NAND_BUSWIDTH_16)
624 omap_read_buf16(mtd, buf, len);
625 else
626 omap_read_buf8(mtd, buf, len);
627}
628
629/*
630 * omap_write_buf_irq_pref - write buffer to NAND controller
631 * @mtd: MTD device structure
632 * @buf: data buffer
633 * @len: number of bytes to write
634 */
635static void omap_write_buf_irq_pref(struct mtd_info *mtd,
636 const u_char *buf, int len)
637{
638 struct omap_nand_info *info = container_of(mtd,
639 struct omap_nand_info, mtd);
640 int ret = 0;
641 unsigned long tim, limit;
642
643 if (len <= mtd->oobsize) {
644 omap_write_buf_pref(mtd, buf, len);
645 return;
646 }
647
648 info->iomode = OMAP_NAND_IO_WRITE;
649 info->buf = (u_char *) buf;
650 init_completion(&info->comp);
651
Sukumar Ghorai317379a2011-01-28 15:42:07 +0530652 /* configure and start prefetch transfer : size=24 */
653 ret = gpmc_prefetch_enable(info->gpmc_cs,
654 (PREFETCH_FIFOTHRESHOLD_MAX * 3) / 8, 0x0, len, 0x1);
Sukumar Ghorai4e070372011-01-28 15:42:06 +0530655 if (ret)
656 /* PFPW engine is busy, use cpu copy method */
657 goto out_copy;
658
659 info->buf_len = len;
660 /* enable irq */
661 gpmc_cs_configure(info->gpmc_cs, GPMC_ENABLE_IRQ,
662 (GPMC_IRQ_FIFOEVENTENABLE | GPMC_IRQ_COUNT_EVENT));
663
664 /* waiting for write to complete */
665 wait_for_completion(&info->comp);
666 /* wait for data to flushed-out before reset the prefetch */
667 tim = 0;
668 limit = (loops_per_jiffy * msecs_to_jiffies(OMAP_NAND_TIMEOUT_MS));
669 while (gpmc_read_status(GPMC_PREFETCH_COUNT) && (tim++ < limit))
670 cpu_relax();
671
672 /* disable and stop the PFPW engine */
673 gpmc_prefetch_reset(info->gpmc_cs);
674 return;
675
676out_copy:
677 if (info->nand.options & NAND_BUSWIDTH_16)
678 omap_write_buf16(mtd, buf, len);
679 else
680 omap_write_buf8(mtd, buf, len);
681}
682
Vimal Singh67ce04b2009-05-12 13:47:03 -0700683/**
684 * omap_verify_buf - Verify chip data against buffer
685 * @mtd: MTD device structure
686 * @buf: buffer containing the data to compare
687 * @len: number of bytes to compare
688 */
689static int omap_verify_buf(struct mtd_info *mtd, const u_char * buf, int len)
690{
691 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
692 mtd);
693 u16 *p = (u16 *) buf;
694
695 len >>= 1;
696 while (len--) {
697 if (*p++ != cpu_to_le16(readw(info->nand.IO_ADDR_R)))
698 return -EFAULT;
699 }
700
701 return 0;
702}
703
Vimal Singh67ce04b2009-05-12 13:47:03 -0700704/**
705 * gen_true_ecc - This function will generate true ECC value
706 * @ecc_buf: buffer to store ecc code
707 *
708 * This generated true ECC value can be used when correcting
709 * data read from NAND flash memory core
710 */
711static void gen_true_ecc(u8 *ecc_buf)
712{
713 u32 tmp = ecc_buf[0] | (ecc_buf[1] << 16) |
714 ((ecc_buf[2] & 0xF0) << 20) | ((ecc_buf[2] & 0x0F) << 8);
715
716 ecc_buf[0] = ~(P64o(tmp) | P64e(tmp) | P32o(tmp) | P32e(tmp) |
717 P16o(tmp) | P16e(tmp) | P8o(tmp) | P8e(tmp));
718 ecc_buf[1] = ~(P1024o(tmp) | P1024e(tmp) | P512o(tmp) | P512e(tmp) |
719 P256o(tmp) | P256e(tmp) | P128o(tmp) | P128e(tmp));
720 ecc_buf[2] = ~(P4o(tmp) | P4e(tmp) | P2o(tmp) | P2e(tmp) | P1o(tmp) |
721 P1e(tmp) | P2048o(tmp) | P2048e(tmp));
722}
723
724/**
725 * omap_compare_ecc - Detect (2 bits) and correct (1 bit) error in data
726 * @ecc_data1: ecc code from nand spare area
727 * @ecc_data2: ecc code from hardware register obtained from hardware ecc
728 * @page_data: page data
729 *
730 * This function compares two ECC's and indicates if there is an error.
731 * If the error can be corrected it will be corrected to the buffer.
John Ogness74f1b722011-02-28 13:12:46 +0100732 * If there is no error, %0 is returned. If there is an error but it
733 * was corrected, %1 is returned. Otherwise, %-1 is returned.
Vimal Singh67ce04b2009-05-12 13:47:03 -0700734 */
735static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
736 u8 *ecc_data2, /* read from register */
737 u8 *page_data)
738{
739 uint i;
740 u8 tmp0_bit[8], tmp1_bit[8], tmp2_bit[8];
741 u8 comp0_bit[8], comp1_bit[8], comp2_bit[8];
742 u8 ecc_bit[24];
743 u8 ecc_sum = 0;
744 u8 find_bit = 0;
745 uint find_byte = 0;
746 int isEccFF;
747
748 isEccFF = ((*(u32 *)ecc_data1 & 0xFFFFFF) == 0xFFFFFF);
749
750 gen_true_ecc(ecc_data1);
751 gen_true_ecc(ecc_data2);
752
753 for (i = 0; i <= 2; i++) {
754 *(ecc_data1 + i) = ~(*(ecc_data1 + i));
755 *(ecc_data2 + i) = ~(*(ecc_data2 + i));
756 }
757
758 for (i = 0; i < 8; i++) {
759 tmp0_bit[i] = *ecc_data1 % 2;
760 *ecc_data1 = *ecc_data1 / 2;
761 }
762
763 for (i = 0; i < 8; i++) {
764 tmp1_bit[i] = *(ecc_data1 + 1) % 2;
765 *(ecc_data1 + 1) = *(ecc_data1 + 1) / 2;
766 }
767
768 for (i = 0; i < 8; i++) {
769 tmp2_bit[i] = *(ecc_data1 + 2) % 2;
770 *(ecc_data1 + 2) = *(ecc_data1 + 2) / 2;
771 }
772
773 for (i = 0; i < 8; i++) {
774 comp0_bit[i] = *ecc_data2 % 2;
775 *ecc_data2 = *ecc_data2 / 2;
776 }
777
778 for (i = 0; i < 8; i++) {
779 comp1_bit[i] = *(ecc_data2 + 1) % 2;
780 *(ecc_data2 + 1) = *(ecc_data2 + 1) / 2;
781 }
782
783 for (i = 0; i < 8; i++) {
784 comp2_bit[i] = *(ecc_data2 + 2) % 2;
785 *(ecc_data2 + 2) = *(ecc_data2 + 2) / 2;
786 }
787
788 for (i = 0; i < 6; i++)
789 ecc_bit[i] = tmp2_bit[i + 2] ^ comp2_bit[i + 2];
790
791 for (i = 0; i < 8; i++)
792 ecc_bit[i + 6] = tmp0_bit[i] ^ comp0_bit[i];
793
794 for (i = 0; i < 8; i++)
795 ecc_bit[i + 14] = tmp1_bit[i] ^ comp1_bit[i];
796
797 ecc_bit[22] = tmp2_bit[0] ^ comp2_bit[0];
798 ecc_bit[23] = tmp2_bit[1] ^ comp2_bit[1];
799
800 for (i = 0; i < 24; i++)
801 ecc_sum += ecc_bit[i];
802
803 switch (ecc_sum) {
804 case 0:
805 /* Not reached because this function is not called if
806 * ECC values are equal
807 */
808 return 0;
809
810 case 1:
811 /* Uncorrectable error */
Brian Norris289c0522011-07-19 10:06:09 -0700812 pr_debug("ECC UNCORRECTED_ERROR 1\n");
Vimal Singh67ce04b2009-05-12 13:47:03 -0700813 return -1;
814
815 case 11:
816 /* UN-Correctable error */
Brian Norris289c0522011-07-19 10:06:09 -0700817 pr_debug("ECC UNCORRECTED_ERROR B\n");
Vimal Singh67ce04b2009-05-12 13:47:03 -0700818 return -1;
819
820 case 12:
821 /* Correctable error */
822 find_byte = (ecc_bit[23] << 8) +
823 (ecc_bit[21] << 7) +
824 (ecc_bit[19] << 6) +
825 (ecc_bit[17] << 5) +
826 (ecc_bit[15] << 4) +
827 (ecc_bit[13] << 3) +
828 (ecc_bit[11] << 2) +
829 (ecc_bit[9] << 1) +
830 ecc_bit[7];
831
832 find_bit = (ecc_bit[5] << 2) + (ecc_bit[3] << 1) + ecc_bit[1];
833
Brian Norris0a32a102011-07-19 10:06:10 -0700834 pr_debug("Correcting single bit ECC error at offset: "
835 "%d, bit: %d\n", find_byte, find_bit);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700836
837 page_data[find_byte] ^= (1 << find_bit);
838
John Ogness74f1b722011-02-28 13:12:46 +0100839 return 1;
Vimal Singh67ce04b2009-05-12 13:47:03 -0700840 default:
841 if (isEccFF) {
842 if (ecc_data2[0] == 0 &&
843 ecc_data2[1] == 0 &&
844 ecc_data2[2] == 0)
845 return 0;
846 }
Brian Norris289c0522011-07-19 10:06:09 -0700847 pr_debug("UNCORRECTED_ERROR default\n");
Vimal Singh67ce04b2009-05-12 13:47:03 -0700848 return -1;
849 }
850}
851
852/**
853 * omap_correct_data - Compares the ECC read with HW generated ECC
854 * @mtd: MTD device structure
855 * @dat: page data
856 * @read_ecc: ecc read from nand flash
857 * @calc_ecc: ecc read from HW ECC registers
858 *
859 * Compares the ecc read from nand spare area with ECC registers values
John Ogness74f1b722011-02-28 13:12:46 +0100860 * and if ECC's mismatched, it will call 'omap_compare_ecc' for error
861 * detection and correction. If there are no errors, %0 is returned. If
862 * there were errors and all of the errors were corrected, the number of
863 * corrected errors is returned. If uncorrectable errors exist, %-1 is
864 * returned.
Vimal Singh67ce04b2009-05-12 13:47:03 -0700865 */
866static int omap_correct_data(struct mtd_info *mtd, u_char *dat,
867 u_char *read_ecc, u_char *calc_ecc)
868{
869 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
870 mtd);
871 int blockCnt = 0, i = 0, ret = 0;
John Ogness74f1b722011-02-28 13:12:46 +0100872 int stat = 0;
Vimal Singh67ce04b2009-05-12 13:47:03 -0700873
874 /* Ex NAND_ECC_HW12_2048 */
875 if ((info->nand.ecc.mode == NAND_ECC_HW) &&
876 (info->nand.ecc.size == 2048))
877 blockCnt = 4;
878 else
879 blockCnt = 1;
880
881 for (i = 0; i < blockCnt; i++) {
882 if (memcmp(read_ecc, calc_ecc, 3) != 0) {
883 ret = omap_compare_ecc(read_ecc, calc_ecc, dat);
884 if (ret < 0)
885 return ret;
John Ogness74f1b722011-02-28 13:12:46 +0100886 /* keep track of the number of corrected errors */
887 stat += ret;
Vimal Singh67ce04b2009-05-12 13:47:03 -0700888 }
889 read_ecc += 3;
890 calc_ecc += 3;
891 dat += 512;
892 }
John Ogness74f1b722011-02-28 13:12:46 +0100893 return stat;
Vimal Singh67ce04b2009-05-12 13:47:03 -0700894}
895
896/**
897 * omap_calcuate_ecc - Generate non-inverted ECC bytes.
898 * @mtd: MTD device structure
899 * @dat: The pointer to data on which ecc is computed
900 * @ecc_code: The ecc_code buffer
901 *
902 * Using noninverted ECC can be considered ugly since writing a blank
903 * page ie. padding will clear the ECC bytes. This is no problem as long
904 * nobody is trying to write data on the seemingly unused page. Reading
905 * an erased page will produce an ECC mismatch between generated and read
906 * ECC bytes that has to be dealt with separately.
907 */
908static int omap_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
909 u_char *ecc_code)
910{
911 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
912 mtd);
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000913 return gpmc_calculate_ecc(info->gpmc_cs, dat, ecc_code);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700914}
915
916/**
917 * omap_enable_hwecc - This function enables the hardware ecc functionality
918 * @mtd: MTD device structure
919 * @mode: Read/Write mode
920 */
921static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
922{
923 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
924 mtd);
925 struct nand_chip *chip = mtd->priv;
926 unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
Vimal Singh67ce04b2009-05-12 13:47:03 -0700927
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000928 gpmc_enable_hwecc(info->gpmc_cs, mode, dev_width, info->nand.ecc.size);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700929}
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000930
Vimal Singh67ce04b2009-05-12 13:47:03 -0700931/**
932 * omap_wait - wait until the command is done
933 * @mtd: MTD device structure
934 * @chip: NAND Chip structure
935 *
936 * Wait function is called during Program and erase operations and
937 * the way it is called from MTD layer, we should wait till the NAND
938 * chip is ready after the programming/erase operation has completed.
939 *
940 * Erase can take up to 400ms and program up to 20ms according to
941 * general NAND and SmartMedia specs
942 */
943static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
944{
945 struct nand_chip *this = mtd->priv;
946 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
947 mtd);
948 unsigned long timeo = jiffies;
Ivan Djelica9c465f2012-04-17 13:11:53 +0200949 int status, state = this->state;
Vimal Singh67ce04b2009-05-12 13:47:03 -0700950
951 if (state == FL_ERASING)
952 timeo += (HZ * 400) / 1000;
953 else
954 timeo += (HZ * 20) / 1000;
955
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000956 gpmc_nand_write(info->gpmc_cs,
957 GPMC_NAND_COMMAND, (NAND_CMD_STATUS & 0xFF));
Vimal Singh67ce04b2009-05-12 13:47:03 -0700958 while (time_before(jiffies, timeo)) {
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000959 status = gpmc_nand_read(info->gpmc_cs, GPMC_NAND_DATA);
vimal singhc276aca2009-06-27 11:07:06 +0530960 if (status & NAND_STATUS_READY)
Vimal Singh67ce04b2009-05-12 13:47:03 -0700961 break;
vimal singhc276aca2009-06-27 11:07:06 +0530962 cond_resched();
Vimal Singh67ce04b2009-05-12 13:47:03 -0700963 }
Ivan Djelica9c465f2012-04-17 13:11:53 +0200964
965 status = gpmc_nand_read(info->gpmc_cs, GPMC_NAND_DATA);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700966 return status;
967}
968
969/**
970 * omap_dev_ready - calls the platform specific dev_ready function
971 * @mtd: MTD device structure
972 */
973static int omap_dev_ready(struct mtd_info *mtd)
974{
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000975 unsigned int val = 0;
Vimal Singh67ce04b2009-05-12 13:47:03 -0700976 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
977 mtd);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700978
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000979 val = gpmc_read_status(GPMC_GET_IRQ_STATUS);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700980 if ((val & 0x100) == 0x100) {
981 /* Clear IRQ Interrupt */
982 val |= 0x100;
983 val &= ~(0x0);
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000984 gpmc_cs_configure(info->gpmc_cs, GPMC_SET_IRQ_STATUS, val);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700985 } else {
986 unsigned int cnt = 0;
987 while (cnt++ < 0x1FF) {
988 if ((val & 0x100) == 0x100)
989 return 0;
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +0000990 val = gpmc_read_status(GPMC_GET_IRQ_STATUS);
Vimal Singh67ce04b2009-05-12 13:47:03 -0700991 }
992 }
993
994 return 1;
995}
996
Ivan Djelic0e618ef2012-04-30 12:17:18 +0200997#ifdef CONFIG_MTD_NAND_OMAP_BCH
998
999/**
1000 * omap3_enable_hwecc_bch - Program OMAP3 GPMC to perform BCH ECC correction
1001 * @mtd: MTD device structure
1002 * @mode: Read/Write mode
1003 */
1004static void omap3_enable_hwecc_bch(struct mtd_info *mtd, int mode)
1005{
1006 int nerrors;
1007 unsigned int dev_width;
1008 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1009 mtd);
1010 struct nand_chip *chip = mtd->priv;
1011
1012 nerrors = (info->nand.ecc.bytes == 13) ? 8 : 4;
1013 dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
1014 /*
1015 * Program GPMC to perform correction on one 512-byte sector at a time.
1016 * Using 4 sectors at a time (i.e. ecc.size = 2048) is also possible and
1017 * gives a slight (5%) performance gain (but requires additional code).
1018 */
1019 (void)gpmc_enable_hwecc_bch(info->gpmc_cs, mode, dev_width, 1, nerrors);
1020}
1021
1022/**
1023 * omap3_calculate_ecc_bch4 - Generate 7 bytes of ECC bytes
1024 * @mtd: MTD device structure
1025 * @dat: The pointer to data on which ecc is computed
1026 * @ecc_code: The ecc_code buffer
1027 */
1028static int omap3_calculate_ecc_bch4(struct mtd_info *mtd, const u_char *dat,
1029 u_char *ecc_code)
1030{
1031 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1032 mtd);
1033 return gpmc_calculate_ecc_bch4(info->gpmc_cs, dat, ecc_code);
1034}
1035
1036/**
1037 * omap3_calculate_ecc_bch8 - Generate 13 bytes of ECC bytes
1038 * @mtd: MTD device structure
1039 * @dat: The pointer to data on which ecc is computed
1040 * @ecc_code: The ecc_code buffer
1041 */
1042static int omap3_calculate_ecc_bch8(struct mtd_info *mtd, const u_char *dat,
1043 u_char *ecc_code)
1044{
1045 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1046 mtd);
1047 return gpmc_calculate_ecc_bch8(info->gpmc_cs, dat, ecc_code);
1048}
1049
1050/**
1051 * omap3_correct_data_bch - Decode received data and correct errors
1052 * @mtd: MTD device structure
1053 * @data: page data
1054 * @read_ecc: ecc read from nand flash
1055 * @calc_ecc: ecc read from HW ECC registers
1056 */
1057static int omap3_correct_data_bch(struct mtd_info *mtd, u_char *data,
1058 u_char *read_ecc, u_char *calc_ecc)
1059{
1060 int i, count;
1061 /* cannot correct more than 8 errors */
1062 unsigned int errloc[8];
1063 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1064 mtd);
1065
1066 count = decode_bch(info->bch, NULL, 512, read_ecc, calc_ecc, NULL,
1067 errloc);
1068 if (count > 0) {
1069 /* correct errors */
1070 for (i = 0; i < count; i++) {
1071 /* correct data only, not ecc bytes */
1072 if (errloc[i] < 8*512)
1073 data[errloc[i]/8] ^= 1 << (errloc[i] & 7);
1074 pr_debug("corrected bitflip %u\n", errloc[i]);
1075 }
1076 } else if (count < 0) {
1077 pr_err("ecc unrecoverable error\n");
1078 }
1079 return count;
1080}
1081
1082/**
1083 * omap3_free_bch - Release BCH ecc resources
1084 * @mtd: MTD device structure
1085 */
1086static void omap3_free_bch(struct mtd_info *mtd)
1087{
1088 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1089 mtd);
1090 if (info->bch) {
1091 free_bch(info->bch);
1092 info->bch = NULL;
1093 }
1094}
1095
1096/**
1097 * omap3_init_bch - Initialize BCH ECC
1098 * @mtd: MTD device structure
1099 * @ecc_opt: OMAP ECC mode (OMAP_ECC_BCH4_CODE_HW or OMAP_ECC_BCH8_CODE_HW)
1100 */
1101static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt)
1102{
1103 int ret, max_errors;
1104 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1105 mtd);
1106#ifdef CONFIG_MTD_NAND_OMAP_BCH8
1107 const int hw_errors = 8;
1108#else
1109 const int hw_errors = 4;
1110#endif
1111 info->bch = NULL;
1112
1113 max_errors = (ecc_opt == OMAP_ECC_BCH8_CODE_HW) ? 8 : 4;
1114 if (max_errors != hw_errors) {
1115 pr_err("cannot configure %d-bit BCH ecc, only %d-bit supported",
1116 max_errors, hw_errors);
1117 goto fail;
1118 }
1119
1120 /* initialize GPMC BCH engine */
1121 ret = gpmc_init_hwecc_bch(info->gpmc_cs, 1, max_errors);
1122 if (ret)
1123 goto fail;
1124
1125 /* software bch library is only used to detect and locate errors */
1126 info->bch = init_bch(13, max_errors, 0x201b /* hw polynomial */);
1127 if (!info->bch)
1128 goto fail;
1129
1130 info->nand.ecc.size = 512;
1131 info->nand.ecc.hwctl = omap3_enable_hwecc_bch;
1132 info->nand.ecc.correct = omap3_correct_data_bch;
1133 info->nand.ecc.mode = NAND_ECC_HW;
1134
1135 /*
1136 * The number of corrected errors in an ecc block that will trigger
1137 * block scrubbing defaults to the ecc strength (4 or 8).
1138 * Set mtd->bitflip_threshold here to define a custom threshold.
1139 */
1140
1141 if (max_errors == 8) {
1142 info->nand.ecc.strength = 8;
1143 info->nand.ecc.bytes = 13;
1144 info->nand.ecc.calculate = omap3_calculate_ecc_bch8;
1145 } else {
1146 info->nand.ecc.strength = 4;
1147 info->nand.ecc.bytes = 7;
1148 info->nand.ecc.calculate = omap3_calculate_ecc_bch4;
1149 }
1150
1151 pr_info("enabling NAND BCH ecc with %d-bit correction\n", max_errors);
1152 return 0;
1153fail:
1154 omap3_free_bch(mtd);
1155 return -1;
1156}
1157
1158/**
1159 * omap3_init_bch_tail - Build an oob layout for BCH ECC correction.
1160 * @mtd: MTD device structure
1161 */
1162static int omap3_init_bch_tail(struct mtd_info *mtd)
1163{
1164 int i, steps;
1165 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1166 mtd);
1167 struct nand_ecclayout *layout = &info->ecclayout;
1168
1169 /* build oob layout */
1170 steps = mtd->writesize/info->nand.ecc.size;
1171 layout->eccbytes = steps*info->nand.ecc.bytes;
1172
1173 /* do not bother creating special oob layouts for small page devices */
1174 if (mtd->oobsize < 64) {
1175 pr_err("BCH ecc is not supported on small page devices\n");
1176 goto fail;
1177 }
1178
1179 /* reserve 2 bytes for bad block marker */
1180 if (layout->eccbytes+2 > mtd->oobsize) {
1181 pr_err("no oob layout available for oobsize %d eccbytes %u\n",
1182 mtd->oobsize, layout->eccbytes);
1183 goto fail;
1184 }
1185
1186 /* put ecc bytes at oob tail */
1187 for (i = 0; i < layout->eccbytes; i++)
1188 layout->eccpos[i] = mtd->oobsize-layout->eccbytes+i;
1189
1190 layout->oobfree[0].offset = 2;
1191 layout->oobfree[0].length = mtd->oobsize-2-layout->eccbytes;
1192 info->nand.ecc.layout = layout;
1193
1194 if (!(info->nand.options & NAND_BUSWIDTH_16))
1195 info->nand.badblock_pattern = &bb_descrip_flashbased;
1196 return 0;
1197fail:
1198 omap3_free_bch(mtd);
1199 return -1;
1200}
1201
1202#else
1203static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt)
1204{
1205 pr_err("CONFIG_MTD_NAND_OMAP_BCH is not enabled\n");
1206 return -1;
1207}
1208static int omap3_init_bch_tail(struct mtd_info *mtd)
1209{
1210 return -1;
1211}
1212static void omap3_free_bch(struct mtd_info *mtd)
1213{
1214}
1215#endif /* CONFIG_MTD_NAND_OMAP_BCH */
1216
Vimal Singh67ce04b2009-05-12 13:47:03 -07001217static int __devinit omap_nand_probe(struct platform_device *pdev)
1218{
1219 struct omap_nand_info *info;
1220 struct omap_nand_platform_data *pdata;
1221 int err;
Sukumar Ghoraif040d332011-01-28 15:42:09 +05301222 int i, offset;
Russell King763e7352012-04-25 00:16:00 +01001223 dma_cap_mask_t mask;
1224 unsigned sig;
Vimal Singh67ce04b2009-05-12 13:47:03 -07001225
1226 pdata = pdev->dev.platform_data;
1227 if (pdata == NULL) {
1228 dev_err(&pdev->dev, "platform data missing\n");
1229 return -ENODEV;
1230 }
1231
1232 info = kzalloc(sizeof(struct omap_nand_info), GFP_KERNEL);
1233 if (!info)
1234 return -ENOMEM;
1235
1236 platform_set_drvdata(pdev, info);
1237
1238 spin_lock_init(&info->controller.lock);
1239 init_waitqueue_head(&info->controller.wq);
1240
1241 info->pdev = pdev;
1242
1243 info->gpmc_cs = pdata->cs;
Vimal Singh2f70a1e2010-02-15 10:03:33 -08001244 info->phys_base = pdata->phys_base;
Vimal Singh67ce04b2009-05-12 13:47:03 -07001245
1246 info->mtd.priv = &info->nand;
1247 info->mtd.name = dev_name(&pdev->dev);
1248 info->mtd.owner = THIS_MODULE;
1249
Sukumar Ghoraid5ce2b62011-01-28 15:42:03 +05301250 info->nand.options = pdata->devsize;
Vimal Singh2f70a1e2010-02-15 10:03:33 -08001251 info->nand.options |= NAND_SKIP_BBTSCAN;
Vimal Singh67ce04b2009-05-12 13:47:03 -07001252
1253 /* NAND write protect off */
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +00001254 gpmc_cs_configure(info->gpmc_cs, GPMC_CONFIG_WP, 0);
Vimal Singh67ce04b2009-05-12 13:47:03 -07001255
1256 if (!request_mem_region(info->phys_base, NAND_IO_SIZE,
1257 pdev->dev.driver->name)) {
1258 err = -EBUSY;
Vimal Singh2f70a1e2010-02-15 10:03:33 -08001259 goto out_free_info;
Vimal Singh67ce04b2009-05-12 13:47:03 -07001260 }
1261
1262 info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE);
1263 if (!info->nand.IO_ADDR_R) {
1264 err = -ENOMEM;
1265 goto out_release_mem_region;
1266 }
vimal singh59e9c5a2009-07-13 16:26:24 +05301267
Vimal Singh67ce04b2009-05-12 13:47:03 -07001268 info->nand.controller = &info->controller;
1269
1270 info->nand.IO_ADDR_W = info->nand.IO_ADDR_R;
1271 info->nand.cmd_ctrl = omap_hwcontrol;
1272
Vimal Singh67ce04b2009-05-12 13:47:03 -07001273 /*
1274 * If RDY/BSY line is connected to OMAP then use the omap ready
1275 * funcrtion and the generic nand_wait function which reads the status
1276 * register after monitoring the RDY/BSY line.Otherwise use a standard
1277 * chip delay which is slightly more than tR (AC Timing) of the NAND
1278 * device and read status register until you get a failure or success
1279 */
1280 if (pdata->dev_ready) {
1281 info->nand.dev_ready = omap_dev_ready;
1282 info->nand.chip_delay = 0;
1283 } else {
1284 info->nand.waitfunc = omap_wait;
1285 info->nand.chip_delay = 50;
1286 }
1287
Sukumar Ghorai1b0b323c2011-01-28 15:42:04 +05301288 switch (pdata->xfer_type) {
1289 case NAND_OMAP_PREFETCH_POLLED:
vimal singh59e9c5a2009-07-13 16:26:24 +05301290 info->nand.read_buf = omap_read_buf_pref;
1291 info->nand.write_buf = omap_write_buf_pref;
Sukumar Ghorai1b0b323c2011-01-28 15:42:04 +05301292 break;
vimal singhdfe32892009-07-13 16:29:16 +05301293
Sukumar Ghorai1b0b323c2011-01-28 15:42:04 +05301294 case NAND_OMAP_POLLED:
vimal singh59e9c5a2009-07-13 16:26:24 +05301295 if (info->nand.options & NAND_BUSWIDTH_16) {
1296 info->nand.read_buf = omap_read_buf16;
1297 info->nand.write_buf = omap_write_buf16;
1298 } else {
1299 info->nand.read_buf = omap_read_buf8;
1300 info->nand.write_buf = omap_write_buf8;
1301 }
Sukumar Ghorai1b0b323c2011-01-28 15:42:04 +05301302 break;
1303
1304 case NAND_OMAP_PREFETCH_DMA:
Russell King763e7352012-04-25 00:16:00 +01001305 dma_cap_zero(mask);
1306 dma_cap_set(DMA_SLAVE, mask);
1307 sig = OMAP24XX_DMA_GPMC;
1308 info->dma = dma_request_channel(mask, omap_dma_filter_fn, &sig);
1309 if (!info->dma) {
1310 dev_warn(&pdev->dev, "DMA engine request failed\n");
1311 } else {
1312 struct dma_slave_config cfg;
1313 int rc;
1314
1315 memset(&cfg, 0, sizeof(cfg));
1316 cfg.src_addr = info->phys_base;
1317 cfg.dst_addr = info->phys_base;
1318 cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
1319 cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
1320 cfg.src_maxburst = 16;
1321 cfg.dst_maxburst = 16;
1322 rc = dmaengine_slave_config(info->dma, &cfg);
1323 if (rc) {
1324 dev_err(&pdev->dev, "DMA engine slave config failed: %d\n",
1325 rc);
1326 goto out_release_mem_region;
1327 }
1328 info->nand.read_buf = omap_read_buf_dma_pref;
1329 info->nand.write_buf = omap_write_buf_dma_pref;
1330 break;
1331 }
Sukumar Ghorai1b0b323c2011-01-28 15:42:04 +05301332 err = omap_request_dma(OMAP24XX_DMA_GPMC, "NAND",
1333 omap_nand_dma_cb, &info->comp, &info->dma_ch);
1334 if (err < 0) {
1335 info->dma_ch = -1;
1336 dev_err(&pdev->dev, "DMA request failed!\n");
1337 goto out_release_mem_region;
1338 } else {
1339 omap_set_dma_dest_burst_mode(info->dma_ch,
1340 OMAP_DMA_DATA_BURST_16);
1341 omap_set_dma_src_burst_mode(info->dma_ch,
1342 OMAP_DMA_DATA_BURST_16);
1343
1344 info->nand.read_buf = omap_read_buf_dma_pref;
1345 info->nand.write_buf = omap_write_buf_dma_pref;
1346 }
1347 break;
1348
Sukumar Ghorai4e070372011-01-28 15:42:06 +05301349 case NAND_OMAP_PREFETCH_IRQ:
1350 err = request_irq(pdata->gpmc_irq,
1351 omap_nand_irq, IRQF_SHARED, "gpmc-nand", info);
1352 if (err) {
1353 dev_err(&pdev->dev, "requesting irq(%d) error:%d",
1354 pdata->gpmc_irq, err);
1355 goto out_release_mem_region;
1356 } else {
1357 info->gpmc_irq = pdata->gpmc_irq;
1358 info->nand.read_buf = omap_read_buf_irq_pref;
1359 info->nand.write_buf = omap_write_buf_irq_pref;
1360 }
1361 break;
1362
Sukumar Ghorai1b0b323c2011-01-28 15:42:04 +05301363 default:
1364 dev_err(&pdev->dev,
1365 "xfer_type(%d) not supported!\n", pdata->xfer_type);
1366 err = -EINVAL;
1367 goto out_release_mem_region;
vimal singh59e9c5a2009-07-13 16:26:24 +05301368 }
Sukumar Ghorai1b0b323c2011-01-28 15:42:04 +05301369
vimal singh59e9c5a2009-07-13 16:26:24 +05301370 info->nand.verify_buf = omap_verify_buf;
1371
Sukumar Ghoraif3d73f32011-01-28 15:42:08 +05301372 /* selsect the ecc type */
1373 if (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_DEFAULT)
1374 info->nand.ecc.mode = NAND_ECC_SOFT;
Sukumar Ghoraif040d332011-01-28 15:42:09 +05301375 else if ((pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW) ||
1376 (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW_ROMCODE)) {
Sukumar Ghoraif3d73f32011-01-28 15:42:08 +05301377 info->nand.ecc.bytes = 3;
1378 info->nand.ecc.size = 512;
Mike Dunn6a918ba2012-03-11 14:21:11 -07001379 info->nand.ecc.strength = 1;
Sukumar Ghoraif3d73f32011-01-28 15:42:08 +05301380 info->nand.ecc.calculate = omap_calculate_ecc;
1381 info->nand.ecc.hwctl = omap_enable_hwecc;
1382 info->nand.ecc.correct = omap_correct_data;
1383 info->nand.ecc.mode = NAND_ECC_HW;
Ivan Djelic0e618ef2012-04-30 12:17:18 +02001384 } else if ((pdata->ecc_opt == OMAP_ECC_BCH4_CODE_HW) ||
1385 (pdata->ecc_opt == OMAP_ECC_BCH8_CODE_HW)) {
1386 err = omap3_init_bch(&info->mtd, pdata->ecc_opt);
1387 if (err) {
1388 err = -EINVAL;
1389 goto out_release_mem_region;
1390 }
Sukumar Ghoraif3d73f32011-01-28 15:42:08 +05301391 }
Vimal Singh67ce04b2009-05-12 13:47:03 -07001392
1393 /* DIP switches on some boards change between 8 and 16 bit
1394 * bus widths for flash. Try the other width if the first try fails.
1395 */
Jan Weitzela80f1c12011-04-19 16:15:34 +02001396 if (nand_scan_ident(&info->mtd, 1, NULL)) {
Vimal Singh67ce04b2009-05-12 13:47:03 -07001397 info->nand.options ^= NAND_BUSWIDTH_16;
Jan Weitzela80f1c12011-04-19 16:15:34 +02001398 if (nand_scan_ident(&info->mtd, 1, NULL)) {
Vimal Singh67ce04b2009-05-12 13:47:03 -07001399 err = -ENXIO;
1400 goto out_release_mem_region;
1401 }
1402 }
1403
Sukumar Ghoraif040d332011-01-28 15:42:09 +05301404 /* rom code layout */
1405 if (pdata->ecc_opt == OMAP_ECC_HAMMING_CODE_HW_ROMCODE) {
1406
1407 if (info->nand.options & NAND_BUSWIDTH_16)
1408 offset = 2;
1409 else {
1410 offset = 1;
1411 info->nand.badblock_pattern = &bb_descrip_flashbased;
1412 }
1413 omap_oobinfo.eccbytes = 3 * (info->mtd.oobsize/16);
1414 for (i = 0; i < omap_oobinfo.eccbytes; i++)
1415 omap_oobinfo.eccpos[i] = i+offset;
1416
1417 omap_oobinfo.oobfree->offset = offset + omap_oobinfo.eccbytes;
1418 omap_oobinfo.oobfree->length = info->mtd.oobsize -
1419 (offset + omap_oobinfo.eccbytes);
1420
1421 info->nand.ecc.layout = &omap_oobinfo;
Ivan Djelic0e618ef2012-04-30 12:17:18 +02001422 } else if ((pdata->ecc_opt == OMAP_ECC_BCH4_CODE_HW) ||
1423 (pdata->ecc_opt == OMAP_ECC_BCH8_CODE_HW)) {
1424 /* build OOB layout for BCH ECC correction */
1425 err = omap3_init_bch_tail(&info->mtd);
1426 if (err) {
1427 err = -EINVAL;
1428 goto out_release_mem_region;
1429 }
Sukumar Ghoraif040d332011-01-28 15:42:09 +05301430 }
Sukumar Ghorai1b0b323c2011-01-28 15:42:04 +05301431
Jan Weitzela80f1c12011-04-19 16:15:34 +02001432 /* second phase scan */
1433 if (nand_scan_tail(&info->mtd)) {
1434 err = -ENXIO;
1435 goto out_release_mem_region;
1436 }
1437
Artem Bityutskiy42d7fbe2012-03-09 19:24:26 +02001438 mtd_device_parse_register(&info->mtd, NULL, NULL, pdata->parts,
1439 pdata->nr_parts);
Vimal Singh67ce04b2009-05-12 13:47:03 -07001440
1441 platform_set_drvdata(pdev, &info->mtd);
1442
1443 return 0;
1444
1445out_release_mem_region:
Russell King763e7352012-04-25 00:16:00 +01001446 if (info->dma)
1447 dma_release_channel(info->dma);
Vimal Singh67ce04b2009-05-12 13:47:03 -07001448 release_mem_region(info->phys_base, NAND_IO_SIZE);
Vimal Singh67ce04b2009-05-12 13:47:03 -07001449out_free_info:
1450 kfree(info);
1451
1452 return err;
1453}
1454
1455static int omap_nand_remove(struct platform_device *pdev)
1456{
1457 struct mtd_info *mtd = platform_get_drvdata(pdev);
Vimal Singhf35b6ed2010-01-05 16:01:08 +05301458 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1459 mtd);
Ivan Djelic0e618ef2012-04-30 12:17:18 +02001460 omap3_free_bch(&info->mtd);
Vimal Singh67ce04b2009-05-12 13:47:03 -07001461
1462 platform_set_drvdata(pdev, NULL);
Sukumar Ghorai1b0b323c2011-01-28 15:42:04 +05301463 if (info->dma_ch != -1)
vimal singhdfe32892009-07-13 16:29:16 +05301464 omap_free_dma(info->dma_ch);
1465
Russell King763e7352012-04-25 00:16:00 +01001466 if (info->dma)
1467 dma_release_channel(info->dma);
1468
Sukumar Ghorai4e070372011-01-28 15:42:06 +05301469 if (info->gpmc_irq)
1470 free_irq(info->gpmc_irq, info);
1471
Vimal Singh67ce04b2009-05-12 13:47:03 -07001472 /* Release NAND device, its internal structures and partitions */
1473 nand_release(&info->mtd);
Sukumar Ghorai2c01946c2010-07-09 09:14:45 +00001474 iounmap(info->nand.IO_ADDR_R);
Vimal Singh67ce04b2009-05-12 13:47:03 -07001475 kfree(&info->mtd);
1476 return 0;
1477}
1478
1479static struct platform_driver omap_nand_driver = {
1480 .probe = omap_nand_probe,
1481 .remove = omap_nand_remove,
1482 .driver = {
1483 .name = DRIVER_NAME,
1484 .owner = THIS_MODULE,
1485 },
1486};
1487
Axel Linf99640d2011-11-27 20:45:03 +08001488module_platform_driver(omap_nand_driver);
Vimal Singh67ce04b2009-05-12 13:47:03 -07001489
Axel Linc804c732011-03-07 11:04:24 +08001490MODULE_ALIAS("platform:" DRIVER_NAME);
Vimal Singh67ce04b2009-05-12 13:47:03 -07001491MODULE_LICENSE("GPL");
1492MODULE_DESCRIPTION("Glue layer for NAND flash on TI OMAP boards");