2 * Copyright © 2004 Texas Instruments, Jian Zhang <jzhang@ti.com>
3 * Copyright © 2004 Micron Technology Inc.
4 * Copyright © 2004 David Brownell
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.
11 #include <linux/platform_device.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/delay.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/nand.h>
16 #include <linux/mtd/partitions.h>
21 #include <mach/gpmc.h>
22 #include <mach/nand.h>
24 #define GPMC_IRQ_STATUS 0x18
25 #define GPMC_ECC_CONFIG 0x1F4
26 #define GPMC_ECC_CONTROL 0x1F8
27 #define GPMC_ECC_SIZE_CONFIG 0x1FC
28 #define GPMC_ECC1_RESULT 0x200
30 #define DRIVER_NAME "omap2-nand"
32 /* size (4 KiB) for IO mapping */
33 #define NAND_IO_SIZE SZ_4K
36 #define NAND_WP_BIT 0x00000010
37 #define WR_RD_PIN_MONITORING 0x00600000
39 #define GPMC_BUF_FULL 0x00000001
40 #define GPMC_BUF_EMPTY 0x00000000
42 #define NAND_Ecc_P1e (1 << 0)
43 #define NAND_Ecc_P2e (1 << 1)
44 #define NAND_Ecc_P4e (1 << 2)
45 #define NAND_Ecc_P8e (1 << 3)
46 #define NAND_Ecc_P16e (1 << 4)
47 #define NAND_Ecc_P32e (1 << 5)
48 #define NAND_Ecc_P64e (1 << 6)
49 #define NAND_Ecc_P128e (1 << 7)
50 #define NAND_Ecc_P256e (1 << 8)
51 #define NAND_Ecc_P512e (1 << 9)
52 #define NAND_Ecc_P1024e (1 << 10)
53 #define NAND_Ecc_P2048e (1 << 11)
55 #define NAND_Ecc_P1o (1 << 16)
56 #define NAND_Ecc_P2o (1 << 17)
57 #define NAND_Ecc_P4o (1 << 18)
58 #define NAND_Ecc_P8o (1 << 19)
59 #define NAND_Ecc_P16o (1 << 20)
60 #define NAND_Ecc_P32o (1 << 21)
61 #define NAND_Ecc_P64o (1 << 22)
62 #define NAND_Ecc_P128o (1 << 23)
63 #define NAND_Ecc_P256o (1 << 24)
64 #define NAND_Ecc_P512o (1 << 25)
65 #define NAND_Ecc_P1024o (1 << 26)
66 #define NAND_Ecc_P2048o (1 << 27)
68 #define TF(value) (value ? 1 : 0)
70 #define P2048e(a) (TF(a & NAND_Ecc_P2048e) << 0)
71 #define P2048o(a) (TF(a & NAND_Ecc_P2048o) << 1)
72 #define P1e(a) (TF(a & NAND_Ecc_P1e) << 2)
73 #define P1o(a) (TF(a & NAND_Ecc_P1o) << 3)
74 #define P2e(a) (TF(a & NAND_Ecc_P2e) << 4)
75 #define P2o(a) (TF(a & NAND_Ecc_P2o) << 5)
76 #define P4e(a) (TF(a & NAND_Ecc_P4e) << 6)
77 #define P4o(a) (TF(a & NAND_Ecc_P4o) << 7)
79 #define P8e(a) (TF(a & NAND_Ecc_P8e) << 0)
80 #define P8o(a) (TF(a & NAND_Ecc_P8o) << 1)
81 #define P16e(a) (TF(a & NAND_Ecc_P16e) << 2)
82 #define P16o(a) (TF(a & NAND_Ecc_P16o) << 3)
83 #define P32e(a) (TF(a & NAND_Ecc_P32e) << 4)
84 #define P32o(a) (TF(a & NAND_Ecc_P32o) << 5)
85 #define P64e(a) (TF(a & NAND_Ecc_P64e) << 6)
86 #define P64o(a) (TF(a & NAND_Ecc_P64o) << 7)
88 #define P128e(a) (TF(a & NAND_Ecc_P128e) << 0)
89 #define P128o(a) (TF(a & NAND_Ecc_P128o) << 1)
90 #define P256e(a) (TF(a & NAND_Ecc_P256e) << 2)
91 #define P256o(a) (TF(a & NAND_Ecc_P256o) << 3)
92 #define P512e(a) (TF(a & NAND_Ecc_P512e) << 4)
93 #define P512o(a) (TF(a & NAND_Ecc_P512o) << 5)
94 #define P1024e(a) (TF(a & NAND_Ecc_P1024e) << 6)
95 #define P1024o(a) (TF(a & NAND_Ecc_P1024o) << 7)
97 #define P8e_s(a) (TF(a & NAND_Ecc_P8e) << 0)
98 #define P8o_s(a) (TF(a & NAND_Ecc_P8o) << 1)
99 #define P16e_s(a) (TF(a & NAND_Ecc_P16e) << 2)
100 #define P16o_s(a) (TF(a & NAND_Ecc_P16o) << 3)
101 #define P1e_s(a) (TF(a & NAND_Ecc_P1e) << 4)
102 #define P1o_s(a) (TF(a & NAND_Ecc_P1o) << 5)
103 #define P2e_s(a) (TF(a & NAND_Ecc_P2e) << 6)
104 #define P2o_s(a) (TF(a & NAND_Ecc_P2o) << 7)
106 #define P4e_s(a) (TF(a & NAND_Ecc_P4e) << 0)
107 #define P4o_s(a) (TF(a & NAND_Ecc_P4o) << 1)
109 #ifdef CONFIG_MTD_PARTITIONS
110 static const char *part_probes[] = { "cmdlinepart", NULL };
113 struct omap_nand_info {
114 struct nand_hw_control controller;
115 struct omap_nand_platform_data *pdata;
117 struct mtd_partition *parts;
118 struct nand_chip nand;
119 struct platform_device *pdev;
122 unsigned long phys_base;
123 void __iomem *gpmc_cs_baseaddr;
124 void __iomem *gpmc_baseaddr;
128 * omap_nand_wp - This function enable or disable the Write Protect feature
129 * @mtd: MTD device structure
132 static void omap_nand_wp(struct mtd_info *mtd, int mode)
134 struct omap_nand_info *info = container_of(mtd,
135 struct omap_nand_info, mtd);
137 unsigned long config = __raw_readl(info->gpmc_baseaddr + GPMC_CONFIG);
140 config &= ~(NAND_WP_BIT); /* WP is ON */
142 config |= (NAND_WP_BIT); /* WP is OFF */
144 __raw_writel(config, (info->gpmc_baseaddr + GPMC_CONFIG));
148 * omap_hwcontrol - hardware specific access to control-lines
149 * @mtd: MTD device structure
150 * @cmd: command to device
152 * NAND_NCE: bit 0 -> don't care
153 * NAND_CLE: bit 1 -> Command Latch
154 * NAND_ALE: bit 2 -> Address Latch
156 * NOTE: boards may use different bits for these!!
158 static void omap_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
160 struct omap_nand_info *info = container_of(mtd,
161 struct omap_nand_info, mtd);
163 case NAND_CTRL_CHANGE | NAND_CTRL_CLE:
164 info->nand.IO_ADDR_W = info->gpmc_cs_baseaddr +
165 GPMC_CS_NAND_COMMAND;
166 info->nand.IO_ADDR_R = info->gpmc_cs_baseaddr +
170 case NAND_CTRL_CHANGE | NAND_CTRL_ALE:
171 info->nand.IO_ADDR_W = info->gpmc_cs_baseaddr +
172 GPMC_CS_NAND_ADDRESS;
173 info->nand.IO_ADDR_R = info->gpmc_cs_baseaddr +
177 case NAND_CTRL_CHANGE | NAND_NCE:
178 info->nand.IO_ADDR_W = info->gpmc_cs_baseaddr +
180 info->nand.IO_ADDR_R = info->gpmc_cs_baseaddr +
185 if (cmd != NAND_CMD_NONE)
186 __raw_writeb(cmd, info->nand.IO_ADDR_W);
190 * omap_read_buf16 - read data from NAND controller into buffer
191 * @mtd: MTD device structure
192 * @buf: buffer to store date
193 * @len: number of bytes to read
195 static void omap_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
197 struct nand_chip *nand = mtd->priv;
199 __raw_readsw(nand->IO_ADDR_R, buf, len / 2);
203 * omap_write_buf16 - write buffer to NAND controller
204 * @mtd: MTD device structure
206 * @len: number of bytes to write
208 static void omap_write_buf16(struct mtd_info *mtd, const u_char * buf, int len)
210 struct omap_nand_info *info = container_of(mtd,
211 struct omap_nand_info, mtd);
212 u16 *p = (u16 *) buf;
214 /* FIXME try bursts of writesw() or DMA ... */
218 writew(*p++, info->nand.IO_ADDR_W);
220 while (GPMC_BUF_EMPTY == (readl(info->gpmc_baseaddr +
221 GPMC_STATUS) & GPMC_BUF_FULL))
226 * omap_verify_buf - Verify chip data against buffer
227 * @mtd: MTD device structure
228 * @buf: buffer containing the data to compare
229 * @len: number of bytes to compare
231 static int omap_verify_buf(struct mtd_info *mtd, const u_char * buf, int len)
233 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
235 u16 *p = (u16 *) buf;
239 if (*p++ != cpu_to_le16(readw(info->nand.IO_ADDR_R)))
246 #ifdef CONFIG_MTD_NAND_OMAP_HWECC
248 * omap_hwecc_init - Initialize the HW ECC for NAND flash in GPMC controller
249 * @mtd: MTD device structure
251 static void omap_hwecc_init(struct mtd_info *mtd)
253 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
255 struct nand_chip *chip = mtd->priv;
256 unsigned long val = 0x0;
258 /* Read from ECC Control Register */
259 val = __raw_readl(info->gpmc_baseaddr + GPMC_ECC_CONTROL);
260 /* Clear all ECC | Enable Reg1 */
261 val = ((0x00000001<<8) | 0x00000001);
262 __raw_writel(val, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
264 /* Read from ECC Size Config Register */
265 val = __raw_readl(info->gpmc_baseaddr + GPMC_ECC_SIZE_CONFIG);
266 /* ECCSIZE1=512 | Select eccResultsize[0-3] */
267 val = ((((chip->ecc.size >> 1) - 1) << 22) | (0x0000000F));
268 __raw_writel(val, info->gpmc_baseaddr + GPMC_ECC_SIZE_CONFIG);
272 * gen_true_ecc - This function will generate true ECC value
273 * @ecc_buf: buffer to store ecc code
275 * This generated true ECC value can be used when correcting
276 * data read from NAND flash memory core
278 static void gen_true_ecc(u8 *ecc_buf)
280 u32 tmp = ecc_buf[0] | (ecc_buf[1] << 16) |
281 ((ecc_buf[2] & 0xF0) << 20) | ((ecc_buf[2] & 0x0F) << 8);
283 ecc_buf[0] = ~(P64o(tmp) | P64e(tmp) | P32o(tmp) | P32e(tmp) |
284 P16o(tmp) | P16e(tmp) | P8o(tmp) | P8e(tmp));
285 ecc_buf[1] = ~(P1024o(tmp) | P1024e(tmp) | P512o(tmp) | P512e(tmp) |
286 P256o(tmp) | P256e(tmp) | P128o(tmp) | P128e(tmp));
287 ecc_buf[2] = ~(P4o(tmp) | P4e(tmp) | P2o(tmp) | P2e(tmp) | P1o(tmp) |
288 P1e(tmp) | P2048o(tmp) | P2048e(tmp));
292 * omap_compare_ecc - Detect (2 bits) and correct (1 bit) error in data
293 * @ecc_data1: ecc code from nand spare area
294 * @ecc_data2: ecc code from hardware register obtained from hardware ecc
295 * @page_data: page data
297 * This function compares two ECC's and indicates if there is an error.
298 * If the error can be corrected it will be corrected to the buffer.
300 static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
301 u8 *ecc_data2, /* read from register */
305 u8 tmp0_bit[8], tmp1_bit[8], tmp2_bit[8];
306 u8 comp0_bit[8], comp1_bit[8], comp2_bit[8];
313 isEccFF = ((*(u32 *)ecc_data1 & 0xFFFFFF) == 0xFFFFFF);
315 gen_true_ecc(ecc_data1);
316 gen_true_ecc(ecc_data2);
318 for (i = 0; i <= 2; i++) {
319 *(ecc_data1 + i) = ~(*(ecc_data1 + i));
320 *(ecc_data2 + i) = ~(*(ecc_data2 + i));
323 for (i = 0; i < 8; i++) {
324 tmp0_bit[i] = *ecc_data1 % 2;
325 *ecc_data1 = *ecc_data1 / 2;
328 for (i = 0; i < 8; i++) {
329 tmp1_bit[i] = *(ecc_data1 + 1) % 2;
330 *(ecc_data1 + 1) = *(ecc_data1 + 1) / 2;
333 for (i = 0; i < 8; i++) {
334 tmp2_bit[i] = *(ecc_data1 + 2) % 2;
335 *(ecc_data1 + 2) = *(ecc_data1 + 2) / 2;
338 for (i = 0; i < 8; i++) {
339 comp0_bit[i] = *ecc_data2 % 2;
340 *ecc_data2 = *ecc_data2 / 2;
343 for (i = 0; i < 8; i++) {
344 comp1_bit[i] = *(ecc_data2 + 1) % 2;
345 *(ecc_data2 + 1) = *(ecc_data2 + 1) / 2;
348 for (i = 0; i < 8; i++) {
349 comp2_bit[i] = *(ecc_data2 + 2) % 2;
350 *(ecc_data2 + 2) = *(ecc_data2 + 2) / 2;
353 for (i = 0; i < 6; i++)
354 ecc_bit[i] = tmp2_bit[i + 2] ^ comp2_bit[i + 2];
356 for (i = 0; i < 8; i++)
357 ecc_bit[i + 6] = tmp0_bit[i] ^ comp0_bit[i];
359 for (i = 0; i < 8; i++)
360 ecc_bit[i + 14] = tmp1_bit[i] ^ comp1_bit[i];
362 ecc_bit[22] = tmp2_bit[0] ^ comp2_bit[0];
363 ecc_bit[23] = tmp2_bit[1] ^ comp2_bit[1];
365 for (i = 0; i < 24; i++)
366 ecc_sum += ecc_bit[i];
370 /* Not reached because this function is not called if
371 * ECC values are equal
376 /* Uncorrectable error */
377 DEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR 1\n");
381 /* UN-Correctable error */
382 DEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR B\n");
386 /* Correctable error */
387 find_byte = (ecc_bit[23] << 8) +
397 find_bit = (ecc_bit[5] << 2) + (ecc_bit[3] << 1) + ecc_bit[1];
399 DEBUG(MTD_DEBUG_LEVEL0, "Correcting single bit ECC error at "
400 "offset: %d, bit: %d\n", find_byte, find_bit);
402 page_data[find_byte] ^= (1 << find_bit);
407 if (ecc_data2[0] == 0 &&
412 DEBUG(MTD_DEBUG_LEVEL0, "UNCORRECTED_ERROR default\n");
418 * omap_correct_data - Compares the ECC read with HW generated ECC
419 * @mtd: MTD device structure
421 * @read_ecc: ecc read from nand flash
422 * @calc_ecc: ecc read from HW ECC registers
424 * Compares the ecc read from nand spare area with ECC registers values
425 * and if ECC's mismached, it will call 'omap_compare_ecc' for error detection
428 static int omap_correct_data(struct mtd_info *mtd, u_char *dat,
429 u_char *read_ecc, u_char *calc_ecc)
431 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
433 int blockCnt = 0, i = 0, ret = 0;
435 /* Ex NAND_ECC_HW12_2048 */
436 if ((info->nand.ecc.mode == NAND_ECC_HW) &&
437 (info->nand.ecc.size == 2048))
442 for (i = 0; i < blockCnt; i++) {
443 if (memcmp(read_ecc, calc_ecc, 3) != 0) {
444 ret = omap_compare_ecc(read_ecc, calc_ecc, dat);
456 * omap_calcuate_ecc - Generate non-inverted ECC bytes.
457 * @mtd: MTD device structure
458 * @dat: The pointer to data on which ecc is computed
459 * @ecc_code: The ecc_code buffer
461 * Using noninverted ECC can be considered ugly since writing a blank
462 * page ie. padding will clear the ECC bytes. This is no problem as long
463 * nobody is trying to write data on the seemingly unused page. Reading
464 * an erased page will produce an ECC mismatch between generated and read
465 * ECC bytes that has to be dealt with separately.
467 static int omap_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
470 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
472 unsigned long val = 0x0;
475 /* Start Reading from HW ECC1_Result = 0x200 */
476 reg = (unsigned long)(info->gpmc_baseaddr + GPMC_ECC1_RESULT);
477 val = __raw_readl(reg);
478 *ecc_code++ = val; /* P128e, ..., P1e */
479 *ecc_code++ = val >> 16; /* P128o, ..., P1o */
480 /* P2048o, P1024o, P512o, P256o, P2048e, P1024e, P512e, P256e */
481 *ecc_code++ = ((val >> 8) & 0x0f) | ((val >> 20) & 0xf0);
488 * omap_enable_hwecc - This function enables the hardware ecc functionality
489 * @mtd: MTD device structure
490 * @mode: Read/Write mode
492 static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
494 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
496 struct nand_chip *chip = mtd->priv;
497 unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
498 unsigned long val = __raw_readl(info->gpmc_baseaddr + GPMC_ECC_CONFIG);
502 __raw_writel(0x101, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
503 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */
504 val = (dev_width << 7) | (info->gpmc_cs << 1) | (0x1);
506 case NAND_ECC_READSYN:
507 __raw_writel(0x100, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
508 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */
509 val = (dev_width << 7) | (info->gpmc_cs << 1) | (0x1);
512 __raw_writel(0x101, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
513 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */
514 val = (dev_width << 7) | (info->gpmc_cs << 1) | (0x1);
517 DEBUG(MTD_DEBUG_LEVEL0, "Error: Unrecognized Mode[%d]!\n",
522 __raw_writel(val, info->gpmc_baseaddr + GPMC_ECC_CONFIG);
527 * omap_wait - wait until the command is done
528 * @mtd: MTD device structure
529 * @chip: NAND Chip structure
531 * Wait function is called during Program and erase operations and
532 * the way it is called from MTD layer, we should wait till the NAND
533 * chip is ready after the programming/erase operation has completed.
535 * Erase can take up to 400ms and program up to 20ms according to
536 * general NAND and SmartMedia specs
538 static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
540 struct nand_chip *this = mtd->priv;
541 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
543 unsigned long timeo = jiffies;
544 int status, state = this->state;
546 if (state == FL_ERASING)
547 timeo += (HZ * 400) / 1000;
549 timeo += (HZ * 20) / 1000;
551 this->IO_ADDR_W = (void *) info->gpmc_cs_baseaddr +
552 GPMC_CS_NAND_COMMAND;
553 this->IO_ADDR_R = (void *) info->gpmc_cs_baseaddr + GPMC_CS_NAND_DATA;
555 __raw_writeb(NAND_CMD_STATUS & 0xFF, this->IO_ADDR_W);
557 while (time_before(jiffies, timeo)) {
558 status = __raw_readb(this->IO_ADDR_R);
559 if (!(status & 0x40))
566 * omap_dev_ready - calls the platform specific dev_ready function
567 * @mtd: MTD device structure
569 static int omap_dev_ready(struct mtd_info *mtd)
571 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
573 unsigned int val = __raw_readl(info->gpmc_baseaddr + GPMC_IRQ_STATUS);
575 if ((val & 0x100) == 0x100) {
576 /* Clear IRQ Interrupt */
579 __raw_writel(val, info->gpmc_baseaddr + GPMC_IRQ_STATUS);
581 unsigned int cnt = 0;
582 while (cnt++ < 0x1FF) {
583 if ((val & 0x100) == 0x100)
585 val = __raw_readl(info->gpmc_baseaddr +
593 static int __devinit omap_nand_probe(struct platform_device *pdev)
595 struct omap_nand_info *info;
596 struct omap_nand_platform_data *pdata;
601 pdata = pdev->dev.platform_data;
603 dev_err(&pdev->dev, "platform data missing\n");
607 info = kzalloc(sizeof(struct omap_nand_info), GFP_KERNEL);
611 platform_set_drvdata(pdev, info);
613 spin_lock_init(&info->controller.lock);
614 init_waitqueue_head(&info->controller.wq);
618 info->gpmc_cs = pdata->cs;
619 info->gpmc_baseaddr = pdata->gpmc_baseaddr;
620 info->gpmc_cs_baseaddr = pdata->gpmc_cs_baseaddr;
622 info->mtd.priv = &info->nand;
623 info->mtd.name = dev_name(&pdev->dev);
624 info->mtd.owner = THIS_MODULE;
626 err = gpmc_cs_request(info->gpmc_cs, NAND_IO_SIZE, &info->phys_base);
628 dev_err(&pdev->dev, "Cannot request GPMC CS\n");
632 /* Enable RD PIN Monitoring Reg */
633 if (pdata->dev_ready) {
634 val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1);
635 val |= WR_RD_PIN_MONITORING;
636 gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG1, val);
639 val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG7);
641 val |= (0xc & 0xf) << 8;
642 gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG7, val);
644 /* NAND write protect off */
645 omap_nand_wp(&info->mtd, NAND_WP_OFF);
647 if (!request_mem_region(info->phys_base, NAND_IO_SIZE,
648 pdev->dev.driver->name)) {
653 info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE);
654 if (!info->nand.IO_ADDR_R) {
656 goto out_release_mem_region;
658 info->nand.controller = &info->controller;
660 info->nand.IO_ADDR_W = info->nand.IO_ADDR_R;
661 info->nand.cmd_ctrl = omap_hwcontrol;
663 /* REVISIT: only supports 16-bit NAND flash */
665 info->nand.read_buf = omap_read_buf16;
666 info->nand.write_buf = omap_write_buf16;
667 info->nand.verify_buf = omap_verify_buf;
670 * If RDY/BSY line is connected to OMAP then use the omap ready
671 * funcrtion and the generic nand_wait function which reads the status
672 * register after monitoring the RDY/BSY line.Otherwise use a standard
673 * chip delay which is slightly more than tR (AC Timing) of the NAND
674 * device and read status register until you get a failure or success
676 if (pdata->dev_ready) {
677 info->nand.dev_ready = omap_dev_ready;
678 info->nand.chip_delay = 0;
680 info->nand.waitfunc = omap_wait;
681 info->nand.chip_delay = 50;
684 info->nand.options |= NAND_SKIP_BBTSCAN;
685 if ((gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1) & 0x3000)
687 info->nand.options |= NAND_BUSWIDTH_16;
689 #ifdef CONFIG_MTD_NAND_OMAP_HWECC
690 info->nand.ecc.bytes = 3;
691 info->nand.ecc.size = 512;
692 info->nand.ecc.calculate = omap_calculate_ecc;
693 info->nand.ecc.hwctl = omap_enable_hwecc;
694 info->nand.ecc.correct = omap_correct_data;
695 info->nand.ecc.mode = NAND_ECC_HW;
698 omap_hwecc_init(&info->mtd);
700 info->nand.ecc.mode = NAND_ECC_SOFT;
703 /* DIP switches on some boards change between 8 and 16 bit
704 * bus widths for flash. Try the other width if the first try fails.
706 if (nand_scan(&info->mtd, 1)) {
707 info->nand.options ^= NAND_BUSWIDTH_16;
708 if (nand_scan(&info->mtd, 1)) {
710 goto out_release_mem_region;
714 #ifdef CONFIG_MTD_PARTITIONS
715 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
717 add_mtd_partitions(&info->mtd, info->parts, err);
718 else if (pdata->parts)
719 add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts);
722 add_mtd_device(&info->mtd);
724 platform_set_drvdata(pdev, &info->mtd);
728 out_release_mem_region:
729 release_mem_region(info->phys_base, NAND_IO_SIZE);
731 gpmc_cs_free(info->gpmc_cs);
738 static int omap_nand_remove(struct platform_device *pdev)
740 struct mtd_info *mtd = platform_get_drvdata(pdev);
741 struct omap_nand_info *info = mtd->priv;
743 platform_set_drvdata(pdev, NULL);
744 /* Release NAND device, its internal structures and partitions */
745 nand_release(&info->mtd);
746 iounmap(info->nand.IO_ADDR_R);
751 static struct platform_driver omap_nand_driver = {
752 .probe = omap_nand_probe,
753 .remove = omap_nand_remove,
756 .owner = THIS_MODULE,
760 static int __init omap_nand_init(void)
762 printk(KERN_INFO "%s driver initializing\n", DRIVER_NAME);
763 return platform_driver_register(&omap_nand_driver);
766 static void __exit omap_nand_exit(void)
768 platform_driver_unregister(&omap_nand_driver);
771 module_init(omap_nand_init);
772 module_exit(omap_nand_exit);
774 MODULE_ALIAS(DRIVER_NAME);
775 MODULE_LICENSE("GPL");
776 MODULE_DESCRIPTION("Glue layer for NAND flash on TI OMAP boards");