From: Andy P. <at...@us...> - 2002-04-10 19:00:34
|
Update of /cvsroot/linux-vax/kernel-2.4/drivers/mtd/nand In directory usw-pr-cvs1:/tmp/cvs-serv22769/mtd/nand Added Files: Config.in Makefile nand.c nand_ecc.c spia.c Log Message: synch 2.4.15 commit 42 --- NEW FILE --- # drivers/mtd/nand/Config.in # $Id: Config.in,v 1.1 2002/04/10 14:57:59 atp Exp $ mainmenu_option next_comment comment 'NAND Flash Device Drivers' dep_tristate ' NAND Device Support' CONFIG_MTD_NAND $CONFIG_MTD if [ "$CONFIG_MTD_NAND" = "y" -o "$CONFIG_MTD_NAND" = "m" ]; then bool ' Enable ECC correction algorithm' CONFIG_MTD_NAND_ECC bool ' Verify NAND page writes' CONFIG_MTD_NAND_VERIFY_WRITE fi if [ "$CONFIG_ARM" = "y" -a "$CONFIG_ARCH_P720T" = "y" ]; then dep_tristate ' NAND Flash device on SPIA board' CONFIG_MTD_NAND_SPIA $CONFIG_MTD_NAND fi endmenu --- NEW FILE --- # # linux/drivers/nand/Makefile # # $Id: Makefile,v 1.1 2002/04/10 14:57:59 atp Exp $ O_TARGET := nandlink.o export-objs := nand.o nand_ecc.o nandobjs-y := nand.o nandobjs-$(CONFIG_MTD_NAND_ECC) += nand_ecc.o obj-$(CONFIG_MTD_NAND) += $(nandobjs-y) obj-$(CONFIG_MTD_NAND_SPIA) += spia.o include $(TOPDIR)/Rules.make --- NEW FILE --- /* * drivers/mtd/nand.c * * Copyright (C) 2000 Steven J. Hill (sj...@co...) * * $Id: nand.c,v 1.1 2002/04/10 14:57:59 atp Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Overview: * This is the generic MTD driver for NAND flash devices. It should be * capable of working with almost all NAND chips currently available. */ #include <linux/delay.h> #include <linux/errno.h> #include <linux/sched.h> [...1335 lines suppressed...] mtd->write_ecc = nand_write_ecc; mtd->read_oob = nand_read_oob; mtd->write_oob = nand_write_oob; mtd->readv = NULL; mtd->writev = nand_writev; mtd->sync = nand_sync; mtd->lock = NULL; mtd->unlock = NULL; mtd->suspend = NULL; mtd->resume = NULL; /* Return happy */ return 0; } EXPORT_SYMBOL(nand_scan); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Steven J. Hill <sj...@co..."); MODULE_DESCRIPTION("Generic NAND flash driver code"); --- NEW FILE --- /* * drivers/mtd/nand_ecc.c * * Copyright (C) 2000 Steven J. Hill (sj...@co...) * Toshiba America Electronics Components, Inc. * * $Id: nand_ecc.c,v 1.1 2002/04/10 14:57:59 atp Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This file contains an ECC algorithm from Toshiba that detects and * corrects 1 bit errors in a 256 byte block of data. */ #include <linux/types.h> #include <linux/kernel.h> #include <linux/module.h> /* * Pre-calculated 256-way 1 byte column parity */ static const u_char nand_ecc_precalc_table[] = { 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00, 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65, 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66, 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03, 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69, 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f, 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a, 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a, 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f, 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69, 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03, 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66, 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65, 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00 }; /* * Creates non-inverted ECC code from line parity */ static void nand_trans_result(u_char reg2, u_char reg3, u_char *ecc_code) { u_char a, b, i, tmp1, tmp2; /* Initialize variables */ a = b = 0x80; tmp1 = tmp2 = 0; /* Calculate first ECC byte */ for (i = 0; i < 4; i++) { if (reg3 & a) /* LP15,13,11,9 --> ecc_code[0] */ tmp1 |= b; b >>= 1; if (reg2 & a) /* LP14,12,10,8 --> ecc_code[0] */ tmp1 |= b; b >>= 1; a >>= 1; } /* Calculate second ECC byte */ b = 0x80; for (i = 0; i < 4; i++) { if (reg3 & a) /* LP7,5,3,1 --> ecc_code[1] */ tmp2 |= b; b >>= 1; if (reg2 & a) /* LP6,4,2,0 --> ecc_code[1] */ tmp2 |= b; b >>= 1; a >>= 1; } /* Store two of the ECC bytes */ ecc_code[0] = tmp1; ecc_code[1] = tmp2; } /* * Calculate 3 byte ECC code for 256 byte block */ void nand_calculate_ecc (const u_char *dat, u_char *ecc_code) { u_char idx, reg1, reg2, reg3; int j; /* Initialize variables */ reg1 = reg2 = reg3 = 0; ecc_code[0] = ecc_code[1] = ecc_code[2] = 0; /* Build up column parity */ for(j = 0; j < 256; j++) { /* Get CP0 - CP5 from table */ idx = nand_ecc_precalc_table[dat[j]]; reg1 ^= (idx & 0x3f); /* All bit XOR = 1 ? */ if (idx & 0x40) { reg3 ^= (u_char) j; reg2 ^= ~((u_char) j); } } /* Create non-inverted ECC code from line parity */ nand_trans_result(reg2, reg3, ecc_code); /* Calculate final ECC code */ ecc_code[0] = ~ecc_code[0]; ecc_code[1] = ~ecc_code[1]; ecc_code[2] = ((~reg1) << 2) | 0x03; } /* * Detect and correct a 1 bit error for 256 byte block */ int nand_correct_data (u_char *dat, u_char *read_ecc, u_char *calc_ecc) { u_char a, b, c, d1, d2, d3, add, bit, i; /* Do error detection */ d1 = calc_ecc[0] ^ read_ecc[0]; d2 = calc_ecc[1] ^ read_ecc[1]; d3 = calc_ecc[2] ^ read_ecc[2]; if ((d1 | d2 | d3) == 0) { /* No errors */ return 0; } else { a = (d1 ^ (d1 >> 1)) & 0x55; b = (d2 ^ (d2 >> 1)) & 0x55; c = (d3 ^ (d3 >> 1)) & 0x54; /* Found and will correct single bit error in the data */ if ((a == 0x55) && (b == 0x55) && (c == 0x54)) { c = 0x80; add = 0; a = 0x80; for (i=0; i<4; i++) { if (d1 & c) add |= a; c >>= 2; a >>= 1; } c = 0x80; for (i=0; i<4; i++) { if (d2 & c) add |= a; c >>= 2; a >>= 1; } bit = 0; b = 0x04; c = 0x80; for (i=0; i<3; i++) { if (d3 & c) bit |= b; c >>= 2; b >>= 1; } b = 0x01; a = dat[add]; a ^= (b << bit); dat[add] = a; return 1; } else { i = 0; while (d1) { if (d1 & 0x01) ++i; d1 >>= 1; } while (d2) { if (d2 & 0x01) ++i; d2 >>= 1; } while (d3) { if (d3 & 0x01) ++i; d3 >>= 1; } if (i == 1) { /* ECC Code Error Correction */ read_ecc[0] = calc_ecc[0]; read_ecc[1] = calc_ecc[1]; read_ecc[2] = calc_ecc[2]; return 2; } else { /* Uncorrectable Error */ return -1; } } } /* Should never happen */ return -1; } EXPORT_SYMBOL(nand_calculate_ecc); EXPORT_SYMBOL(nand_correct_data); --- NEW FILE --- /* * drivers/mtd/nand/spia.c * * Copyright (C) 2000 Steven J. Hill (sj...@co...) * * $Id: spia.c,v 1.1 2002/04/10 14:57:59 atp Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Overview: * This is a device driver for the NAND flash device found on the * SPIA board which utilizes the Toshiba TC58V64AFT part. This is * a 64Mibit (8MiB x 8 bits) NAND flash device. */ #include <linux/slab.h> #include <linux/module.h> #include <linux/mtd/mtd.h> #include <linux/mtd/nand.h> #include <linux/mtd/partitions.h> #include <asm/io.h> /* * MTD structure for SPIA board */ static struct mtd_info *spia_mtd = NULL; /* * Values specific to the SPIA board (used with EP7212 processor) */ #define SPIA_IO_ADDR = 0xd0000000 /* Start of EP7212 IO address space */ #define SPIA_FIO_ADDR = 0xf0000000 /* Address where flash is mapped */ #define SPIA_PEDR = 0x0080 /* * IO offset to Port E data register * where the CLE, ALE and NCE pins * are wired to. */ #define SPIA_PEDDR = 0x00c0 /* * IO offset to Port E data direction * register so we can control the IO * lines. */ /* * Module stuff */ static int spia_io_base = SPIA_IO_BASE; static int spia_fio_base = SPIA_FIO_BASE; static int spia_pedr = SPIA_PEDR; static int spia_peddr = SPIA_PEDDR; MODULE_PARM(spia_io_base, "i"); MODULE_PARM(spia_fio_base, "i"); MODULE_PARM(spia_pedr, "i"); MODULE_PARM(spia_peddr, "i"); __setup("spia_io_base=",spia_io_base); __setup("spia_fio_base=",spia_fio_base); __setup("spia_pedr=",spia_pedr); __setup("spia_peddr=",spia_peddr); /* * Define partitions for flash device */ const static struct mtd_partition partition_info[] = { { name: "SPIA flash partition 1", offset: 0, size: 2*1024*1024 }, { name: "SPIA flash partition 2", offset: 2*1024*1024, size: 6*1024*1024 } }; #define NUM_PARTITIONS 2 /* * Main initialization routine */ int __init spia_init (void) { struct nand_chip *this; /* Allocate memory for MTD device structure and private data */ spia_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip), GFP_KERNEL); if (!spia_mtd) { printk ("Unable to allocate SPIA NAND MTD device structure.\n"); return -ENOMEM; } /* Get pointer to private data */ this = (struct nand_chip *) (&spia_mtd[1]); /* Initialize structures */ memset((char *) spia_mtd, 0, sizeof(struct mtd_info)); memset((char *) this, 0, sizeof(struct nand_chip)); /* Link the private data with the MTD structure */ spia_mtd->priv = this; /* * Set GPIO Port E control register so that the pins are configured * to be outputs for controlling the NAND flash. */ (*(volatile unsigned char *) (spia_io_base + spia_peddr)) = 0x07; /* Set address of NAND IO lines */ this->IO_ADDR = spia_fio_base; this->CTRL_ADDR = spia_io_base + spia_pedr; this->CLE = 0x01; this->ALE = 0x02; this->NCE = 0x04; /* Scan to find existance of the device */ if (nand_scan (spia_mtd)) { kfree (spia_mtd); return -ENXIO; } /* Allocate memory for internal data buffer */ this->data_buf = kmalloc (sizeof(u_char) * (spia_mtd->oobblock + spia_mtd->oobsize), GFP_KERNEL); if (!this->data_buf) { printk ("Unable to allocate NAND data buffer for SPIA.\n"); kfree (spia_mtd); return -ENOMEM; } /* Register the partitions */ add_mtd_partitions(spia_mtd, partition_info, NUM_PARTITIONS); /* Return happy */ return 0; } module_init(spia_init); /* * Clean up routine */ #ifdef MODULE static void __exit spia_cleanup (void) { struct nand_chip *this = (struct nand_chip *) &spia_mtd[1]; /* Unregister the device */ del_mtd_device (spia_mtd); /* Free internal data buffer */ kfree (this->data_buf); /* Free the MTD device structure */ kfree (spia_mtd); } module_exit(spia_cleanup); #endif MODULE_LICENSE("GPL"); MODULE_AUTHOR("Steven J. Hill <sj...@co..."); MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on SPIA board"); |