2 * drivers/mtd/nand/omap2.c
4 * Copyright (c) 2004 Texas Instruments, Jian Zhang <jzhang@ti.com>
5 * Copyright (c) 2004 Micron Technology Inc.
6 * Copyright (c) 2004 David Brownell
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/platform_device.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/delay.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/nand.h>
18 #include <linux/mtd/partitions.h>
23 #include <asm/arch/gpmc.h>
24 #include <asm/arch/nand.h>
26 #define GPMC_IRQ_STATUS 0x18
27 #define GPMC_ECC_CONFIG 0x1F4
28 #define GPMC_ECC_CONTROL 0x1F8
29 #define GPMC_ECC_SIZE_CONFIG 0x1FC
30 #define GPMC_ECC1_RESULT 0x200
32 #define DRIVER_NAME "omap2-nand"
33 #define NAND_IO_SIZE SZ_4K
37 #define NAND_WP_BIT 0x00000010
38 #define WR_RD_PIN_MONITORING 0x00600000
40 #define GPMC_BUF_FULL 0x00000001
41 #define GPMC_BUF_EMPTY 0x00000000
43 #define NAND_Ecc_P1e (1 << 0)
44 #define NAND_Ecc_P2e (1 << 1)
45 #define NAND_Ecc_P4e (1 << 2)
46 #define NAND_Ecc_P8e (1 << 3)
47 #define NAND_Ecc_P16e (1 << 4)
48 #define NAND_Ecc_P32e (1 << 5)
49 #define NAND_Ecc_P64e (1 << 6)
50 #define NAND_Ecc_P128e (1 << 7)
51 #define NAND_Ecc_P256e (1 << 8)
52 #define NAND_Ecc_P512e (1 << 9)
53 #define NAND_Ecc_P1024e (1 << 10)
54 #define NAND_Ecc_P2048e (1 << 11)
56 #define NAND_Ecc_P1o (1 << 16)
57 #define NAND_Ecc_P2o (1 << 17)
58 #define NAND_Ecc_P4o (1 << 18)
59 #define NAND_Ecc_P8o (1 << 19)
60 #define NAND_Ecc_P16o (1 << 20)
61 #define NAND_Ecc_P32o (1 << 21)
62 #define NAND_Ecc_P64o (1 << 22)
63 #define NAND_Ecc_P128o (1 << 23)
64 #define NAND_Ecc_P256o (1 << 24)
65 #define NAND_Ecc_P512o (1 << 25)
66 #define NAND_Ecc_P1024o (1 << 26)
67 #define NAND_Ecc_P2048o (1 << 27)
69 #define TF(value) (value ? 1 : 0)
71 #define P2048e(a) (TF(a & NAND_Ecc_P2048e) << 0)
72 #define P2048o(a) (TF(a & NAND_Ecc_P2048o) << 1)
73 #define P1e(a) (TF(a & NAND_Ecc_P1e) << 2)
74 #define P1o(a) (TF(a & NAND_Ecc_P1o) << 3)
75 #define P2e(a) (TF(a & NAND_Ecc_P2e) << 4)
76 #define P2o(a) (TF(a & NAND_Ecc_P2o) << 5)
77 #define P4e(a) (TF(a & NAND_Ecc_P4e) << 6)
78 #define P4o(a) (TF(a & NAND_Ecc_P4o) << 7)
80 #define P8e(a) (TF(a & NAND_Ecc_P8e) << 0)
81 #define P8o(a) (TF(a & NAND_Ecc_P8o) << 1)
82 #define P16e(a) (TF(a & NAND_Ecc_P16e) << 2)
83 #define P16o(a) (TF(a & NAND_Ecc_P16o) << 3)
84 #define P32e(a) (TF(a & NAND_Ecc_P32e) << 4)
85 #define P32o(a) (TF(a & NAND_Ecc_P32o) << 5)
86 #define P64e(a) (TF(a & NAND_Ecc_P64e) << 6)
87 #define P64o(a) (TF(a & NAND_Ecc_P64o) << 7)
89 #define P128e(a) (TF(a & NAND_Ecc_P128e) << 0)
90 #define P128o(a) (TF(a & NAND_Ecc_P128o) << 1)
91 #define P256e(a) (TF(a & NAND_Ecc_P256e) << 2)
92 #define P256o(a) (TF(a & NAND_Ecc_P256o) << 3)
93 #define P512e(a) (TF(a & NAND_Ecc_P512e) << 4)
94 #define P512o(a) (TF(a & NAND_Ecc_P512o) << 5)
95 #define P1024e(a) (TF(a & NAND_Ecc_P1024e) << 6)
96 #define P1024o(a) (TF(a & NAND_Ecc_P1024o) << 7)
98 #define P8e_s(a) (TF(a & NAND_Ecc_P8e) << 0)
99 #define P8o_s(a) (TF(a & NAND_Ecc_P8o) << 1)
100 #define P16e_s(a) (TF(a & NAND_Ecc_P16e) << 2)
101 #define P16o_s(a) (TF(a & NAND_Ecc_P16o) << 3)
102 #define P1e_s(a) (TF(a & NAND_Ecc_P1e) << 4)
103 #define P1o_s(a) (TF(a & NAND_Ecc_P1o) << 5)
104 #define P2e_s(a) (TF(a & NAND_Ecc_P2e) << 6)
105 #define P2o_s(a) (TF(a & NAND_Ecc_P2o) << 7)
107 #define P4e_s(a) (TF(a & NAND_Ecc_P4e) << 0)
108 #define P4o_s(a) (TF(a & NAND_Ecc_P4o) << 1)
110 #ifdef CONFIG_MTD_PARTITIONS
111 static const char *part_probes[] = { "cmdlinepart", NULL };
114 struct omap_nand_info {
115 struct nand_hw_control controller;
116 struct omap_nand_platform_data *pdata;
118 struct mtd_partition *parts;
119 struct nand_chip nand;
120 struct platform_device *pdev;
123 unsigned long phys_base;
124 void __iomem *gpmc_cs_baseaddr;
125 void __iomem *gpmc_baseaddr;
129 * omap_nand_wp - This function enable or disable the Write Protect feature on
131 * @mtd: MTD device structure
134 static void omap_nand_wp(struct mtd_info *mtd, int mode)
136 struct omap_nand_info *info = container_of(mtd,
137 struct omap_nand_info, mtd);
139 unsigned long config = __raw_readl(info->gpmc_baseaddr + GPMC_CONFIG);
142 config &= ~(NAND_WP_BIT); /* WP is ON */
144 config |= (NAND_WP_BIT); /* WP is OFF */
146 __raw_writel(config, (info->gpmc_baseaddr + GPMC_CONFIG));
150 * hardware specific access to control-lines
151 * NOTE: boards may use different bits for these!!
154 * NAND_NCE: bit 0 - don't care
155 * NAND_CLE: bit 1 -> Command Latch
156 * NAND_ALE: bit 2 -> Address Latch
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_buf - 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_buf(struct mtd_info *mtd, u_char *buf, int len)
197 struct omap_nand_info *info = container_of(mtd,
198 struct omap_nand_info, mtd);
199 u16 *p = (u16 *) buf;
204 *p++ = cpu_to_le16(readw(info->nand.IO_ADDR_R));
208 * omap_write_buf - write buffer to NAND controller
209 * @mtd: MTD device structure
211 * @len: number of bytes to write
213 static void omap_write_buf(struct mtd_info *mtd, const u_char * buf, int len)
215 struct omap_nand_info *info = container_of(mtd,
216 struct omap_nand_info, mtd);
217 u16 *p = (u16 *) buf;
222 writew(cpu_to_le16(*p++), info->nand.IO_ADDR_W);
224 while (GPMC_BUF_EMPTY == (readl(info->gpmc_baseaddr +
225 GPMC_STATUS) & GPMC_BUF_FULL));
229 * omap_verify_buf - Verify chip data against buffer
230 * @mtd: MTD device structure
231 * @buf: buffer containing the data to compare
232 * @len: number of bytes to compare
234 static int omap_verify_buf(struct mtd_info *mtd, const u_char * buf, int len)
236 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
238 u16 *p = (u16 *) buf;
244 if (*p++ != cpu_to_le16(readw(info->nand.IO_ADDR_R)))
251 #ifdef CONFIG_MTD_NAND_OMAP_HWECC
253 * omap_hwecc_init-Initialize the Hardware ECC for NAND flash in GPMC controller
254 * @mtd: MTD device structure
256 static void omap_hwecc_init(struct mtd_info *mtd)
258 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
260 register struct nand_chip *chip = mtd->priv;
261 unsigned long val = 0x0;
263 /* Read from ECC Control Register */
264 val = __raw_readl(info->gpmc_baseaddr + GPMC_ECC_CONTROL);
265 /* Clear all ECC | Enable Reg1 */
266 val = ((0x00000001<<8) | 0x00000001);
267 __raw_writel(val, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
269 /* Read from ECC Size Config Register */
270 val = __raw_readl(info->gpmc_baseaddr + GPMC_ECC_SIZE_CONFIG);
271 /* ECCSIZE1=512 | Select eccResultsize[0-3] */
272 val = ((((chip->ecc.size >> 1) - 1) << 22) | (0x0000000F));
273 __raw_writel(val, info->gpmc_baseaddr + GPMC_ECC_SIZE_CONFIG);
277 * gen_true_ecc - This function will generate true ECC value, which can be used
278 * when correcting data read from NAND flash memory core
279 * @ecc_buf: buffer to store ecc code
281 static void gen_true_ecc(u8 *ecc_buf)
283 u32 tmp = ecc_buf[0] | (ecc_buf[1] << 16) |
284 ((ecc_buf[2] & 0xF0) << 20) | ((ecc_buf[2] & 0x0F) << 8);
286 ecc_buf[0] = ~(P64o(tmp) | P64e(tmp) | P32o(tmp) | P32e(tmp) |
287 P16o(tmp) | P16e(tmp) | P8o(tmp) | P8e(tmp));
288 ecc_buf[1] = ~(P1024o(tmp) | P1024e(tmp) | P512o(tmp) | P512e(tmp) |
289 P256o(tmp) | P256e(tmp) | P128o(tmp) | P128e(tmp));
290 ecc_buf[2] = ~(P4o(tmp) | P4e(tmp) | P2o(tmp) | P2e(tmp) | P1o(tmp) |
291 P1e(tmp) | P2048o(tmp) | P2048e(tmp));
295 * omap_compare_ecc - This function compares two ECC's and indicates if there
296 * is an error. If the error can be corrected it will be corrected to the
298 * @ecc_data1: ecc code from nand spare area
299 * @ecc_data2: ecc code from hardware register obtained from hardware ecc
300 * @page_data: page data
302 static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
303 u8 *ecc_data2, /* read from register */
307 u8 tmp0_bit[8], tmp1_bit[8], tmp2_bit[8];
308 u8 comp0_bit[8], comp1_bit[8], comp2_bit[8];
315 isEccFF = ((*(u32 *)ecc_data1 & 0xFFFFFF) == 0xFFFFFF);
317 gen_true_ecc(ecc_data1);
318 gen_true_ecc(ecc_data2);
320 for (i = 0; i <= 2; i++) {
321 *(ecc_data1 + i) = ~(*(ecc_data1 + i));
322 *(ecc_data2 + i) = ~(*(ecc_data2 + i));
325 for (i = 0; i < 8; i++) {
326 tmp0_bit[i] = *ecc_data1 % 2;
327 *ecc_data1 = *ecc_data1 / 2;
330 for (i = 0; i < 8; i++) {
331 tmp1_bit[i] = *(ecc_data1 + 1) % 2;
332 *(ecc_data1 + 1) = *(ecc_data1 + 1) / 2;
335 for (i = 0; i < 8; i++) {
336 tmp2_bit[i] = *(ecc_data1 + 2) % 2;
337 *(ecc_data1 + 2) = *(ecc_data1 + 2) / 2;
340 for (i = 0; i < 8; i++) {
341 comp0_bit[i] = *ecc_data2 % 2;
342 *ecc_data2 = *ecc_data2 / 2;
345 for (i = 0; i < 8; i++) {
346 comp1_bit[i] = *(ecc_data2 + 1) % 2;
347 *(ecc_data2 + 1) = *(ecc_data2 + 1) / 2;
350 for (i = 0; i < 8; i++) {
351 comp2_bit[i] = *(ecc_data2 + 2) % 2;
352 *(ecc_data2 + 2) = *(ecc_data2 + 2) / 2;
355 for (i = 0; i < 6; i++)
356 ecc_bit[i] = tmp2_bit[i + 2] ^ comp2_bit[i + 2];
358 for (i = 0; i < 8; i++)
359 ecc_bit[i + 6] = tmp0_bit[i] ^ comp0_bit[i];
361 for (i = 0; i < 8; i++)
362 ecc_bit[i + 14] = tmp1_bit[i] ^ comp1_bit[i];
364 ecc_bit[22] = tmp2_bit[0] ^ comp2_bit[0];
365 ecc_bit[23] = tmp2_bit[1] ^ comp2_bit[1];
367 for (i = 0; i < 24; i++)
368 ecc_sum += ecc_bit[i];
372 /* Not reached because this function is not called if
373 * ECC values are equal
378 /* Uncorrectable error */
379 DEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR 1\n");
383 /* UN-Correctable error */
384 DEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR B\n");
388 /* Correctable error */
389 find_byte = (ecc_bit[23] << 8) +
399 find_bit = (ecc_bit[5] << 2) + (ecc_bit[3] << 1) + ecc_bit[1];
401 DEBUG(MTD_DEBUG_LEVEL0, "Correcting single bit ECC error at "
402 "offset: %d, bit: %d\n", find_byte, find_bit);
404 page_data[find_byte] ^= (1 << find_bit);
409 if (ecc_data2[0] == 0 &&
414 DEBUG(MTD_DEBUG_LEVEL0, "UNCORRECTED_ERROR default\n");
420 * omap_correct_data - Compares the ecc read from nand spare area with ECC
421 * registers values and corrects one bit error if it has occured
422 * @mtd: MTD device structure
424 * @read_ecc: ecc read from nand flash
425 * @calc_ecc: ecc read from ECC registers
427 static int omap_correct_data(struct mtd_info *mtd, u_char * dat,
428 u_char * read_ecc, u_char * calc_ecc)
430 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
432 int blockCnt = 0, i = 0, ret = 0;
434 /* Ex NAND_ECC_HW12_2048 */
435 if ((info->nand.ecc.mode == NAND_ECC_HW) &&
436 (info->nand.ecc.size == 2048))
441 for (i = 0; i < blockCnt; i++) {
442 if (memcmp(read_ecc, calc_ecc, 3) != 0) {
443 ret = omap_compare_ecc(read_ecc, calc_ecc, dat);
444 if (ret < 0) return ret;
454 * omap_calcuate_ecc - Generate non-inverted ECC bytes.
455 * Using noninverted ECC can be considered ugly since writing a blank
456 * page ie. padding will clear the ECC bytes. This is no problem as long
457 * nobody is trying to write data on the seemingly unused page. Reading
458 * an erased page will produce an ECC mismatch between generated and read
459 * ECC bytes that has to be dealt with separately.
460 * @mtd: MTD device structure
461 * @dat: The pointer to data on which ecc is computed
462 * @ecc_code: The ecc_code buffer
464 static int omap_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
467 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
469 unsigned long val = 0x0;
472 /* Start Reading from HW ECC1_Result = 0x200 */
473 reg = (unsigned long)(info->gpmc_baseaddr + GPMC_ECC1_RESULT);
474 val = __raw_readl(reg);
475 *ecc_code++ = val; /* P128e, ..., P1e */
476 *ecc_code++ = val >> 16; /* P128o, ..., P1o */
477 /* P2048o, P1024o, P512o, P256o, P2048e, P1024e, P512e, P256e */
478 *ecc_code++ = ((val >> 8) & 0x0f) | ((val >> 20) & 0xf0);
485 * omap_enable_hwecc - This function enables the hardware ecc functionality
486 * @mtd: MTD device structure
487 * @mode: Read/Write mode
489 static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
491 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
493 register struct nand_chip *chip = mtd->priv;
494 unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
495 unsigned long val = __raw_readl(info->gpmc_baseaddr + GPMC_ECC_CONFIG);
499 __raw_writel(0x101, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
500 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */
501 val = (dev_width << 7) | (info->gpmc_cs << 1) | (0x1);
503 case NAND_ECC_READSYN :
504 __raw_writel(0x100, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
505 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */
506 val = (dev_width << 7) | (info->gpmc_cs << 1) | (0x1);
508 case NAND_ECC_WRITE :
509 __raw_writel(0x101, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
510 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */
511 val = (dev_width << 7) | (info->gpmc_cs << 1) | (0x1);
514 DEBUG(MTD_DEBUG_LEVEL0, "Error: Unrecognized Mode[%d]!\n",
519 __raw_writel(val, info->gpmc_baseaddr + GPMC_ECC_CONFIG);
524 * omap_wait - Wait function is called during Program and erase
525 * operations and the way it is called from MTD layer, we should wait
526 * till the NAND chip is ready after the programming/erase operation
528 * @mtd: MTD device structure
529 * @chip: NAND Chip structure
531 static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
533 register struct nand_chip *this = mtd->priv;
534 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
538 this->IO_ADDR_W = (void *) info->gpmc_cs_baseaddr +
539 GPMC_CS_NAND_COMMAND;
540 this->IO_ADDR_R = (void *) info->gpmc_cs_baseaddr + GPMC_CS_NAND_DATA;
542 while (!(status & 0x40)) {
543 __raw_writeb(NAND_CMD_STATUS & 0xFF, this->IO_ADDR_W);
544 status = __raw_readb(this->IO_ADDR_R);
550 * omap_dev_ready - calls the platform specific dev_ready function
551 * @mtd: MTD device structure
553 static int omap_dev_ready(struct mtd_info *mtd)
555 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
557 unsigned int val = __raw_readl(info->gpmc_baseaddr + GPMC_IRQ_STATUS);
559 if ((val & 0x100) == 0x100) {
560 /* Clear IRQ Interrupt */
563 __raw_writel(val, info->gpmc_baseaddr + GPMC_IRQ_STATUS);
565 unsigned int cnt = 0;
566 while (cnt++ < 0x1FF) {
567 if ((val & 0x100) == 0x100)
569 val = __raw_readl(info->gpmc_baseaddr +
577 static int __devinit omap_nand_probe(struct platform_device *pdev)
579 struct omap_nand_info *info;
580 struct omap_nand_platform_data *pdata;
585 pdata = pdev->dev.platform_data;
587 dev_err(&pdev->dev, "platform data missing\n");
591 info = kzalloc(sizeof(struct omap_nand_info), GFP_KERNEL);
592 if (!info) return -ENOMEM;
594 platform_set_drvdata(pdev, info);
596 spin_lock_init(&info->controller.lock);
597 init_waitqueue_head(&info->controller.wq);
601 info->gpmc_cs = pdata->cs;
602 info->gpmc_baseaddr = pdata->gpmc_baseaddr;
603 info->gpmc_cs_baseaddr = pdata->gpmc_cs_baseaddr;
605 info->mtd.priv = &info->nand;
606 info->mtd.name = pdev->dev.bus_id;
607 info->mtd.owner = THIS_MODULE;
609 err = gpmc_cs_request(info->gpmc_cs, NAND_IO_SIZE, &info->phys_base);
611 dev_err(&pdev->dev, "Cannot request GPMC CS\n");
615 /* Enable RD PIN Monitoring Reg */
616 if (pdata->dev_ready) {
617 val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1);
618 val |= WR_RD_PIN_MONITORING;
619 gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG1, val);
622 val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG7);
624 val |= (0xc & 0xf) << 8;
625 gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG7, val);
627 /* NAND write protect off */
628 omap_nand_wp(&info->mtd, NAND_WP_OFF);
630 if (!request_mem_region(info->phys_base, NAND_IO_SIZE,
631 pdev->dev.driver->name)) {
636 info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE);
637 if (!info->nand.IO_ADDR_R) {
639 goto out_release_mem_region;
641 info->nand.controller = &info->controller;
643 info->nand.IO_ADDR_W = info->nand.IO_ADDR_R;
644 info->nand.cmd_ctrl = omap_hwcontrol;
646 info->nand.read_buf = omap_read_buf;
647 info->nand.write_buf = omap_write_buf;
648 info->nand.verify_buf = omap_verify_buf;
651 * If RDY/BSY line is connected to OMAP then use the omap ready funcrtion
652 * and the generic nand_wait function which reads the status register
653 * after monitoring the RDY/BSY line.Otherwise use a standard chip delay
654 * which is slightly more than tR (AC Timing) of the NAND device and read
655 * status register until you get a failure or success
657 if (pdata->dev_ready) {
658 info->nand.dev_ready = omap_dev_ready;
659 info->nand.chip_delay = 0;
661 info->nand.waitfunc = omap_wait;
662 info->nand.chip_delay = 50;
665 info->nand.options |= NAND_SKIP_BBTSCAN;
666 if ((gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1) & 0x3000)
668 info->nand.options |= NAND_BUSWIDTH_16;
670 #ifdef CONFIG_MTD_NAND_OMAP_HWECC
671 info->nand.ecc.bytes = 3;
672 info->nand.ecc.size = 512;
673 info->nand.ecc.calculate = omap_calculate_ecc;
674 info->nand.ecc.hwctl = omap_enable_hwecc;
675 info->nand.ecc.correct = omap_correct_data;
676 info->nand.ecc.mode = NAND_ECC_HW;
679 omap_hwecc_init(&info->mtd);
681 info->nand.ecc.mode = NAND_ECC_SOFT;
684 /* DIP switches on some boards change between 8 and 16 bit
685 * bus widths for flash. Try the other width if the first try fails.
687 if (nand_scan(&info->mtd, 1)) {
688 info->nand.options ^= NAND_BUSWIDTH_16;
689 if (nand_scan(&info->mtd, 1)) {
691 goto out_release_mem_region;
695 #ifdef CONFIG_MTD_PARTITIONS
696 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
698 add_mtd_partitions(&info->mtd, info->parts, err);
699 else if (pdata->parts)
700 add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts);
703 add_mtd_device(&info->mtd);
705 platform_set_drvdata(pdev, &info->mtd);
709 out_release_mem_region:
710 release_mem_region(info->phys_base, NAND_IO_SIZE);
712 gpmc_cs_free(info->gpmc_cs);
719 static int omap_nand_remove(struct platform_device *pdev)
721 struct mtd_info *mtd = platform_get_drvdata(pdev);
722 struct omap_nand_info *info = mtd->priv;
724 platform_set_drvdata(pdev, NULL);
725 /* Release NAND device, its internal structures and partitions */
726 nand_release(&info->mtd);
727 iounmap(info->nand.IO_ADDR_R);
732 static struct platform_driver omap_nand_driver = {
733 .probe = omap_nand_probe,
734 .remove = omap_nand_remove,
737 .owner = THIS_MODULE,
740 MODULE_ALIAS(DRIVER_NAME);
742 static int __init omap_nand_init(void)
744 printk(KERN_INFO "%s driver initializing\n", DRIVER_NAME);
745 return platform_driver_register(&omap_nand_driver);
748 static void __exit omap_nand_exit(void)
750 platform_driver_unregister(&omap_nand_driver);
753 module_init(omap_nand_init);
754 module_exit(omap_nand_exit);
756 MODULE_LICENSE("GPL");
757 MODULE_DESCRIPTION("Glue layer for NAND flash on TI OMAP boards");