Merge git://git.infradead.org/mtd-2.6
Linus Torvalds [Tue, 20 Jun 2006 21:50:31 +0000 (14:50 -0700)]
* git://git.infradead.org/mtd-2.6: (199 commits)
  [MTD] NAND: Fix breakage all over the place
  [PATCH] NAND: fix remaining OOB length calculation
  [MTD] NAND Fixup NDFC merge brokeness
  [MTD NAND] S3C2410 driver cleanup
  [MTD NAND] s3c24x0 board: Fix clock handling, ensure proper initialisation.
  [JFFS2] Check CRC32 on dirent and data nodes each time they're read
  [JFFS2] When retiring nextblock, allocate a node_ref for the wasted space
  [JFFS2] Mark XATTR support as experimental, for now
  [JFFS2] Don't trust node headers before the CRC is checked.
  [MTD] Restore MTD_ROM and MTD_RAM types
  [MTD] assume mtd->writesize is 1 for NOR flashes
  [MTD NAND] Fix s3c2410 NAND driver so it at least _looks_ like it compiles
  [MTD] Prepare physmap for 64-bit-resources
  [JFFS2] Fix more breakage caused by janitorial meddling.
  [JFFS2] Remove stray __exit from jffs2_compressors_exit()
  [MTD] Allow alternate JFFS2 mount variant for root filesystem.
  [MTD] Disconnect struct mtd_info from ABI
  [MTD] replace MTD_RAM with MTD_GENERIC_TYPE
  [MTD] replace MTD_ROM with MTD_GENERIC_TYPE
  [MTD] remove a forgotten MTD_XIP
  ...

124 files changed:
MAINTAINERS
drivers/mtd/Kconfig
drivers/mtd/chips/Kconfig
drivers/mtd/chips/Makefile
drivers/mtd/chips/amd_flash.c
drivers/mtd/chips/cfi_cmdset_0001.c
drivers/mtd/chips/cfi_cmdset_0002.c
drivers/mtd/chips/cfi_cmdset_0020.c
drivers/mtd/chips/cfi_probe.c
drivers/mtd/chips/gen_probe.c
drivers/mtd/chips/map_ram.c
drivers/mtd/chips/map_rom.c
drivers/mtd/chips/sharp.c
drivers/mtd/devices/Kconfig
drivers/mtd/devices/Makefile
drivers/mtd/devices/block2mtd.c
drivers/mtd/devices/doc2000.c
drivers/mtd/devices/doc2001.c
drivers/mtd/devices/doc2001plus.c
drivers/mtd/devices/docprobe.c
drivers/mtd/devices/lart.c
drivers/mtd/devices/m25p80.c
drivers/mtd/devices/ms02-nv.c
drivers/mtd/devices/mtdram.c
drivers/mtd/devices/phram.c
drivers/mtd/devices/slram.c
drivers/mtd/inftlcore.c
drivers/mtd/inftlmount.c
drivers/mtd/maps/Kconfig
drivers/mtd/maps/cfi_flagadm.c
drivers/mtd/maps/dbox2-flash.c
drivers/mtd/maps/mtx-1_flash.c
drivers/mtd/maps/nettel.c
drivers/mtd/maps/pcmciamtd.c
drivers/mtd/maps/physmap.c
drivers/mtd/mtdblock.c
drivers/mtd/mtdblock_ro.c
drivers/mtd/mtdchar.c
drivers/mtd/mtdconcat.c
drivers/mtd/mtdcore.c
drivers/mtd/mtdpart.c
drivers/mtd/nand/Kconfig
drivers/mtd/nand/Makefile
drivers/mtd/nand/ams-delta.c [new file with mode: 0644]
drivers/mtd/nand/au1550nd.c
drivers/mtd/nand/autcpu12.c
drivers/mtd/nand/cs553x_nand.c [new file with mode: 0644]
drivers/mtd/nand/diskonchip.c
drivers/mtd/nand/edb7312.c
drivers/mtd/nand/h1910.c
drivers/mtd/nand/nand_base.c
drivers/mtd/nand/nand_bbt.c
drivers/mtd/nand/nand_ecc.c
drivers/mtd/nand/nand_ids.c
drivers/mtd/nand/nandsim.c
drivers/mtd/nand/ndfc.c [new file with mode: 0644]
drivers/mtd/nand/ppchameleonevb.c
drivers/mtd/nand/rtc_from4.c
drivers/mtd/nand/s3c2410.c
drivers/mtd/nand/sharpsl.c
drivers/mtd/nand/spia.c
drivers/mtd/nand/toto.c
drivers/mtd/nand/ts7250.c [new file with mode: 0644]
drivers/mtd/nftlcore.c
drivers/mtd/nftlmount.c
drivers/mtd/onenand/Kconfig
drivers/mtd/onenand/onenand_base.c
drivers/mtd/onenand/onenand_bbt.c
drivers/mtd/redboot.c
drivers/mtd/rfd_ftl.c
fs/Kconfig
fs/jffs/intrep.c
fs/jffs2/Makefile
fs/jffs2/README.Locking
fs/jffs2/acl.c [new file with mode: 0644]
fs/jffs2/acl.h [new file with mode: 0644]
fs/jffs2/build.c
fs/jffs2/compr.c
fs/jffs2/compr.h
fs/jffs2/debug.c
fs/jffs2/debug.h
fs/jffs2/dir.c
fs/jffs2/erase.c
fs/jffs2/file.c
fs/jffs2/fs.c
fs/jffs2/gc.c
fs/jffs2/histo.h [deleted file]
fs/jffs2/jffs2_fs_i.h [moved from include/linux/jffs2_fs_i.h with 91% similarity]
fs/jffs2/jffs2_fs_sb.h [moved from include/linux/jffs2_fs_sb.h with 92% similarity]
fs/jffs2/malloc.c
fs/jffs2/nodelist.c
fs/jffs2/nodelist.h
fs/jffs2/nodemgmt.c
fs/jffs2/os-linux.h
fs/jffs2/readinode.c
fs/jffs2/scan.c
fs/jffs2/security.c [new file with mode: 0644]
fs/jffs2/summary.c
fs/jffs2/summary.h
fs/jffs2/super.c
fs/jffs2/symlink.c
fs/jffs2/wbuf.c
fs/jffs2/write.c
fs/jffs2/xattr.c [new file with mode: 0644]
fs/jffs2/xattr.h [new file with mode: 0644]
fs/jffs2/xattr_trusted.c [new file with mode: 0644]
fs/jffs2/xattr_user.c [new file with mode: 0644]
include/linux/jffs2.h
include/linux/module.h
include/linux/mtd/inftl.h
include/linux/mtd/mtd.h
include/linux/mtd/nand.h
include/linux/mtd/ndfc.h [new file with mode: 0644]
include/linux/mtd/nftl.h
include/linux/mtd/onenand.h
include/linux/mtd/onenand_regs.h
include/linux/mtd/partitions.h
include/linux/mtd/physmap.h
include/mtd/mtd-abi.h
include/mtd/mtd-user.h
init/Kconfig
init/do_mounts.c
kernel/Makefile
kernel/intermodule.c [deleted file]

index 854a152..ce37c4b 100644 (file)
@@ -1843,12 +1843,12 @@ S:     linux-scsi@vger.kernel.org
 W:     http://megaraid.lsilogic.com
 S:     Maintained
 
-MEMORY TECHNOLOGY DEVICES
+MEMORY TECHNOLOGY DEVICES (MTD)
 P:     David Woodhouse
 M:     dwmw2@infradead.org
 W:     http://www.linux-mtd.infradead.org/
 L:     linux-mtd@lists.infradead.org
-T:     git kernel.org:/pub/scm/linux/kernel/git/tglx/mtd-2.6.git
+T:     git git://git.infradead.org/mtd-2.6.git
 S:     Maintained
 
 MICROTEK X6 SCANNER
index f6b775e..5ac265d 100644 (file)
@@ -78,7 +78,7 @@ config MTD_REDBOOT_DIRECTORY_BLOCK
          option.
 
          The option specifies which Flash sectors holds the RedBoot
-         partition table.  A zero or positive value gives an absolete
+         partition table.  A zero or positive value gives an absolute
          erase block number. A negative value specifies a number of
          sectors before the end of the device.
 
@@ -103,7 +103,7 @@ config MTD_CMDLINE_PARTS
        bool "Command line partition table parsing"
        depends on MTD_PARTITIONS = "y"
        ---help---
-         Allow generic configuration of the MTD paritition tables via the kernel
+         Allow generic configuration of the MTD partition tables via the kernel
          command line. Multiple flash resources are supported for hardware where
          different kinds of flash memory are available.
 
index a7ec595..6d8f30d 100644 (file)
@@ -30,7 +30,6 @@ config MTD_JEDECPROBE
 
 config MTD_GEN_PROBE
        tristate
-       select OBSOLETE_INTERMODULE
 
 config MTD_CFI_ADV_OPTIONS
        bool "Flash chip driver advanced configuration options"
index 8afe309..75bc1c2 100644 (file)
@@ -3,13 +3,6 @@
 #
 # $Id: Makefile.common,v 1.5 2005/11/07 11:14:22 gleixner Exp $
 
-#                       *** BIG UGLY NOTE ***
-#
-# The removal of get_module_symbol() and replacement with
-# inter_module_register() et al has introduced a link order dependency
-# here where previously there was none.  We now have to ensure that
-# the CFI command set drivers are linked before gen_probe.o
-
 obj-$(CONFIG_MTD)              += chipreg.o
 obj-$(CONFIG_MTD_AMDSTD)       += amd_flash.o
 obj-$(CONFIG_MTD_CFI)          += cfi_probe.o
index 5711561..16eaca6 100644 (file)
@@ -97,7 +97,6 @@ struct amd_flash_private {
        int interleave;
        int numchips;
        unsigned long chipshift;
-//     const char *im_name;
        struct flchip chips[0];
 };
 
@@ -131,12 +130,6 @@ static struct mtd_chip_driver amd_flash_chipdrv = {
        .module = THIS_MODULE
 };
 
-
-
-static const char im_name[] = "amd_flash";
-
-
-
 static inline __u32 wide_read(struct map_info *map, __u32 addr)
 {
        if (map->buswidth == 1) {
@@ -737,6 +730,7 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
                offset += dev_size;
        }
        mtd->type = MTD_NORFLASH;
+       mtd->writesize = 1;
        mtd->flags = MTD_CAP_NORFLASH;
        mtd->name = map->name;
        mtd->erase = amd_flash_erase;
index 1c074d6..0d43581 100644 (file)
@@ -331,13 +331,6 @@ read_pri_intelext(struct map_info *map, __u16 adr)
        return extp;
 }
 
-/* This routine is made available to other mtd code via
- * inter_module_register.  It must only be accessed through
- * inter_module_get which will bump the use count of this module.  The
- * addresses passed back in cfi are valid as long as the use count of
- * this module is non-zero, i.e. between inter_module_get and
- * inter_module_put.  Keith Owens <kaos@ocs.com.au> 29 Oct 2000.
- */
 struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
 {
        struct cfi_private *cfi = map->fldrv_priv;
@@ -406,7 +399,7 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
        for (i=0; i< cfi->numchips; i++) {
                cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp;
                cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp;
-               cfi->chips[i].erase_time = 1<<cfi->cfiq->BlockEraseTimeoutTyp;
+               cfi->chips[i].erase_time = 1000<<cfi->cfiq->BlockEraseTimeoutTyp;
                cfi->chips[i].ref_point_counter = 0;
                init_waitqueue_head(&(cfi->chips[i].wq));
        }
@@ -415,6 +408,11 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
 
        return cfi_intelext_setup(mtd);
 }
+struct mtd_info *cfi_cmdset_0003(struct map_info *map, int primary) __attribute__((alias("cfi_cmdset_0001")));
+struct mtd_info *cfi_cmdset_0200(struct map_info *map, int primary) __attribute__((alias("cfi_cmdset_0001")));
+EXPORT_SYMBOL_GPL(cfi_cmdset_0001);
+EXPORT_SYMBOL_GPL(cfi_cmdset_0003);
+EXPORT_SYMBOL_GPL(cfi_cmdset_0200);
 
 static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
 {
@@ -547,12 +545,12 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
                if (extp->MinorVersion >= '4') {
                        struct cfi_intelext_programming_regioninfo *prinfo;
                        prinfo = (struct cfi_intelext_programming_regioninfo *)&extp->extra[offs];
-                       MTD_PROGREGION_SIZE(mtd) = cfi->interleave << prinfo->ProgRegShift;
+                       mtd->writesize = cfi->interleave << prinfo->ProgRegShift;
                        MTD_PROGREGION_CTRLMODE_VALID(mtd) = cfi->interleave * prinfo->ControlValid;
                        MTD_PROGREGION_CTRLMODE_INVALID(mtd) = cfi->interleave * prinfo->ControlInvalid;
-                       mtd->flags |= MTD_PROGRAM_REGIONS;
+                       mtd->flags &= ~MTD_BIT_WRITEABLE;
                        printk(KERN_DEBUG "%s: program region size/ctrl_valid/ctrl_inval = %d/%d/%d\n",
-                              map->name, MTD_PROGREGION_SIZE(mtd),
+                              map->name, mtd->writesize,
                               MTD_PROGREGION_CTRLMODE_VALID(mtd),
                               MTD_PROGREGION_CTRLMODE_INVALID(mtd));
                }
@@ -896,26 +894,33 @@ static void __xipram xip_enable(struct map_info *map, struct flchip *chip,
 
 /*
  * When a delay is required for the flash operation to complete, the
- * xip_udelay() function is polling for both the given timeout and pending
- * (but still masked) hardware interrupts.  Whenever there is an interrupt
- * pending then the flash erase or write operation is suspended, array mode
- * restored and interrupts unmasked.  Task scheduling might also happen at that
- * point.  The CPU eventually returns from the interrupt or the call to
- * schedule() and the suspended flash operation is resumed for the remaining
- * of the delay period.
+ * xip_wait_for_operation() function is polling for both the given timeout
+ * and pending (but still masked) hardware interrupts.  Whenever there is an
+ * interrupt pending then the flash erase or write operation is suspended,
+ * array mode restored and interrupts unmasked.  Task scheduling might also
+ * happen at that point.  The CPU eventually returns from the interrupt or
+ * the call to schedule() and the suspended flash operation is resumed for
+ * the remaining of the delay period.
  *
  * Warning: this function _will_ fool interrupt latency tracing tools.
  */
 
-static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
-                               unsigned long adr, int usec)
+static int __xipram xip_wait_for_operation(
+               struct map_info *map, struct flchip *chip,
+               unsigned long adr, int *chip_op_time )
 {
        struct cfi_private *cfi = map->fldrv_priv;
        struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
        map_word status, OK = CMD(0x80);
-       unsigned long suspended, start = xip_currtime();
+       unsigned long usec, suspended, start, done;
        flstate_t oldstate, newstate;
 
+               start = xip_currtime();
+       usec = *chip_op_time * 8;
+       if (usec == 0)
+               usec = 500000;
+       done = 0;
+
        do {
                cpu_relax();
                if (xip_irqpending() && cfip &&
@@ -932,9 +937,9 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
                         * we resume the whole thing at once).  Yes, it
                         * can happen!
                         */
+                       usec -= done;
                        map_write(map, CMD(0xb0), adr);
                        map_write(map, CMD(0x70), adr);
-                       usec -= xip_elapsed_since(start);
                        suspended = xip_currtime();
                        do {
                                if (xip_elapsed_since(suspended) > 100000) {
@@ -944,7 +949,7 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
                                         * This is a critical error but there
                                         * is not much we can do here.
                                         */
-                                       return;
+                                       return -EIO;
                                }
                                status = map_read(map, adr);
                        } while (!map_word_andequal(map, status, OK, OK));
@@ -1004,65 +1009,107 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
                        xip_cpu_idle();
                }
                status = map_read(map, adr);
+               done = xip_elapsed_since(start);
        } while (!map_word_andequal(map, status, OK, OK)
-                && xip_elapsed_since(start) < usec);
-}
+                && done < usec);
 
-#define UDELAY(map, chip, adr, usec)  xip_udelay(map, chip, adr, usec)
+       return (done >= usec) ? -ETIME : 0;
+}
 
 /*
  * The INVALIDATE_CACHED_RANGE() macro is normally used in parallel while
  * the flash is actively programming or erasing since we have to poll for
  * the operation to complete anyway.  We can't do that in a generic way with
  * a XIP setup so do it before the actual flash operation in this case
- * and stub it out from INVALIDATE_CACHE_UDELAY.
+ * and stub it out from INVAL_CACHE_AND_WAIT.
  */
 #define XIP_INVAL_CACHED_RANGE(map, from, size)  \
        INVALIDATE_CACHED_RANGE(map, from, size)
 
-#define INVALIDATE_CACHE_UDELAY(map, chip, cmd_adr, adr, len, usec)  \
-       UDELAY(map, chip, cmd_adr, usec)
-
-/*
- * Extra notes:
- *
- * Activating this XIP support changes the way the code works a bit.  For
- * example the code to suspend the current process when concurrent access
- * happens is never executed because xip_udelay() will always return with the
- * same chip state as it was entered with.  This is why there is no care for
- * the presence of add_wait_queue() or schedule() calls from within a couple
- * xip_disable()'d  areas of code, like in do_erase_oneblock for example.
- * The queueing and scheduling are always happening within xip_udelay().
- *
- * Similarly, get_chip() and put_chip() just happen to always be executed
- * with chip->state set to FL_READY (or FL_XIP_WHILE_*) where flash state
- * is in array mode, therefore never executing many cases therein and not
- * causing any problem with XIP.
- */
+#define INVAL_CACHE_AND_WAIT(map, chip, cmd_adr, inval_adr, inval_len, p_usec) \
+       xip_wait_for_operation(map, chip, cmd_adr, p_usec)
 
 #else
 
 #define xip_disable(map, chip, adr)
 #define xip_enable(map, chip, adr)
 #define XIP_INVAL_CACHED_RANGE(x...)
+#define INVAL_CACHE_AND_WAIT inval_cache_and_wait_for_operation
+
+static int inval_cache_and_wait_for_operation(
+               struct map_info *map, struct flchip *chip,
+               unsigned long cmd_adr, unsigned long inval_adr, int inval_len,
+               int *chip_op_time )
+{
+       struct cfi_private *cfi = map->fldrv_priv;
+       map_word status, status_OK = CMD(0x80);
+       int z, chip_state = chip->state;
+       unsigned long timeo;
+
+       spin_unlock(chip->mutex);
+       if (inval_len)
+               INVALIDATE_CACHED_RANGE(map, inval_adr, inval_len);
+       if (*chip_op_time)
+               cfi_udelay(*chip_op_time);
+       spin_lock(chip->mutex);
+
+       timeo = *chip_op_time * 8 * HZ / 1000000;
+       if (timeo < HZ/2)
+               timeo = HZ/2;
+       timeo += jiffies;
+
+       z = 0;
+       for (;;) {
+               if (chip->state != chip_state) {
+                       /* Someone's suspended the operation: sleep */
+                       DECLARE_WAITQUEUE(wait, current);
+
+                       set_current_state(TASK_UNINTERRUPTIBLE);
+                       add_wait_queue(&chip->wq, &wait);
+                       spin_unlock(chip->mutex);
+                       schedule();
+                       remove_wait_queue(&chip->wq, &wait);
+                       timeo = jiffies + (HZ / 2); /* FIXME */
+                       spin_lock(chip->mutex);
+                       continue;
+               }
 
-#define UDELAY(map, chip, adr, usec)  \
-do {  \
-       spin_unlock(chip->mutex);  \
-       cfi_udelay(usec);  \
-       spin_lock(chip->mutex);  \
-} while (0)
-
-#define INVALIDATE_CACHE_UDELAY(map, chip, cmd_adr, adr, len, usec)  \
-do {  \
-       spin_unlock(chip->mutex);  \
-       INVALIDATE_CACHED_RANGE(map, adr, len);  \
-       cfi_udelay(usec);  \
-       spin_lock(chip->mutex);  \
-} while (0)
+               status = map_read(map, cmd_adr);
+               if (map_word_andequal(map, status, status_OK, status_OK))
+                       break;
+
+               /* OK Still waiting */
+               if (time_after(jiffies, timeo)) {
+                       map_write(map, CMD(0x70), cmd_adr);
+                       chip->state = FL_STATUS;
+                       return -ETIME;
+               }
+
+               /* Latency issues. Drop the lock, wait a while and retry */
+               z++;
+               spin_unlock(chip->mutex);
+               cfi_udelay(1);
+               spin_lock(chip->mutex);
+       }
+
+       if (!z) {
+               if (!--(*chip_op_time))
+                       *chip_op_time = 1;
+       } else if (z > 1)
+               ++(*chip_op_time);
+
+       /* Done and happy. */
+       chip->state = FL_STATUS;
+       return 0;
+}
 
 #endif
 
+#define WAIT_TIMEOUT(map, chip, adr, udelay) \
+       ({ int __udelay = (udelay); \
+          INVAL_CACHE_AND_WAIT(map, chip, adr, 0, 0, &__udelay); })
+
+
 static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t adr, size_t len)
 {
        unsigned long cmd_addr;
@@ -1252,14 +1299,11 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
                                     unsigned long adr, map_word datum, int mode)
 {
        struct cfi_private *cfi = map->fldrv_priv;
-       map_word status, status_OK, write_cmd;
-       unsigned long timeo;
-       int z, ret=0;
+       map_word status, write_cmd;
+       int ret=0;
 
        adr += chip->start;
 
-       /* Let's determine those according to the interleave only once */
-       status_OK = CMD(0x80);
        switch (mode) {
        case FL_WRITING:
                write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0x40) : CMD(0x41);
@@ -1285,57 +1329,17 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
        map_write(map, datum, adr);
        chip->state = mode;
 
-       INVALIDATE_CACHE_UDELAY(map, chip, adr,
-                               adr, map_bankwidth(map),
-                               chip->word_write_time);
-
-       timeo = jiffies + (HZ/2);
-       z = 0;
-       for (;;) {
-               if (chip->state != mode) {
-                       /* Someone's suspended the write. Sleep */
-                       DECLARE_WAITQUEUE(wait, current);
-
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       add_wait_queue(&chip->wq, &wait);
-                       spin_unlock(chip->mutex);
-                       schedule();
-                       remove_wait_queue(&chip->wq, &wait);
-                       timeo = jiffies + (HZ / 2); /* FIXME */
-                       spin_lock(chip->mutex);
-                       continue;
-               }
-
-               status = map_read(map, adr);
-               if (map_word_andequal(map, status, status_OK, status_OK))
-                       break;
-
-               /* OK Still waiting */
-               if (time_after(jiffies, timeo)) {
-                       map_write(map, CMD(0x70), adr);
-                       chip->state = FL_STATUS;
-                       xip_enable(map, chip, adr);
-                       printk(KERN_ERR "%s: word write error (status timeout)\n", map->name);
-                       ret = -EIO;
-                       goto out;
-               }
-
-               /* Latency issues. Drop the lock, wait a while and retry */
-               z++;
-               UDELAY(map, chip, adr, 1);
-       }
-       if (!z) {
-               chip->word_write_time--;
-               if (!chip->word_write_time)
-                       chip->word_write_time = 1;
+       ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
+                                  adr, map_bankwidth(map),
+                                  &chip->word_write_time);
+       if (ret) {
+               xip_enable(map, chip, adr);
+               printk(KERN_ERR "%s: word write error (status timeout)\n", map->name);
+               goto out;
        }
-       if (z > 1)
-               chip->word_write_time++;
-
-       /* Done and happy. */
-       chip->state = FL_STATUS;
 
        /* check for errors */
+       status = map_read(map, adr);
        if (map_word_bitsset(map, status, CMD(0x1a))) {
                unsigned long chipstatus = MERGESTATUS(status);
 
@@ -1452,9 +1456,9 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
                                    unsigned long *pvec_seek, int len)
 {
        struct cfi_private *cfi = map->fldrv_priv;
-       map_word status, status_OK, write_cmd, datum;
-       unsigned long cmd_adr, timeo;
-       int wbufsize, z, ret=0, word_gap, words;
+       map_word status, write_cmd, datum;
+       unsigned long cmd_adr;
+       int ret, wbufsize, word_gap, words;
        const struct kvec *vec;
        unsigned long vec_seek;
 
@@ -1463,7 +1467,6 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
        cmd_adr = adr & ~(wbufsize-1);
 
        /* Let's determine this according to the interleave only once */
-       status_OK = CMD(0x80);
        write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0xe8) : CMD(0xe9);
 
        spin_lock(chip->mutex);
@@ -1477,12 +1480,14 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
        ENABLE_VPP(map);
        xip_disable(map, chip, cmd_adr);
 
-       /* §4.8 of the 28FxxxJ3A datasheet says "Any time SR.4 and/or SR.5 is set
+       /* §4.8 of the 28FxxxJ3A datasheet says "Any time SR.4 and/or SR.5 is set
           [...], the device will not accept any more Write to Buffer commands".
           So we must check here and reset those bits if they're set. Otherwise
           we're just pissing in the wind */
-       if (chip->state != FL_STATUS)
+       if (chip->state != FL_STATUS) {
                map_write(map, CMD(0x70), cmd_adr);
+               chip->state = FL_STATUS;
+       }
        status = map_read(map, cmd_adr);
        if (map_word_bitsset(map, status, CMD(0x30))) {
                xip_enable(map, chip, cmd_adr);
@@ -1493,32 +1498,20 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
        }
 
        chip->state = FL_WRITING_TO_BUFFER;
-
-       z = 0;
-       for (;;) {
-               map_write(map, write_cmd, cmd_adr);
-
+       map_write(map, write_cmd, cmd_adr);
+       ret = WAIT_TIMEOUT(map, chip, cmd_adr, 0);
+       if (ret) {
+               /* Argh. Not ready for write to buffer */
+               map_word Xstatus = map_read(map, cmd_adr);
+               map_write(map, CMD(0x70), cmd_adr);
+               chip->state = FL_STATUS;
                status = map_read(map, cmd_adr);
-               if (map_word_andequal(map, status, status_OK, status_OK))
-                       break;
-
-               UDELAY(map, chip, cmd_adr, 1);
-
-               if (++z > 20) {
-                       /* Argh. Not ready for write to buffer */
-                       map_word Xstatus;
-                       map_write(map, CMD(0x70), cmd_adr);
-                       chip->state = FL_STATUS;
-                       Xstatus = map_read(map, cmd_adr);
-                       /* Odd. Clear status bits */
-                       map_write(map, CMD(0x50), cmd_adr);
-                       map_write(map, CMD(0x70), cmd_adr);
-                       xip_enable(map, chip, cmd_adr);
-                       printk(KERN_ERR "%s: Chip not ready for buffer write. status = %lx, Xstatus = %lx\n",
-                              map->name, status.x[0], Xstatus.x[0]);
-                       ret = -EIO;
-                       goto out;
-               }
+               map_write(map, CMD(0x50), cmd_adr);
+               map_write(map, CMD(0x70), cmd_adr);
+               xip_enable(map, chip, cmd_adr);
+               printk(KERN_ERR "%s: Chip not ready for buffer write. Xstatus = %lx, status = %lx\n",
+                               map->name, Xstatus.x[0], status.x[0]);
+               goto out;
        }
 
        /* Figure out the number of words to write */
@@ -1573,56 +1566,19 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
        map_write(map, CMD(0xd0), cmd_adr);
        chip->state = FL_WRITING;
 
-       INVALIDATE_CACHE_UDELAY(map, chip, cmd_adr,
-                               adr, len,
-                               chip->buffer_write_time);
-
-       timeo = jiffies + (HZ/2);
-       z = 0;
-       for (;;) {
-               if (chip->state != FL_WRITING) {
-                       /* Someone's suspended the write. Sleep */
-                       DECLARE_WAITQUEUE(wait, current);
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       add_wait_queue(&chip->wq, &wait);
-                       spin_unlock(chip->mutex);
-                       schedule();
-                       remove_wait_queue(&chip->wq, &wait);
-                       timeo = jiffies + (HZ / 2); /* FIXME */
-                       spin_lock(chip->mutex);
-                       continue;
-               }
-
-               status = map_read(map, cmd_adr);
-               if (map_word_andequal(map, status, status_OK, status_OK))
-                       break;
-
-               /* OK Still waiting */
-               if (time_after(jiffies, timeo)) {
-                       map_write(map, CMD(0x70), cmd_adr);
-                       chip->state = FL_STATUS;
-                       xip_enable(map, chip, cmd_adr);
-                       printk(KERN_ERR "%s: buffer write error (status timeout)\n", map->name);
-                       ret = -EIO;
-                       goto out;
-               }
-
-               /* Latency issues. Drop the lock, wait a while and retry */
-               z++;
-               UDELAY(map, chip, cmd_adr, 1);
-       }
-       if (!z) {
-               chip->buffer_write_time--;
-               if (!chip->buffer_write_time)
-                       chip->buffer_write_time = 1;
+       ret = INVAL_CACHE_AND_WAIT(map, chip, cmd_adr,
+                                  adr, len,
+                                  &chip->buffer_write_time);
+       if (ret) {
+               map_write(map, CMD(0x70), cmd_adr);
+               chip->state = FL_STATUS;
+               xip_enable(map, chip, cmd_adr);
+               printk(KERN_ERR "%s: buffer write error (status timeout)\n", map->name);
+               goto out;
        }
-       if (z > 1)
-               chip->buffer_write_time++;
-
-       /* Done and happy. */
-       chip->state = FL_STATUS;
 
        /* check for errors */
+       status = map_read(map, cmd_adr);
        if (map_word_bitsset(map, status, CMD(0x1a))) {
                unsigned long chipstatus = MERGESTATUS(status);
 
@@ -1693,6 +1649,11 @@ static int cfi_intelext_writev (struct mtd_info *mtd, const struct kvec *vecs,
                        if (chipnum == cfi->numchips)
                                return 0;
                }
+
+               /* Be nice and reschedule with the chip in a usable state for other
+                  processes. */
+               cond_resched();
+
        } while (len);
 
        return 0;
@@ -1713,17 +1674,12 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
                                      unsigned long adr, int len, void *thunk)
 {
        struct cfi_private *cfi = map->fldrv_priv;
-       map_word status, status_OK;
-       unsigned long timeo;
+       map_word status;
        int retries = 3;
-       DECLARE_WAITQUEUE(wait, current);
-       int ret = 0;
+       int ret;
 
        adr += chip->start;
 
-       /* Let's determine this according to the interleave only once */
-       status_OK = CMD(0x80);
-
  retry:
        spin_lock(chip->mutex);
        ret = get_chip(map, chip, adr, FL_ERASING);
@@ -1745,48 +1701,15 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
        chip->state = FL_ERASING;
        chip->erase_suspended = 0;
 
-       INVALIDATE_CACHE_UDELAY(map, chip, adr,
-                               adr, len,
-                               chip->erase_time*1000/2);
-
-       /* FIXME. Use a timer to check this, and return immediately. */
-       /* Once the state machine's known to be working I'll do that */
-
-       timeo = jiffies + (HZ*20);
-       for (;;) {
-               if (chip->state != FL_ERASING) {
-                       /* Someone's suspended the erase. Sleep */
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       add_wait_queue(&chip->wq, &wait);
-                       spin_unlock(chip->mutex);
-                       schedule();
-                       remove_wait_queue(&chip->wq, &wait);
-                       spin_lock(chip->mutex);
-                       continue;
-               }
-               if (chip->erase_suspended) {
-                       /* This erase was suspended and resumed.
-                          Adjust the timeout */
-                       timeo = jiffies + (HZ*20); /* FIXME */
-                       chip->erase_suspended = 0;
-               }
-
-               status = map_read(map, adr);
-               if (map_word_andequal(map, status, status_OK, status_OK))
-                       break;
-
-               /* OK Still waiting */
-               if (time_after(jiffies, timeo)) {
-                       map_write(map, CMD(0x70), adr);
-                       chip->state = FL_STATUS;
-                       xip_enable(map, chip, adr);
-                       printk(KERN_ERR "%s: block erase error: (status timeout)\n", map->name);
-                       ret = -EIO;
-                       goto out;
-               }
-
-               /* Latency issues. Drop the lock, wait a while and retry */
-               UDELAY(map, chip, adr, 1000000/HZ);
+       ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
+                                  adr, len,
+                                  &chip->erase_time);
+       if (ret) {
+               map_write(map, CMD(0x70), adr);
+               chip->state = FL_STATUS;
+               xip_enable(map, chip, adr);
+               printk(KERN_ERR "%s: block erase error: (status timeout)\n", map->name);
+               goto out;
        }
 
        /* We've broken this before. It doesn't hurt to be safe */
@@ -1815,7 +1738,6 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
                        ret = -EIO;
                } else if (chipstatus & 0x20 && retries--) {
                        printk(KERN_DEBUG "block erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);
-                       timeo = jiffies + HZ;
                        put_chip(map, chip, adr);
                        spin_unlock(chip->mutex);
                        goto retry;
@@ -1921,15 +1843,11 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
 {
        struct cfi_private *cfi = map->fldrv_priv;
        struct cfi_pri_intelext *extp = cfi->cmdset_priv;
-       map_word status, status_OK;
-       unsigned long timeo = jiffies + HZ;
+       int udelay;
        int ret;
 
        adr += chip->start;
 
-       /* Let's determine this according to the interleave only once */
-       status_OK = CMD(0x80);
-
        spin_lock(chip->mutex);
        ret = get_chip(map, chip, adr, FL_LOCKING);
        if (ret) {
@@ -1954,41 +1872,21 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
         * If Instant Individual Block Locking supported then no need
         * to delay.
         */
+       udelay = (!extp || !(extp->FeatureSupport & (1 << 5))) ? 1000000/HZ : 0;
 
-       if (!extp || !(extp->FeatureSupport & (1 << 5)))
-               UDELAY(map, chip, adr, 1000000/HZ);
-
-       /* FIXME. Use a timer to check this, and return immediately. */
-       /* Once the state machine's known to be working I'll do that */
-
-       timeo = jiffies + (HZ*20);
-       for (;;) {
-
-               status = map_read(map, adr);
-               if (map_word_andequal(map, status, status_OK, status_OK))
-                       break;
-
-               /* OK Still waiting */
-               if (time_after(jiffies, timeo)) {
-                       map_write(map, CMD(0x70), adr);
-                       chip->state = FL_STATUS;
-                       xip_enable(map, chip, adr);
-                       printk(KERN_ERR "%s: block unlock error: (status timeout)\n", map->name);
-                       put_chip(map, chip, adr);
-                       spin_unlock(chip->mutex);
-                       return -EIO;
-               }
-
-               /* Latency issues. Drop the lock, wait a while and retry */
-               UDELAY(map, chip, adr, 1);
+       ret = WAIT_TIMEOUT(map, chip, adr, udelay);
+       if (ret) {
+               map_write(map, CMD(0x70), adr);
+               chip->state = FL_STATUS;
+               xip_enable(map, chip, adr);
+               printk(KERN_ERR "%s: block unlock error: (status timeout)\n", map->name);
+               goto out;
        }
 
-       /* Done and happy. */
-       chip->state = FL_STATUS;
        xip_enable(map, chip, adr);
-       put_chip(map, chip, adr);
+out:   put_chip(map, chip, adr);
        spin_unlock(chip->mutex);
-       return 0;
+       return ret;
 }
 
 static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
@@ -2445,28 +2343,8 @@ static void cfi_intelext_destroy(struct mtd_info *mtd)
        kfree(mtd->eraseregions);
 }
 
-static char im_name_0001[] = "cfi_cmdset_0001";
-static char im_name_0003[] = "cfi_cmdset_0003";
-static char im_name_0200[] = "cfi_cmdset_0200";
-
-static int __init cfi_intelext_init(void)
-{
-       inter_module_register(im_name_0001, THIS_MODULE, &cfi_cmdset_0001);
-       inter_module_register(im_name_0003, THIS_MODULE, &cfi_cmdset_0001);
-       inter_module_register(im_name_0200, THIS_MODULE, &cfi_cmdset_0001);
-       return 0;
-}
-
-static void __exit cfi_intelext_exit(void)
-{
-       inter_module_unregister(im_name_0001);
-       inter_module_unregister(im_name_0003);
-       inter_module_unregister(im_name_0200);
-}
-
-module_init(cfi_intelext_init);
-module_exit(cfi_intelext_exit);
-
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org> et al.");
 MODULE_DESCRIPTION("MTD chip driver for Intel/Sharp flash chips");
+MODULE_ALIAS("cfi_cmdset_0003");
+MODULE_ALIAS("cfi_cmdset_0200");
index aed10bd..1e01ad3 100644 (file)
@@ -236,6 +236,7 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
        mtd->resume  = cfi_amdstd_resume;
        mtd->flags   = MTD_CAP_NORFLASH;
        mtd->name    = map->name;
+       mtd->writesize = 1;
 
        if (cfi->cfi_mode==CFI_MODE_CFI){
                unsigned char bootloc;
@@ -326,7 +327,7 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
 
        return cfi_amdstd_setup(mtd);
 }
-
+EXPORT_SYMBOL_GPL(cfi_cmdset_0002);
 
 static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd)
 {
@@ -1758,25 +1759,6 @@ static void cfi_amdstd_destroy(struct mtd_info *mtd)
        kfree(mtd->eraseregions);
 }
 
-static char im_name[]="cfi_cmdset_0002";
-
-
-static int __init cfi_amdstd_init(void)
-{
-       inter_module_register(im_name, THIS_MODULE, &cfi_cmdset_0002);
-       return 0;
-}
-
-
-static void __exit cfi_amdstd_exit(void)
-{
-       inter_module_unregister(im_name);
-}
-
-
-module_init(cfi_amdstd_init);
-module_exit(cfi_amdstd_exit);
-
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Crossnet Co. <info@crossnet.co.jp> et al.");
 MODULE_DESCRIPTION("MTD chip driver for AMD/Fujitsu flash chips");
index 0807c1c..fae70a5 100644 (file)
@@ -162,6 +162,7 @@ struct mtd_info *cfi_cmdset_0020(struct map_info *map, int primary)
 
        return cfi_staa_setup(map);
 }
+EXPORT_SYMBOL_GPL(cfi_cmdset_0020);
 
 static struct mtd_info *cfi_staa_setup(struct map_info *map)
 {
@@ -237,9 +238,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
        mtd->unlock = cfi_staa_unlock;
        mtd->suspend = cfi_staa_suspend;
        mtd->resume = cfi_staa_resume;
-       mtd->flags = MTD_CAP_NORFLASH;
-       mtd->flags |= MTD_ECC; /* FIXME: Not all STMicro flashes have this */
-       mtd->eccsize = 8; /* FIXME: Should be 0 for STMicro flashes w/out ECC */
+       mtd->flags = MTD_CAP_NORFLASH & ~MTD_BIT_WRITEABLE;
+       mtd->writesize = 8; /* FIXME: Should be 0 for STMicro flashes w/out ECC */
        map->fldrv = &cfi_staa_chipdrv;
        __module_get(THIS_MODULE);
        mtd->name = map->name;
@@ -1410,20 +1410,4 @@ static void cfi_staa_destroy(struct mtd_info *mtd)
        kfree(cfi);
 }
 
-static char im_name[]="cfi_cmdset_0020";
-
-static int __init cfi_staa_init(void)
-{
-       inter_module_register(im_name, THIS_MODULE, &cfi_cmdset_0020);
-       return 0;
-}
-
-static void __exit cfi_staa_exit(void)
-{
-       inter_module_unregister(im_name);
-}
-
-module_init(cfi_staa_init);
-module_exit(cfi_staa_exit);
-
 MODULE_LICENSE("GPL");
index e636aa8..4bf9f8c 100644 (file)
@@ -349,12 +349,12 @@ static void print_cfi_ident(struct cfi_ident *cfip)
        else
                printk("No Vpp line\n");
 
-       printk("Typical byte/word write timeout: %d µs\n", 1<<cfip->WordWriteTimeoutTyp);
-       printk("Maximum byte/word write timeout: %d µs\n", (1<<cfip->WordWriteTimeoutMax) * (1<<cfip->WordWriteTimeoutTyp));
+       printk("Typical byte/word write timeout: %d µs\n", 1<<cfip->WordWriteTimeoutTyp);
+       printk("Maximum byte/word write timeout: %d µs\n", (1<<cfip->WordWriteTimeoutMax) * (1<<cfip->WordWriteTimeoutTyp));
 
        if (cfip->BufWriteTimeoutTyp || cfip->BufWriteTimeoutMax) {
-               printk("Typical full buffer write timeout: %d µs\n", 1<<cfip->BufWriteTimeoutTyp);
-               printk("Maximum full buffer write timeout: %d µs\n", (1<<cfip->BufWriteTimeoutMax) * (1<<cfip->BufWriteTimeoutTyp));
+               printk("Typical full buffer write timeout: %d µs\n", 1<<cfip->BufWriteTimeoutTyp);
+               printk("Maximum full buffer write timeout: %d µs\n", (1<<cfip->BufWriteTimeoutMax) * (1<<cfip->BufWriteTimeoutTyp));
        }
        else
                printk("Full buffer write not supported\n");
index 41bd59d..cdb0f59 100644 (file)
@@ -37,8 +37,15 @@ struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp)
        if (!mtd)
                mtd = check_cmd_set(map, 0); /* Then the secondary */
 
-       if (mtd)
+       if (mtd) {
+               if (mtd->size > map->size) {
+                       printk(KERN_WARNING "Reducing visibility of %ldKiB chip to %ldKiB\n",
+                              (unsigned long)mtd->size >> 10, 
+                              (unsigned long)map->size >> 10);
+                       mtd->size = map->size;
+               }
                return mtd;
+       }
 
        printk(KERN_WARNING"gen_probe: No supported Vendor Command Set found\n");
 
@@ -100,7 +107,12 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
         * Align bitmap storage size to full byte.
         */
        max_chips = map->size >> cfi.chipshift;
-       mapsize = (max_chips / 8) + ((max_chips % 8) ? 1 : 0);
+       if (!max_chips) {
+               printk(KERN_WARNING "NOR chip too large to fit in mapping. Attempting to cope...\n");
+               max_chips = 1;
+       }
+
+       mapsize = (max_chips + BITS_PER_LONG-1) / BITS_PER_LONG;
        chip_map = kmalloc(mapsize, GFP_KERNEL);
        if (!chip_map) {
                printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name);
@@ -194,25 +206,28 @@ static inline struct mtd_info *cfi_cmdset_unknown(struct map_info *map,
 {
        struct cfi_private *cfi = map->fldrv_priv;
        __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID;
-#if defined(CONFIG_MODULES) && defined(HAVE_INTER_MODULE)
-       char probename[32];
+#ifdef CONFIG_MODULES
+       char probename[16+sizeof(MODULE_SYMBOL_PREFIX)];
        cfi_cmdset_fn_t *probe_function;
 
-       sprintf(probename, "cfi_cmdset_%4.4X", type);
+       sprintf(probename, MODULE_SYMBOL_PREFIX "cfi_cmdset_%4.4X", type);
 
-       probe_function = inter_module_get_request(probename, probename);
+       probe_function = __symbol_get(probename);
+       if (!probe_function) {
+               request_module(probename + sizeof(MODULE_SYMBOL_PREFIX) - 1);
+               probe_function = __symbol_get(probename);
+       }
 
        if (probe_function) {
                struct mtd_info *mtd;
 
                mtd = (*probe_function)(map, primary);
                /* If it was happy, it'll have increased its own use count */
-               inter_module_put(probename);
+               symbol_put_addr(probe_function);
                return mtd;
        }
 #endif
-       printk(KERN_NOTICE "Support for command set %04X not present\n",
-              type);
+       printk(KERN_NOTICE "Support for command set %04X not present\n", type);
 
        return NULL;
 }
@@ -226,12 +241,8 @@ static struct mtd_info *check_cmd_set(struct map_info *map, int primary)
                return NULL;
 
        switch(type){
-               /* Urgh. Ifdefs. The version with weak symbols was
-                * _much_ nicer. Shame it didn't seem to work on
-                * anything but x86, really.
-                * But we can't rely in inter_module_get() because
-                * that'd mean we depend on link order.
-                */
+               /* We need these for the !CONFIG_MODULES case,
+                  because symbol_get() doesn't work there */
 #ifdef CONFIG_MTD_CFI_INTELEXT
        case 0x0001:
        case 0x0003:
@@ -246,9 +257,9 @@ static struct mtd_info *check_cmd_set(struct map_info *map, int primary)
         case 0x0020:
                return cfi_cmdset_0020(map, primary);
 #endif
+       default:
+               return cfi_cmdset_unknown(map, primary);
        }
-
-       return cfi_cmdset_unknown(map, primary);
 }
 
 MODULE_LICENSE("GPL");
index bd2e876..7639257 100644 (file)
@@ -70,7 +70,7 @@ static struct mtd_info *map_ram_probe(struct map_info *map)
        mtd->read = mapram_read;
        mtd->write = mapram_write;
        mtd->sync = mapram_nop;
-       mtd->flags = MTD_CAP_RAM | MTD_VOLATILE;
+       mtd->flags = MTD_CAP_RAM;
 
        mtd->erasesize = PAGE_SIZE;
        while(mtd->size & (mtd->erasesize - 1))
index 624c12c..bc6ee9e 100644 (file)
@@ -46,9 +46,7 @@ static struct mtd_info *map_rom_probe(struct map_info *map)
        mtd->write = maprom_write;
        mtd->sync = maprom_nop;
        mtd->flags = MTD_CAP_ROM;
-       mtd->erasesize = 131072;
-       while(mtd->size & (mtd->erasesize - 1))
-               mtd->erasesize >>= 1;
+       mtd->erasesize = map->size;
 
        __module_get(THIS_MODULE);
        return mtd;
index 3cc0b23..967abbe 100644 (file)
@@ -140,6 +140,7 @@ static struct mtd_info *sharp_probe(struct map_info *map)
        mtd->suspend = sharp_suspend;
        mtd->resume = sharp_resume;
        mtd->flags = MTD_CAP_NORFLASH;
+       mtd->writesize = 1;
        mtd->name = map->name;
 
        memset(sharp, 0, sizeof(*sharp));
index 7fac438..16c02b5 100644 (file)
@@ -47,6 +47,11 @@ config MTD_MS02NV
          accelerator.  Say Y here if you have a DECstation 5000/2x0 or a
          DECsystem 5900 equipped with such a module.
 
+         If you want to compile this driver as a module ( = code which can be
+         inserted in and removed from the running kernel whenever you want),
+         say M here and read <file:Documentation/modules.txt>.  The module will
+         be called ms02-nv.o.
+
 config MTD_DATAFLASH
        tristate "Support for AT45xxx DataFlash"
        depends on MTD && SPI_MASTER && EXPERIMENTAL
@@ -209,7 +214,6 @@ config MTD_DOC2001PLUS
 config MTD_DOCPROBE
        tristate
        select MTD_DOCECC
-       select OBSOLETE_INTERMODULE
 
 config MTD_DOCECC
        tristate
index b657367..0f788d5 100644 (file)
@@ -3,13 +3,6 @@
 #
 # $Id: Makefile.common,v 1.7 2004/12/22 17:51:15 joern Exp $
 
-#                       *** BIG UGLY NOTE ***
-#
-# The removal of get_module_symbol() and replacement with
-# inter_module_register() et al has introduced a link order dependency
-# here where previously there was none.  We now have to ensure that
-# doc200[01].o are linked before docprobe.o
-
 obj-$(CONFIG_MTD_DOC2000)      += doc2000.o
 obj-$(CONFIG_MTD_DOC2001)      += doc2001.o
 obj-$(CONFIG_MTD_DOC2001PLUS)  += doc2001plus.o
index 4160b83..0d98c22 100644 (file)
@@ -4,7 +4,7 @@
  * block2mtd.c - create an mtd from a block device
  *
  * Copyright (C) 2001,2002     Simon Evans <spse@secret.org.uk>
- * Copyright (C) 2004,2005     Jörn Engel <joern@wh.fh-wedel.de>
+ * Copyright (C) 2004-2006     Jörn Engel <joern@wh.fh-wedel.de>
  *
  * Licence: GPL
  */
@@ -331,7 +331,6 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
        dev->mtd.writev = default_mtd_writev;
        dev->mtd.sync = block2mtd_sync;
        dev->mtd.read = block2mtd_read;
-       dev->mtd.readv = default_mtd_readv;
        dev->mtd.priv = dev;
        dev->mtd.owner = THIS_MODULE;
 
@@ -351,6 +350,12 @@ devinit_err:
 }
 
 
+/* This function works similar to reguler strtoul.  In addition, it
+ * allows some suffixes for a more human-readable number format:
+ * ki, Ki, kiB, KiB    - multiply result with 1024
+ * Mi, MiB             - multiply result with 1024^2
+ * Gi, GiB             - multiply result with 1024^3
+ */
 static int ustrtoul(const char *cp, char **endp, unsigned int base)
 {
        unsigned long result = simple_strtoul(cp, endp, base);
@@ -359,11 +364,16 @@ static int ustrtoul(const char *cp, char **endp, unsigned int base)
                result *= 1024;
        case 'M':
                result *= 1024;
+       case 'K':
        case 'k':
                result *= 1024;
        /* By dwmw2 editorial decree, "ki", "Mi" or "Gi" are to be used. */
-               if ((*endp)[1] == 'i')
-                       (*endp) += 2;
+               if ((*endp)[1] == 'i') {
+                       if ((*endp)[2] == 'B')
+                               (*endp) += 3;
+                       else
+                               (*endp) += 2;
+               }
        }
        return result;
 }
@@ -418,7 +428,8 @@ static inline void kill_final_newline(char *str)
 
 static int block2mtd_setup(const char *val, struct kernel_param *kp)
 {
-       char buf[80+12], *str=buf; /* 80 for device, 12 for erase size */
+       char buf[80+12]; /* 80 for device, 12 for erase size */
+       char *str = buf;
        char *token[2];
        char *name;
        size_t erase_size = PAGE_SIZE;
@@ -430,7 +441,7 @@ static int block2mtd_setup(const char *val, struct kernel_param *kp)
        strcpy(str, val);
        kill_final_newline(str);
 
-       for (i=0; i<2; i++)
+       for (i = 0; i < 2; i++)
                token[i] = strsep(&str, ",");
 
        if (str)
@@ -449,8 +460,10 @@ static int block2mtd_setup(const char *val, struct kernel_param *kp)
 
        if (token[1]) {
                ret = parse_num(&erase_size, token[1]);
-               if (ret)
+               if (ret) {
+                       kfree(name);
                        parse_err("illegal erase size");
+               }
        }
 
        add_device(name, erase_size);
index 23e7a5c..c54e404 100644 (file)
@@ -59,13 +59,10 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
                        size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
 static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
                         size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
-static int doc_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
-                         unsigned long count, loff_t to, size_t *retlen,
-                         u_char *eccbuf, struct nand_oobinfo *oobsel);
-static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                       size_t *retlen, u_char *buf);
-static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                        size_t *retlen, const u_char *buf);
+static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
+                       struct mtd_oob_ops *ops);
+static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
+                        struct mtd_oob_ops *ops);
 static int doc_write_oob_nolock(struct mtd_info *mtd, loff_t ofs, size_t len,
                         size_t *retlen, const u_char *buf);
 static int doc_erase (struct mtd_info *mtd, struct erase_info *instr);
@@ -517,16 +514,9 @@ static int DoC2k_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2)
        return retval;
 }
 
-static const char im_name[] = "DoC2k_init";
-
-/* This routine is made available to other mtd code via
- * inter_module_register.  It must only be accessed through
- * inter_module_get which will bump the use count of this module.  The
- * addresses passed back in mtd are valid as long as the use count of
- * this module is non-zero, i.e. between inter_module_get and
- * inter_module_put.  Keith Owens <kaos@ocs.com.au> 29 Oct 2000.
- */
-static void DoC2k_init(struct mtd_info *mtd)
+/* This routine is found from the docprobe code by symbol_get(),
+ * which will bump the use count of this module. */
+void DoC2k_init(struct mtd_info *mtd)
 {
        struct DiskOnChip *this = mtd->priv;
        struct DiskOnChip *old = NULL;
@@ -586,7 +576,7 @@ static void DoC2k_init(struct mtd_info *mtd)
        mtd->ecctype = MTD_ECC_RS_DiskOnChip;
        mtd->size = 0;
        mtd->erasesize = 0;
-       mtd->oobblock = 512;
+       mtd->writesize = 512;
        mtd->oobsize = 16;
        mtd->owner = THIS_MODULE;
        mtd->erase = doc_erase;
@@ -594,9 +584,6 @@ static void DoC2k_init(struct mtd_info *mtd)
        mtd->unpoint = NULL;
        mtd->read = doc_read;
        mtd->write = doc_write;
-       mtd->read_ecc = doc_read_ecc;
-       mtd->write_ecc = doc_write_ecc;
-       mtd->writev_ecc = doc_writev_ecc;
        mtd->read_oob = doc_read_oob;
        mtd->write_oob = doc_write_oob;
        mtd->sync = NULL;
@@ -623,6 +610,7 @@ static void DoC2k_init(struct mtd_info *mtd)
                return;
        }
 }
+EXPORT_SYMBOL_GPL(DoC2k_init);
 
 static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
                    size_t * retlen, u_char * buf)
@@ -971,72 +959,18 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
        return 0;
 }
 
-static int doc_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
-                         unsigned long count, loff_t to, size_t *retlen,
-                         u_char *eccbuf, struct nand_oobinfo *oobsel)
-{
-       static char static_buf[512];
-       static DEFINE_MUTEX(writev_buf_mutex);
-
-       size_t totretlen = 0;
-       size_t thisvecofs = 0;
-       int ret= 0;
-
-       mutex_lock(&writev_buf_mutex);
-
-       while(count) {
-               size_t thislen, thisretlen;
-               unsigned char *buf;
-
-               buf = vecs->iov_base + thisvecofs;
-               thislen = vecs->iov_len - thisvecofs;
-
-
-               if (thislen >= 512) {
-                       thislen = thislen & ~(512-1);
-                       thisvecofs += thislen;
-               } else {
-                       /* Not enough to fill a page. Copy into buf */
-                       memcpy(static_buf, buf, thislen);
-                       buf = &static_buf[thislen];
-
-                       while(count && thislen < 512) {
-                               vecs++;
-                               count--;
-                               thisvecofs = min((512-thislen), vecs->iov_len);
-                               memcpy(buf, vecs->iov_base, thisvecofs);
-                               thislen += thisvecofs;
-                               buf += thisvecofs;
-                       }
-                       buf = static_buf;
-               }
-               if (count && thisvecofs == vecs->iov_len) {
-                       thisvecofs = 0;
-                       vecs++;
-                       count--;
-               }
-               ret = doc_write_ecc(mtd, to, thislen, &thisretlen, buf, eccbuf, oobsel);
-
-               totretlen += thisretlen;
-
-               if (ret || thisretlen != thislen)
-                       break;
-
-               to += thislen;
-       }
-
-       mutex_unlock(&writev_buf_mutex);
-       *retlen = totretlen;
-       return ret;
-}
-
-
-static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                       size_t * retlen, u_char * buf)
+static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
+                       struct mtd_oob_ops *ops)
 {
        struct DiskOnChip *this = mtd->priv;
        int len256 = 0, ret;
        struct Nand *mychip;
+       uint8_t *buf = ops->oobbuf;
+       size_t len = ops->len;
+
+       BUG_ON(ops->mode != MTD_OOB_PLACE);
+
+       ofs += ops->ooboffs;
 
        mutex_lock(&this->lock);
 
@@ -1077,7 +1011,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
 
        DoC_ReadBuf(this, &buf[len256], len - len256);
 
-       *retlen = len;
+       ops->retlen = len;
        /* Reading the full OOB data drops us off of the end of the page,
          * causing the flash device to go into busy mode, so we need
          * to wait until ready 11.4.1 and Toshiba TC58256FT docs */
@@ -1192,17 +1126,20 @@ static int doc_write_oob_nolock(struct mtd_info *mtd, loff_t ofs, size_t len,
 
 }
 
-static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                        size_t * retlen, const u_char * buf)
+static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
+                        struct mtd_oob_ops *ops)
 {
-       struct DiskOnChip *this = mtd->priv;
-       int ret;
+       struct DiskOnChip *this = mtd->priv;
+       int ret;
 
-       mutex_lock(&this->lock);
-       ret = doc_write_oob_nolock(mtd, ofs, len, retlen, buf);
+       BUG_ON(ops->mode != MTD_OOB_PLACE);
+
+       mutex_lock(&this->lock);
+       ret = doc_write_oob_nolock(mtd, ofs + ops->ooboffs, ops->len,
+                                  &ops->retlen, ops->oobbuf);
 
-       mutex_unlock(&this->lock);
-       return ret;
+       mutex_unlock(&this->lock);
+       return ret;
 }
 
 static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
@@ -1277,12 +1214,6 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
  *
  ****************************************************************************/
 
-static int __init init_doc2000(void)
-{
-       inter_module_register(im_name, THIS_MODULE, &DoC2k_init);
-       return 0;
-}
-
 static void __exit cleanup_doc2000(void)
 {
        struct mtd_info *mtd;
@@ -1298,11 +1229,9 @@ static void __exit cleanup_doc2000(void)
                kfree(this->chips);
                kfree(mtd);
        }
-       inter_module_unregister(im_name);
 }
 
 module_exit(cleanup_doc2000);
-module_init(init_doc2000);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org> et al.");
index 681a9c7..0cf022a 100644 (file)
@@ -43,10 +43,10 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
 static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
                         size_t *retlen, const u_char *buf, u_char *eccbuf,
                         struct nand_oobinfo *oobsel);
-static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                       size_t *retlen, u_char *buf);
-static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                        size_t *retlen, const u_char *buf);
+static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
+                       struct mtd_oob_ops *ops);
+static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
+                        struct mtd_oob_ops *ops);
 static int doc_erase (struct mtd_info *mtd, struct erase_info *instr);
 
 static struct mtd_info *docmillist = NULL;
@@ -324,16 +324,9 @@ static int DoCMil_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2)
        return retval;
 }
 
-static const char im_name[] = "DoCMil_init";
-
-/* This routine is made available to other mtd code via
- * inter_module_register.  It must only be accessed through
- * inter_module_get which will bump the use count of this module.  The
- * addresses passed back in mtd are valid as long as the use count of
- * this module is non-zero, i.e. between inter_module_get and
- * inter_module_put.  Keith Owens <kaos@ocs.com.au> 29 Oct 2000.
- */
-static void DoCMil_init(struct mtd_info *mtd)
+/* This routine is found from the docprobe code by symbol_get(),
+ * which will bump the use count of this module. */
+void DoCMil_init(struct mtd_info *mtd)
 {
        struct DiskOnChip *this = mtd->priv;
        struct DiskOnChip *old = NULL;
@@ -368,7 +361,7 @@ static void DoCMil_init(struct mtd_info *mtd)
        /* FIXME: erase size is not always 8KiB */
        mtd->erasesize = 0x2000;
 
-       mtd->oobblock = 512;
+       mtd->writesize = 512;
        mtd->oobsize = 16;
        mtd->owner = THIS_MODULE;
        mtd->erase = doc_erase;
@@ -376,8 +369,6 @@ static void DoCMil_init(struct mtd_info *mtd)
        mtd->unpoint = NULL;
        mtd->read = doc_read;
        mtd->write = doc_write;
-       mtd->read_ecc = doc_read_ecc;
-       mtd->write_ecc = doc_write_ecc;
        mtd->read_oob = doc_read_oob;
        mtd->write_oob = doc_write_oob;
        mtd->sync = NULL;
@@ -401,6 +392,7 @@ static void DoCMil_init(struct mtd_info *mtd)
                return;
        }
 }
+EXPORT_SYMBOL_GPL(DoCMil_init);
 
 static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
                     size_t *retlen, u_char *buf)
@@ -670,8 +662,8 @@ static int doc_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
        return ret;
 }
 
-static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                       size_t *retlen, u_char *buf)
+static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
+                       struct mtd_oob_ops *ops)
 {
 #ifndef USE_MEMCPY
        int i;
@@ -680,6 +672,12 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
        struct DiskOnChip *this = mtd->priv;
        void __iomem *docptr = this->virtadr;
        struct Nand *mychip = &this->chips[ofs >> this->chipshift];
+       uint8_t *buf = ops->oobbuf;
+       size_t len = ops->len;
+
+       BUG_ON(ops->mode != MTD_OOB_PLACE);
+
+       ofs += ops->ooboffs;
 
        /* Find the chip which is to be used and select it */
        if (this->curfloor != mychip->floor) {
@@ -716,13 +714,13 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
 #endif
        buf[len - 1] = ReadDOC(docptr, LastDataRead);
 
-       *retlen = len;
+       ops->retlen = len;
 
        return 0;
 }
 
-static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                        size_t *retlen, const u_char *buf)
+static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
+                        struct mtd_oob_ops *ops)
 {
 #ifndef USE_MEMCPY
        int i;
@@ -732,6 +730,12 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
        struct DiskOnChip *this = mtd->priv;
        void __iomem *docptr = this->virtadr;
        struct Nand *mychip = &this->chips[ofs >> this->chipshift];
+       uint8_t *buf = ops->oobbuf;
+       size_t len = ops->len;
+
+       BUG_ON(ops->mode != MTD_OOB_PLACE);
+
+       ofs += ops->ooboffs;
 
        /* Find the chip which is to be used and select it */
        if (this->curfloor != mychip->floor) {
@@ -783,12 +787,12 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
        if (ReadDOC(docptr, Mil_CDSN_IO) & 1) {
                printk("Error programming oob data\n");
                /* FIXME: implement Bad Block Replacement (in nftl.c ??) */
-               *retlen = 0;
+               ops->retlen = 0;
                ret = -EIO;
        }
        dummy = ReadDOC(docptr, LastDataRead);
 
-       *retlen = len;
+       ops->retlen = len;
 
        return ret;
 }
@@ -856,12 +860,6 @@ int doc_erase (struct mtd_info *mtd, struct erase_info *instr)
  *
  ****************************************************************************/
 
-static int __init init_doc2001(void)
-{
-       inter_module_register(im_name, THIS_MODULE, &DoCMil_init);
-       return 0;
-}
-
 static void __exit cleanup_doc2001(void)
 {
        struct mtd_info *mtd;
@@ -877,11 +875,9 @@ static void __exit cleanup_doc2001(void)
                kfree(this->chips);
                kfree(mtd);
        }
-       inter_module_unregister(im_name);
 }
 
 module_exit(cleanup_doc2001);
-module_init(init_doc2001);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org> et al.");
index 5f57f29..66cb1e5 100644 (file)
@@ -47,10 +47,10 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
 static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
                size_t *retlen, const u_char *buf, u_char *eccbuf,
                struct nand_oobinfo *oobsel);
-static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-               size_t *retlen, u_char *buf);
-static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-               size_t *retlen, const u_char *buf);
+static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
+                       struct mtd_oob_ops *ops);
+static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
+                        struct mtd_oob_ops *ops);
 static int doc_erase (struct mtd_info *mtd, struct erase_info *instr);
 
 static struct mtd_info *docmilpluslist = NULL;
@@ -447,16 +447,9 @@ static int DoCMilPlus_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2)
        return retval;
 }
 
-static const char im_name[] = "DoCMilPlus_init";
-
-/* This routine is made available to other mtd code via
- * inter_module_register.  It must only be accessed through
- * inter_module_get which will bump the use count of this module.  The
- * addresses passed back in mtd are valid as long as the use count of
- * this module is non-zero, i.e. between inter_module_get and
- * inter_module_put.  Keith Owens <kaos@ocs.com.au> 29 Oct 2000.
- */
-static void DoCMilPlus_init(struct mtd_info *mtd)
+/* This routine is found from the docprobe code by symbol_get(),
+ * which will bump the use count of this module. */
+void DoCMilPlus_init(struct mtd_info *mtd)
 {
        struct DiskOnChip *this = mtd->priv;
        struct DiskOnChip *old = NULL;
@@ -490,7 +483,7 @@ static void DoCMilPlus_init(struct mtd_info *mtd)
        mtd->size = 0;
 
        mtd->erasesize = 0;
-       mtd->oobblock = 512;
+       mtd->writesize = 512;
        mtd->oobsize = 16;
        mtd->owner = THIS_MODULE;
        mtd->erase = doc_erase;
@@ -498,8 +491,6 @@ static void DoCMilPlus_init(struct mtd_info *mtd)
        mtd->unpoint = NULL;
        mtd->read = doc_read;
        mtd->write = doc_write;
-       mtd->read_ecc = doc_read_ecc;
-       mtd->write_ecc = doc_write_ecc;
        mtd->read_oob = doc_read_oob;
        mtd->write_oob = doc_write_oob;
        mtd->sync = NULL;
@@ -524,6 +515,7 @@ static void DoCMilPlus_init(struct mtd_info *mtd)
                return;
        }
 }
+EXPORT_SYMBOL_GPL(DoCMilPlus_init);
 
 #if 0
 static int doc_dumpblk(struct mtd_info *mtd, loff_t from)
@@ -876,14 +868,20 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
        return ret;
 }
 
-static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                       size_t *retlen, u_char *buf)
+static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
+                       struct mtd_oob_ops *ops)
 {
        loff_t fofs, base;
        struct DiskOnChip *this = mtd->priv;
        void __iomem * docptr = this->virtadr;
        struct Nand *mychip = &this->chips[ofs >> this->chipshift];
        size_t i, size, got, want;
+       uint8_t *buf = ops->oobbuf;
+       size_t len = ops->len;
+
+       BUG_ON(ops->mode != MTD_OOB_PLACE);
+
+       ofs += ops->ooboffs;
 
        DoC_CheckASIC(docptr);
 
@@ -949,12 +947,12 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
        /* Disable flash internally */
        WriteDOC(0, docptr, Mplus_FlashSelect);
 
-       *retlen = len;
+       ops->retlen = len;
        return 0;
 }
 
-static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
-                        size_t *retlen, const u_char *buf)
+static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
+                        struct mtd_oob_ops *ops)
 {
        volatile char dummy;
        loff_t fofs, base;
@@ -963,6 +961,12 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
        struct Nand *mychip = &this->chips[ofs >> this->chipshift];
        size_t i, size, got, want;
        int ret = 0;
+       uint8_t *buf = ops->oobbuf;
+       size_t len = ops->len;
+
+       BUG_ON(ops->mode != MTD_OOB_PLACE);
+
+       ofs += ops->ooboffs;
 
        DoC_CheckASIC(docptr);
 
@@ -1038,7 +1042,7 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
                        printk("MTD: Error 0x%x programming oob at 0x%x\n",
                                dummy, (int)ofs);
                        /* FIXME: implement Bad Block Replacement */
-                       *retlen = 0;
+                       ops->retlen = 0;
                        ret = -EIO;
                }
                dummy = ReadDOC(docptr, Mplus_LastDataRead);
@@ -1051,7 +1055,7 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
        /* Disable flash internally */
        WriteDOC(0, docptr, Mplus_FlashSelect);
 
-       *retlen = len;
+       ops->retlen = len;
        return ret;
 }
 
@@ -1122,12 +1126,6 @@ int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
  *
  ****************************************************************************/
 
-static int __init init_doc2001plus(void)
-{
-       inter_module_register(im_name, THIS_MODULE, &DoCMilPlus_init);
-       return 0;
-}
-
 static void __exit cleanup_doc2001plus(void)
 {
        struct mtd_info *mtd;
@@ -1143,11 +1141,9 @@ static void __exit cleanup_doc2001plus(void)
                kfree(this->chips);
                kfree(mtd);
        }
-       inter_module_unregister(im_name);
 }
 
 module_exit(cleanup_doc2001plus);
-module_init(init_doc2001plus);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com> et al.");
index 13178b9..593bb03 100644 (file)
@@ -231,6 +231,10 @@ static inline int __init doccheck(void __iomem *potential, unsigned long physadr
 
 static int docfound;
 
+extern void DoC2k_init(struct mtd_info *);
+extern void DoCMil_init(struct mtd_info *);
+extern void DoCMilPlus_init(struct mtd_info *);
+
 static void __init DoC_Probe(unsigned long physadr)
 {
        void __iomem *docptr;
@@ -239,8 +243,6 @@ static void __init DoC_Probe(unsigned long physadr)
        int ChipID;
        char namebuf[15];
        char *name = namebuf;
-       char *im_funcname = NULL;
-       char *im_modname = NULL;
        void (*initroutine)(struct mtd_info *) = NULL;
 
        docptr = ioremap(physadr, DOC_IOREMAP_LEN);
@@ -278,41 +280,33 @@ static void __init DoC_Probe(unsigned long physadr)
                switch(ChipID) {
                case DOC_ChipID_Doc2kTSOP:
                        name="2000 TSOP";
-                       im_funcname = "DoC2k_init";
-                       im_modname = "doc2000";
+                       initroutine = symbol_request(DoC2k_init);
                        break;
 
                case DOC_ChipID_Doc2k:
                        name="2000";
-                       im_funcname = "DoC2k_init";
-                       im_modname = "doc2000";
+                       initroutine = symbol_request(DoC2k_init);
                        break;
 
                case DOC_ChipID_DocMil:
                        name="Millennium";
 #ifdef DOC_SINGLE_DRIVER
-                       im_funcname = "DoC2k_init";
-                       im_modname = "doc2000";
+                       initroutine = symbol_request(DoC2k_init);
 #else
-                       im_funcname = "DoCMil_init";
-                       im_modname = "doc2001";
+                       initroutine = symbol_request(DoCMil_init);
 #endif /* DOC_SINGLE_DRIVER */
                        break;
 
                case DOC_ChipID_DocMilPlus16:
                case DOC_ChipID_DocMilPlus32:
                        name="MillenniumPlus";
-                       im_funcname = "DoCMilPlus_init";
-                       im_modname = "doc2001plus";
+                       initroutine = symbol_request(DoCMilPlus_init);
                        break;
                }
 
-               if (im_funcname)
-                       initroutine = inter_module_get_request(im_funcname, im_modname);
-
                if (initroutine) {
                        (*initroutine)(mtd);
-                       inter_module_put(im_funcname);
+                       symbol_put_addr(initroutine);
                        return;
                }
                printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr);
index 29b0dda..4ea50a1 100644 (file)
@@ -635,6 +635,7 @@ int __init lart_flash_init (void)
    printk ("%s: This looks like a LART board to me.\n",module_name);
    mtd.name = module_name;
    mtd.type = MTD_NORFLASH;
+   mtd.writesize = 1;
    mtd.flags = MTD_CAP_NORFLASH;
    mtd.size = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM + FLASH_BLOCKSIZE_MAIN * FLASH_NUMBLOCKS_16m_MAIN;
    mtd.erasesize = FLASH_BLOCKSIZE_MAIN;
index 04e65d5..a846614 100644 (file)
@@ -465,6 +465,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
                flash->mtd.name = spi->dev.bus_id;
 
        flash->mtd.type = MTD_NORFLASH;
+       flash->mtd.writesize = 1;
        flash->mtd.flags = MTD_CAP_NORFLASH;
        flash->mtd.size = info->sector_size * info->n_sectors;
        flash->mtd.erasesize = info->sector_size;
index 485f663..4ab7670 100644 (file)
@@ -219,7 +219,7 @@ static int __init ms02nv_init_one(ulong addr)
        mp->uaddr = phys_to_virt(fixaddr);
 
        mtd->type = MTD_RAM;
-       mtd->flags = MTD_CAP_RAM | MTD_XIP;
+       mtd->flags = MTD_CAP_RAM;
        mtd->size = fixsize;
        mtd->name = (char *)ms02nv_name;
        mtd->owner = THIS_MODULE;
index 1443117..b4438ea 100644 (file)
@@ -106,6 +106,7 @@ int mtdram_init_device(struct mtd_info *mtd, void *mapped_address,
        mtd->type = MTD_RAM;
        mtd->flags = MTD_CAP_RAM;
        mtd->size = size;
+       mtd->writesize = 1;
        mtd->erasesize = MTDRAM_ERASE_SIZE;
        mtd->priv = mapped_address;
 
index e8685ee..e09e416 100644 (file)
@@ -1,8 +1,8 @@
 /**
  * $Id: phram.c,v 1.16 2005/11/07 11:14:25 gleixner Exp $
  *
- * Copyright (c) ????          Jochen Schäuble <psionic@psionic.de>
- * Copyright (c) 2003-2004     Jörn Engel <joern@wh.fh-wedel.de>
+ * Copyright (c) ????          Jochen Schäuble <psionic@psionic.de>
+ * Copyright (c) 2003-2004     Jörn Engel <joern@wh.fh-wedel.de>
  *
  * Usage:
  *
@@ -142,7 +142,7 @@ static int register_device(char *name, unsigned long start, unsigned long len)
 
        new->mtd.name = name;
        new->mtd.size = len;
-       new->mtd.flags = MTD_CAP_RAM | MTD_ERASEABLE | MTD_VOLATILE;
+       new->mtd.flags = MTD_CAP_RAM;
         new->mtd.erase = phram_erase;
        new->mtd.point = phram_point;
        new->mtd.unpoint = phram_unpoint;
@@ -266,12 +266,16 @@ static int phram_setup(const char *val, struct kernel_param *kp)
                return 0;
 
        ret = parse_num32(&start, token[1]);
-       if (ret)
+       if (ret) {
+               kfree(name);
                parse_err("illegal start address\n");
+       }
 
        ret = parse_num32(&len, token[2]);
-       if (ret)
+       if (ret) {
+               kfree(name);
                parse_err("illegal device length\n");
+       }
 
        register_device(name, start, len);
 
@@ -296,5 +300,5 @@ module_init(init_phram);
 module_exit(cleanup_phram);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Jörn Engel <joern@wh.fh-wedel.de>");
+MODULE_AUTHOR("Jörn Engel <joern@wh.fh-wedel.de>");
 MODULE_DESCRIPTION("MTD driver for physical RAM");
index 6faee6c..b3f665e 100644 (file)
@@ -200,8 +200,7 @@ static int register_device(char *name, unsigned long start, unsigned long length
 
        (*curmtd)->mtdinfo->name = name;
        (*curmtd)->mtdinfo->size = length;
-       (*curmtd)->mtdinfo->flags = MTD_CLEAR_BITS | MTD_SET_BITS |
-                                       MTD_WRITEB_WRITEABLE | MTD_VOLATILE | MTD_CAP_RAM;
+       (*curmtd)->mtdinfo->flags = MTD_CAP_RAM;
         (*curmtd)->mtdinfo->erase = slram_erase;
        (*curmtd)->mtdinfo->point = slram_point;
        (*curmtd)->mtdinfo->unpoint = slram_unpoint;
index a3b9247..1e21a2c 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nftl.h>
 #include <linux/mtd/inftl.h>
+#include <linux/mtd/nand.h>
 #include <asm/uaccess.h>
 #include <asm/errno.h>
 #include <asm/io.h>
@@ -79,14 +80,12 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
        inftl->mbd.devnum = -1;
        inftl->mbd.blksize = 512;
        inftl->mbd.tr = tr;
-       memcpy(&inftl->oobinfo, &mtd->oobinfo, sizeof(struct nand_oobinfo));
-       inftl->oobinfo.useecc = MTD_NANDECC_PLACEONLY;
 
-        if (INFTL_mount(inftl) < 0) {
+       if (INFTL_mount(inftl) < 0) {
                printk(KERN_WARNING "INFTL: could not mount device\n");
                kfree(inftl);
                return;
-        }
+       }
 
        /* OK, it's a new one. Set up all the data structures. */
 
@@ -152,6 +151,69 @@ static void inftl_remove_dev(struct mtd_blktrans_dev *dev)
  */
 
 /*
+ * Read oob data from flash
+ */
+int inftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
+                  size_t *retlen, uint8_t *buf)
+{
+       struct mtd_oob_ops ops;
+       int res;
+
+       ops.mode = MTD_OOB_PLACE;
+       ops.ooboffs = offs & (mtd->writesize - 1);
+       ops.ooblen = len;
+       ops.oobbuf = buf;
+       ops.datbuf = NULL;
+       ops.len = len;
+
+       res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+       *retlen = ops.retlen;
+       return res;
+}
+
+/*
+ * Write oob data to flash
+ */
+int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
+                   size_t *retlen, uint8_t *buf)
+{
+       struct mtd_oob_ops ops;
+       int res;
+
+       ops.mode = MTD_OOB_PLACE;
+       ops.ooboffs = offs & (mtd->writesize - 1);
+       ops.ooblen = len;
+       ops.oobbuf = buf;
+       ops.datbuf = NULL;
+       ops.len = len;
+
+       res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+       *retlen = ops.retlen;
+       return res;
+}
+
+/*
+ * Write data and oob to flash
+ */
+static int inftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
+                      size_t *retlen, uint8_t *buf, uint8_t *oob)
+{
+       struct mtd_oob_ops ops;
+       int res;
+
+       ops.mode = MTD_OOB_PLACE;
+       ops.ooboffs = offs;
+       ops.ooblen = mtd->oobsize;
+       ops.oobbuf = oob;
+       ops.datbuf = buf;
+       ops.len = len;
+
+       res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
+       *retlen = ops.retlen;
+       return res;
+}
+
+/*
  * INFTL_findfreeblock: Find a free Erase Unit on the INFTL partition.
  *     This function is used when the give Virtual Unit Chain.
  */
@@ -198,10 +260,11 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
        u16 BlockMap[MAX_SECTORS_PER_UNIT];
        unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
        unsigned int thisEUN, prevEUN, status;
+       struct mtd_info *mtd = inftl->mbd.mtd;
        int block, silly;
        unsigned int targetEUN;
        struct inftl_oob oob;
-        size_t retlen;
+       size_t retlen;
 
        DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
                "pending=%d)\n", inftl, thisVUC, pendingblock);
@@ -221,18 +284,18 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
         * Scan to find the Erase Unit which holds the actual data for each
         * 512-byte block within the Chain.
         */
-        silly = MAX_LOOPS;
+       silly = MAX_LOOPS;
        while (thisEUN < inftl->nb_blocks) {
                for (block = 0; block < inftl->EraseSize/SECTORSIZE; block ++) {
                        if ((BlockMap[block] != 0xffff) || BlockDeleted[block])
                                continue;
 
-                       if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize)
-                            + (block * SECTORSIZE), 16 , &retlen,
-                            (char *)&oob) < 0)
+                       if (inftl_read_oob(mtd, (thisEUN * inftl->EraseSize)
+                                          + (block * SECTORSIZE), 16, &retlen,
+                                          (char *)&oob) < 0)
                                status = SECTOR_IGNORE;
                        else
-                               status = oob.b.Status | oob.b.Status1;
+                               status = oob.b.Status | oob.b.Status1;
 
                        switch(status) {
                        case SECTOR_FREE:
@@ -282,29 +345,31 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
                        continue;
                }
 
-                /*
+               /*
                 * Copy only in non free block (free blocks can only
                  * happen in case of media errors or deleted blocks).
                 */
-                if (BlockMap[block] == BLOCK_NIL)
-                        continue;
-
-                ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize *
-                       BlockMap[block]) + (block * SECTORSIZE), SECTORSIZE,
-                       &retlen, movebuf);
-                if (ret < 0) {
-                       ret = MTD_READ(inftl->mbd.mtd, (inftl->EraseSize *
-                               BlockMap[block]) + (block * SECTORSIZE),
-                               SECTORSIZE, &retlen, movebuf);
+               if (BlockMap[block] == BLOCK_NIL)
+                       continue;
+
+               ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) +
+                               (block * SECTORSIZE), SECTORSIZE, &retlen,
+                               movebuf);
+               if (ret < 0 && ret != -EUCLEAN) {
+                       ret = mtd->read(mtd,
+                                       (inftl->EraseSize * BlockMap[block]) +
+                                       (block * SECTORSIZE), SECTORSIZE,
+                                       &retlen, movebuf);
                        if (ret != -EIO)
-                               DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went "
-                                       "away on retry?\n");
-                }
-                memset(&oob, 0xff, sizeof(struct inftl_oob));
-                oob.b.Status = oob.b.Status1 = SECTOR_USED;
-                MTD_WRITEECC(inftl->mbd.mtd, (inftl->EraseSize * targetEUN) +
-                       (block * SECTORSIZE), SECTORSIZE, &retlen,
-                       movebuf, (char *)&oob, &inftl->oobinfo);
+                               DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went "
+                                     "away on retry?\n");
+               }
+               memset(&oob, 0xff, sizeof(struct inftl_oob));
+               oob.b.Status = oob.b.Status1 = SECTOR_USED;
+
+               inftl_write(inftl->mbd.mtd, (inftl->EraseSize * targetEUN) +
+                           (block * SECTORSIZE), SECTORSIZE, &retlen,
+                           movebuf, (char *)&oob);
        }
 
        /*
@@ -329,17 +394,17 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
                if (thisEUN == targetEUN)
                        break;
 
-                if (INFTL_formatblock(inftl, thisEUN) < 0) {
+               if (INFTL_formatblock(inftl, thisEUN) < 0) {
                        /*
                         * Could not erase : mark block as reserved.
                         */
                        inftl->PUtable[thisEUN] = BLOCK_RESERVED;
-                } else {
+               } else {
                        /* Correctly erased : mark it as free */
                        inftl->PUtable[thisEUN] = BLOCK_FREE;
                        inftl->PUtable[prevEUN] = BLOCK_NIL;
                        inftl->numfreeEUNs++;
-                }
+               }
        }
 
        return targetEUN;
@@ -415,6 +480,7 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
        unsigned int thisVUC = block / (inftl->EraseSize / SECTORSIZE);
        unsigned int thisEUN, writeEUN, prev_block, status;
        unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize -1);
+       struct mtd_info *mtd = inftl->mbd.mtd;
        struct inftl_oob oob;
        struct inftl_bci bci;
        unsigned char anac, nacs, parity;
@@ -434,10 +500,10 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
                silly = MAX_LOOPS;
 
                while (thisEUN <= inftl->lastEUN) {
-                       MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
-                               blockofs, 8, &retlen, (char *)&bci);
+                       inftl_read_oob(mtd, (thisEUN * inftl->EraseSize) +
+                                      blockofs, 8, &retlen, (char *)&bci);
 
-                        status = bci.Status | bci.Status1;
+                       status = bci.Status | bci.Status1;
                        DEBUG(MTD_DEBUG_LEVEL3, "INFTL: status of block %d in "
                                "EUN %d is %x\n", block , writeEUN, status);
 
@@ -522,8 +588,8 @@ hitused:
                nacs = 0;
                thisEUN = inftl->VUtable[thisVUC];
                if (thisEUN != BLOCK_NIL) {
-                       MTD_READOOB(inftl->mbd.mtd, thisEUN * inftl->EraseSize
-                               + 8, 8, &retlen, (char *)&oob.u);
+                       inftl_read_oob(mtd, thisEUN * inftl->EraseSize
+                                      + 8, 8, &retlen, (char *)&oob.u);
                        anac = oob.u.a.ANAC + 1;
                        nacs = oob.u.a.NACs + 1;
                }
@@ -544,8 +610,8 @@ hitused:
                oob.u.a.parityPerField = parity;
                oob.u.a.discarded = 0xaa;
 
-               MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize + 8, 8,
-                       &retlen, (char *)&oob.u);
+               inftl_write_oob(mtd, writeEUN * inftl->EraseSize + 8, 8,
+                               &retlen, (char *)&oob.u);
 
                /* Also back up header... */
                oob.u.b.virtualUnitNo = cpu_to_le16(thisVUC);
@@ -555,8 +621,8 @@ hitused:
                oob.u.b.parityPerField = parity;
                oob.u.b.discarded = 0xaa;
 
-               MTD_WRITEOOB(inftl->mbd.mtd, writeEUN * inftl->EraseSize +
-                       SECTORSIZE * 4 + 8, 8, &retlen, (char *)&oob.u);
+               inftl_write_oob(mtd, writeEUN * inftl->EraseSize +
+                               SECTORSIZE * 4 + 8, 8, &retlen, (char *)&oob.u);
 
                inftl->PUtable[writeEUN] = inftl->VUtable[thisVUC];
                inftl->VUtable[thisVUC] = writeEUN;
@@ -576,6 +642,7 @@ hitused:
  */
 static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
 {
+       struct mtd_info *mtd = inftl->mbd.mtd;
        unsigned char BlockUsed[MAX_SECTORS_PER_UNIT];
        unsigned char BlockDeleted[MAX_SECTORS_PER_UNIT];
        unsigned int thisEUN, status;
@@ -606,9 +673,9 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
                        if (BlockUsed[block] || BlockDeleted[block])
                                continue;
 
-                       if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize)
-                           + (block * SECTORSIZE), 8 , &retlen,
-                           (char *)&bci) < 0)
+                       if (inftl_read_oob(mtd, (thisEUN * inftl->EraseSize)
+                                          + (block * SECTORSIZE), 8 , &retlen,
+                                         (char *)&bci) < 0)
                                status = SECTOR_IGNORE;
                        else
                                status = bci.Status | bci.Status1;
@@ -670,12 +737,12 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
                DEBUG(MTD_DEBUG_LEVEL3, "Deleting EUN %d from VUC %d\n",
                      thisEUN, thisVUC);
 
-                if (INFTL_formatblock(inftl, thisEUN) < 0) {
+               if (INFTL_formatblock(inftl, thisEUN) < 0) {
                        /*
                         * Could not erase : mark block as reserved.
                         */
                        inftl->PUtable[thisEUN] = BLOCK_RESERVED;
-                } else {
+               } else {
                        /* Correctly erased : mark it as free */
                        inftl->PUtable[thisEUN] = BLOCK_FREE;
                        inftl->numfreeEUNs++;
@@ -697,6 +764,7 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
 {
        unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
        unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
+       struct mtd_info *mtd = inftl->mbd.mtd;
        unsigned int status;
        int silly = MAX_LOOPS;
        size_t retlen;
@@ -706,8 +774,8 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
                "block=%d)\n", inftl, block);
 
        while (thisEUN < inftl->nb_blocks) {
-               if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
-                   blockofs, 8, &retlen, (char *)&bci) < 0)
+               if (inftl_read_oob(mtd, (thisEUN * inftl->EraseSize) +
+                                  blockofs, 8, &retlen, (char *)&bci) < 0)
                        status = SECTOR_IGNORE;
                else
                        status = bci.Status | bci.Status1;
@@ -741,10 +809,10 @@ foundit:
        if (thisEUN != BLOCK_NIL) {
                loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
 
-               if (MTD_READOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0)
+               if (inftl_read_oob(mtd, ptr, 8, &retlen, (char *)&bci) < 0)
                        return -EIO;
                bci.Status = bci.Status1 = SECTOR_DELETED;
-               if (MTD_WRITEOOB(inftl->mbd.mtd, ptr, 8, &retlen, (char *)&bci) < 0)
+               if (inftl_write_oob(mtd, ptr, 8, &retlen, (char *)&bci) < 0)
                        return -EIO;
                INFTL_trydeletechain(inftl, block / (inftl->EraseSize / SECTORSIZE));
        }
@@ -784,9 +852,10 @@ static int inftl_writeblock(struct mtd_blktrans_dev *mbd, unsigned long block,
 
                memset(&oob, 0xff, sizeof(struct inftl_oob));
                oob.b.Status = oob.b.Status1 = SECTOR_USED;
-               MTD_WRITEECC(inftl->mbd.mtd, (writeEUN * inftl->EraseSize) +
-                       blockofs, SECTORSIZE, &retlen, (char *)buffer,
-                       (char *)&oob, &inftl->oobinfo);
+
+               inftl_write(inftl->mbd.mtd, (writeEUN * inftl->EraseSize) +
+                           blockofs, SECTORSIZE, &retlen, (char *)buffer,
+                           (char *)&oob);
                /*
                 * need to write SECTOR_USED flags since they are not written
                 * in mtd_writeecc
@@ -804,17 +873,18 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
        struct INFTLrecord *inftl = (void *)mbd;
        unsigned int thisEUN = inftl->VUtable[block / (inftl->EraseSize / SECTORSIZE)];
        unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize - 1);
-        unsigned int status;
+       struct mtd_info *mtd = inftl->mbd.mtd;
+       unsigned int status;
        int silly = MAX_LOOPS;
-        struct inftl_bci bci;
+       struct inftl_bci bci;
        size_t retlen;
 
        DEBUG(MTD_DEBUG_LEVEL3, "INFTL: inftl_readblock(inftl=%p,block=%ld,"
                "buffer=%p)\n", inftl, block, buffer);
 
        while (thisEUN < inftl->nb_blocks) {
-               if (MTD_READOOB(inftl->mbd.mtd, (thisEUN * inftl->EraseSize) +
-                    blockofs, 8, &retlen, (char *)&bci) < 0)
+               if (inftl_read_oob(mtd, (thisEUN * inftl->EraseSize) +
+                                 blockofs, 8, &retlen, (char *)&bci) < 0)
                        status = SECTOR_IGNORE;
                else
                        status = bci.Status | bci.Status1;
@@ -850,10 +920,12 @@ foundit:
                /* The requested block is not on the media, return all 0x00 */
                memset(buffer, 0, SECTORSIZE);
        } else {
-               size_t retlen;
+               size_t retlen;
                loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs;
-               if (MTD_READ(inftl->mbd.mtd, ptr, SECTORSIZE, &retlen,
-                   buffer))
+               int ret = mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer);
+
+               /* Handle corrected bit flips gracefully */
+               if (ret < 0 && ret != -EUCLEAN)
                        return -EIO;
        }
        return 0;
index 43fdc94..8f6006f 100644 (file)
 
 char inftlmountrev[]="$Revision: 1.18 $";
 
+extern int inftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
+                         size_t *retlen, uint8_t *buf);
+extern int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
+                          size_t *retlen, uint8_t *buf);
+
 /*
  * find_boot_record: Find the INFTL Media Header and its Spare copy which
  *     contains the various device information of the INFTL partition and
@@ -57,6 +62,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
        unsigned int i, block;
        u8 buf[SECTORSIZE];
        struct INFTLMediaHeader *mh = &inftl->MediaHdr;
+       struct mtd_info *mtd = inftl->mbd.mtd;
        struct INFTLPartition *ip;
        size_t retlen;
 
@@ -80,8 +86,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
                 * Check for BNAND header first. Then whinge if it's found
                 * but later checks fail.
                 */
-               ret = MTD_READ(inftl->mbd.mtd, block * inftl->EraseSize,
-                   SECTORSIZE, &retlen, buf);
+               ret = mtd->read(mtd, block * inftl->EraseSize,
+                               SECTORSIZE, &retlen, buf);
                /* We ignore ret in case the ECC of the MediaHeader is invalid
                   (which is apparently acceptable) */
                if (retlen != SECTORSIZE) {
@@ -106,8 +112,9 @@ static int find_boot_record(struct INFTLrecord *inftl)
                }
 
                /* To be safer with BIOS, also use erase mark as discriminant */
-               if ((ret = MTD_READOOB(inftl->mbd.mtd, block * inftl->EraseSize +
-                   SECTORSIZE + 8, 8, &retlen, (char *)&h1) < 0)) {
+               if ((ret = inftl_read_oob(mtd, block * inftl->EraseSize +
+                                         SECTORSIZE + 8, 8, &retlen,
+                                         (char *)&h1) < 0)) {
                        printk(KERN_WARNING "INFTL: ANAND header found at "
                                "0x%x in mtd%d, but OOB data read failed "
                                "(err %d)\n", block * inftl->EraseSize,
@@ -123,8 +130,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
                memcpy(mh, buf, sizeof(struct INFTLMediaHeader));
 
                /* Read the spare media header at offset 4096 */
-               MTD_READ(inftl->mbd.mtd, block * inftl->EraseSize + 4096,
-                   SECTORSIZE, &retlen, buf);
+               mtd->read(mtd, block * inftl->EraseSize + 4096,
+                         SECTORSIZE, &retlen, buf);
                if (retlen != SECTORSIZE) {
                        printk(KERN_WARNING "INFTL: Unable to read spare "
                               "Media Header\n");
@@ -233,7 +240,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
                                 */
                                instr->addr = ip->Reserved0 * inftl->EraseSize;
                                instr->len = inftl->EraseSize;
-                               MTD_ERASE(inftl->mbd.mtd, instr);
+                               mtd->erase(mtd, instr);
                        }
                        if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) {
                                printk(KERN_WARNING "INFTL: Media Header "
@@ -350,21 +357,21 @@ static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address,
        int len, int check_oob)
 {
        u8 buf[SECTORSIZE + inftl->mbd.mtd->oobsize];
+       struct mtd_info *mtd = inftl->mbd.mtd;
        size_t retlen;
        int i;
 
-       DEBUG(MTD_DEBUG_LEVEL3, "INFTL: check_free_sectors(inftl=%p,"
-               "address=0x%x,len=%d,check_oob=%d)\n", inftl,
-               address, len, check_oob);
-
        for (i = 0; i < len; i += SECTORSIZE) {
-               if (MTD_READECC(inftl->mbd.mtd, address, SECTORSIZE, &retlen, buf, &buf[SECTORSIZE], &inftl->oobinfo) < 0)
+               if (mtd->read(mtd, address, SECTORSIZE, &retlen, buf))
                        return -1;
                if (memcmpb(buf, 0xff, SECTORSIZE) != 0)
                        return -1;
 
                if (check_oob) {
-                       if (memcmpb(buf + SECTORSIZE, 0xff, inftl->mbd.mtd->oobsize) != 0)
+                       if(inftl_read_oob(mtd, address, mtd->oobsize,
+                                         &retlen, &buf[SECTORSIZE]) < 0)
+                               return -1;
+                       if (memcmpb(buf + SECTORSIZE, 0xff, mtd->oobsize) != 0)
                                return -1;
                }
                address += SECTORSIZE;
@@ -387,6 +394,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
        size_t retlen;
        struct inftl_unittail uci;
        struct erase_info *instr = &inftl->instr;
+       struct mtd_info *mtd = inftl->mbd.mtd;
        int physblock;
 
        DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_formatblock(inftl=%p,"
@@ -404,8 +412,9 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
        /* Erase one physical eraseblock at a time, even though the NAND api
           allows us to group them.  This way we if we have a failure, we can
           mark only the failed block in the bbt. */
-       for (physblock = 0; physblock < inftl->EraseSize; physblock += instr->len, instr->addr += instr->len) {
-               MTD_ERASE(inftl->mbd.mtd, instr);
+       for (physblock = 0; physblock < inftl->EraseSize;
+            physblock += instr->len, instr->addr += instr->len) {
+               mtd->erase(inftl->mbd.mtd, instr);
 
                if (instr->state == MTD_ERASE_FAILED) {
                        printk(KERN_WARNING "INFTL: error while formatting block %d\n",
@@ -414,10 +423,10 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
                }
 
                /*
-               * Check the "freeness" of Erase Unit before updating metadata.
-               * FixMe: is this check really necessary? Since we have check the
-               *        return code after the erase operation.
-               */
+                * Check the "freeness" of Erase Unit before updating metadata.
+                * FixMe: is this check really necessary? Since we have check
+                * the return code after the erase operation.
+                */
                if (check_free_sectors(inftl, instr->addr, instr->len, 1) != 0)
                        goto fail;
        }
@@ -429,8 +438,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
        uci.Reserved[2] = 0;
        uci.Reserved[3] = 0;
        instr->addr = block * inftl->EraseSize + SECTORSIZE * 2;
-       if (MTD_WRITEOOB(inftl->mbd.mtd, instr->addr +
-           8, 8, &retlen, (char *)&uci) < 0)
+       if (inftl_write_oob(mtd, instr->addr + 8, 8, &retlen, (char *)&uci) < 0)
                goto fail;
        return 0;
 fail:
@@ -549,6 +557,7 @@ void INFTL_dumpVUchains(struct INFTLrecord *s)
 
 int INFTL_mount(struct INFTLrecord *s)
 {
+       struct mtd_info *mtd = s->mbd.mtd;
        unsigned int block, first_block, prev_block, last_block;
        unsigned int first_logical_block, logical_block, erase_mark;
        int chain_length, do_format_chain;
@@ -607,10 +616,11 @@ int INFTL_mount(struct INFTLrecord *s)
                                break;
                        }
 
-                       if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8,
-                           8, &retlen, (char *)&h0) < 0 ||
-                           MTD_READOOB(s->mbd.mtd, block * s->EraseSize +
-                           2 * SECTORSIZE + 8, 8, &retlen, (char *)&h1) < 0) {
+                       if (inftl_read_oob(mtd, block * s->EraseSize + 8,
+                                          8, &retlen, (char *)&h0) < 0 ||
+                           inftl_read_oob(mtd, block * s->EraseSize +
+                                          2 * SECTORSIZE + 8, 8, &retlen,
+                                          (char *)&h1) < 0) {
                                /* Should never happen? */
                                do_format_chain++;
                                break;
index 7abd7fe..6bdaacc 100644 (file)
@@ -37,7 +37,7 @@ config MTD_PHYSMAP_START
 config MTD_PHYSMAP_LEN
        hex "Physical length of flash mapping"
        depends on MTD_PHYSMAP
-       default "0x4000000"
+       default "0"
        help
          This is the total length of the mapping of the flash chips on
          your particular board. If there is space, or aliases, in the
@@ -78,7 +78,7 @@ config MTD_PNC2000
 
 config MTD_SC520CDP
        tristate "CFI Flash device mapped on AMD SC520 CDP"
-       depends on X86 && MTD_CFI
+       depends on X86 && MTD_CFI && MTD_CONCAT
        help
          The SC520 CDP board has two banks of CFI-compliant chips and one
          Dual-in-line JEDEC chip. This 'mapping' driver supports that
@@ -109,7 +109,7 @@ config MTD_TS5500
          mtd1 allows you to reprogram your BIOS. BE VERY CAREFUL.
 
          Note that jumper 3 ("Write Enable Drive A") must be set
-         otherwise detection won't succeeed.
+         otherwise detection won't succeed.
 
 config MTD_SBC_GXX
        tristate "CFI Flash device mapped on Arcom SBC-GXx boards"
@@ -200,8 +200,8 @@ config MTD_TSUNAMI
          Support for the flash chip on Tsunami TIG bus.
 
 config MTD_LASAT
-       tristate "Flash chips on LASAT board"
-       depends on LASAT
+       tristate "LASAT flash device"
+       depends on LASAT && MTD_CFI
        help
          Support for the flash chips on the Lasat 100 and 200 boards.
 
@@ -561,7 +561,6 @@ config MTD_PCMCIA
 config MTD_PCMCIA_ANONYMOUS
        bool "Use PCMCIA MTD drivers for anonymous PCMCIA cards"
        depends on MTD_PCMCIA
-       default N
        help
          If this option is enabled, PCMCIA cards which do not report
          anything about themselves are assumed to be MTD cards.
index fd0f0d3..92b5d88 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is>
+ *  Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is>
  *
  *  $Id: cfi_flagadm.c,v 1.15 2005/11/07 11:14:26 gleixner Exp $
  *
@@ -135,5 +135,5 @@ module_exit(cleanup_flagadm);
 
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
+MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
 MODULE_DESCRIPTION("MTD map driver for Flaga digital module");
index 652813c..85c2a9e 100644 (file)
@@ -122,5 +122,5 @@ module_exit(cleanup_dbox2_flash);
 
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>, Bastian Blank <waldi@tuxbox.org>, Alexander Wild <wild@te-elektronik.com>");
+MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>, Bastian Blank <waldi@tuxbox.org>, Alexander Wild <wild@te-elektronik.com>");
 MODULE_DESCRIPTION("MTD map driver for D-Box 2 board");
index d1e66e1..5c25d4e 100644 (file)
@@ -4,7 +4,7 @@
  * $Id: mtx-1_flash.c,v 1.2 2005/11/07 11:14:27 gleixner Exp $
  *
  * (C) 2005 Bruno Randolf <bruno.randolf@4g-systems.biz>
- * (C) 2005 Jörn Engel <joern@wohnheim.fh-wedel.de>
+ * (C) 2005 Jörn Engel <joern@wohnheim.fh-wedel.de>
  *
  */
 
index 54a3102..0994b5b 100644 (file)
@@ -20,6 +20,8 @@
 #include <linux/mtd/partitions.h>
 #include <linux/mtd/cfi.h>
 #include <linux/reboot.h>
+#include <linux/kdev_t.h>
+#include <linux/root_dev.h>
 #include <asm/io.h>
 
 /****************************************************************************/
@@ -188,7 +190,7 @@ int nettel_eraseconfig(void)
                set_current_state(TASK_INTERRUPTIBLE);
                add_wait_queue(&wait_q, &wait);
 
-               ret = MTD_ERASE(mtd, &nettel_erase);
+               ret = mtd->erase(mtd, &nettel_erase);
                if (ret) {
                        set_current_state(TASK_RUNNING);
                        remove_wait_queue(&wait_q, &wait);
index d27f412..c861134 100644 (file)
@@ -713,6 +713,7 @@ static void pcmciamtd_detach(struct pcmcia_device *link)
 
        if(dev->mtd_info) {
                del_mtd_device(dev->mtd_info);
+               map_destroy(dev->mtd_info);
                info("mtd%d: Removed", dev->mtd_info->index);
        }
 
index f49ebc3..433c3ca 100644 (file)
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/slab.h>
-#include <asm/io.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
 #include <linux/config.h>
 #include <linux/mtd/partitions.h>
 #include <linux/mtd/physmap.h>
+#include <asm/io.h>
 
-static struct mtd_info *mymtd;
-
-struct map_info physmap_map = {
-       .name = "phys_mapped_flash",
-       .phys = CONFIG_MTD_PHYSMAP_START,
-       .size = CONFIG_MTD_PHYSMAP_LEN,
-       .bankwidth = CONFIG_MTD_PHYSMAP_BANKWIDTH,
+struct physmap_flash_info {
+       struct mtd_info         *mtd;
+       struct map_info         map;
+       struct resource         *res;
+#ifdef CONFIG_MTD_PARTITIONS
+       int                     nr_parts;
+       struct mtd_partition    *parts;
+#endif
 };
 
+
+static int physmap_flash_remove(struct platform_device *dev)
+{
+       struct physmap_flash_info *info;
+       struct physmap_flash_data *physmap_data;
+
+       info = platform_get_drvdata(dev);
+       if (info == NULL)
+               return 0;
+       platform_set_drvdata(dev, NULL);
+
+       physmap_data = dev->dev.platform_data;
+
+       if (info->mtd != NULL) {
 #ifdef CONFIG_MTD_PARTITIONS
-static struct mtd_partition *mtd_parts;
-static int                   mtd_parts_nb;
+               if (info->nr_parts) {
+                       del_mtd_partitions(info->mtd);
+                       kfree(info->parts);
+               } else if (physmap_data->nr_parts) {
+                       del_mtd_partitions(info->mtd);
+               } else {
+                       del_mtd_device(info->mtd);
+               }
+#else
+               del_mtd_device(info->mtd);
+#endif
+               map_destroy(info->mtd);
+       }
 
-static int num_physmap_partitions;
-static struct mtd_partition *physmap_partitions;
+       if (info->map.virt != NULL)
+               iounmap((void *)info->map.virt);
 
-static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
+       if (info->res != NULL) {
+               release_resource(info->res);
+               kfree(info->res);
+       }
 
-void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
-{
-       physmap_partitions=parts;
-       num_physmap_partitions=num_parts;
+       return 0;
 }
-#endif /* CONFIG_MTD_PARTITIONS */
 
-static int __init init_physmap(void)
+static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
+#ifdef CONFIG_MTD_PARTITIONS
+static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
+#endif
+
+static int physmap_flash_probe(struct platform_device *dev)
 {
-       static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
-       const char **type;
+       struct physmap_flash_data *physmap_data;
+       struct physmap_flash_info *info;
+       const char **probe_type;
+       int err;
+
+       physmap_data = dev->dev.platform_data;
+       if (physmap_data == NULL)
+               return -ENODEV;
+
+               printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n",
+           (unsigned long long)dev->resource->end - dev->resource->start + 1,
+           (unsigned long long)dev->resource->start);
+
+       info = kmalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
+       if (info == NULL) {
+               err = -ENOMEM;
+               goto err_out;
+       }
+       memset(info, 0, sizeof(*info));
 
-               printk(KERN_NOTICE "physmap flash device: %lx at %lx\n", physmap_map.size, physmap_map.phys);
-       physmap_map.virt = ioremap(physmap_map.phys, physmap_map.size);
+       platform_set_drvdata(dev, info);
 
-       if (!physmap_map.virt) {
-               printk("Failed to ioremap\n");
-               return -EIO;
+       info->res = request_mem_region(dev->resource->start,
+                       dev->resource->end - dev->resource->start + 1,
+                       dev->dev.bus_id);
+       if (info->res == NULL) {
+               dev_err(&dev->dev, "Could not reserve memory region\n");
+               err = -ENOMEM;
+               goto err_out;
        }
 
-       simple_map_init(&physmap_map);
+       info->map.name = dev->dev.bus_id;
+       info->map.phys = dev->resource->start;
+       info->map.size = dev->resource->end - dev->resource->start + 1;
+       info->map.bankwidth = physmap_data->width;
+       info->map.set_vpp = physmap_data->set_vpp;
+
+       info->map.virt = ioremap(info->map.phys, info->map.size);
+       if (info->map.virt == NULL) {
+               dev_err(&dev->dev, "Failed to ioremap flash region\n");
+               err = EIO;
+               goto err_out;
+       }
 
-       mymtd = NULL;
-       type = rom_probe_types;
-       for(; !mymtd && *type; type++) {
-               mymtd = do_map_probe(*type, &physmap_map);
+       simple_map_init(&info->map);
+
+       probe_type = rom_probe_types;
+       for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
+               info->mtd = do_map_probe(*probe_type, &info->map);
+       if (info->mtd == NULL) {
+               dev_err(&dev->dev, "map_probe failed\n");
+               err = -ENXIO;
+               goto err_out;
        }
-       if (mymtd) {
-               mymtd->owner = THIS_MODULE;
+       info->mtd->owner = THIS_MODULE;
 
 #ifdef CONFIG_MTD_PARTITIONS
-               mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes,
-                                                   &mtd_parts, 0);
+       err = parse_mtd_partitions(info->mtd, part_probe_types, &info->parts, 0);
+       if (err > 0) {
+               add_mtd_partitions(info->mtd, info->parts, err);
+               return 0;
+       }
 
-               if (mtd_parts_nb > 0)
-               {
-                       add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb);
-                       return 0;
-               }
+       if (physmap_data->nr_parts) {
+               printk(KERN_NOTICE "Using physmap partition information\n");
+               add_mtd_partitions(info->mtd, physmap_data->parts,
+                                               physmap_data->nr_parts);
+               return 0;
+       }
+#endif
+
+       add_mtd_device(info->mtd);
+       return 0;
+
+err_out:
+       physmap_flash_remove(dev);
+       return err;
+}
+
+static struct platform_driver physmap_flash_driver = {
+       .probe          = physmap_flash_probe,
+       .remove         = physmap_flash_remove,
+       .driver         = {
+               .name   = "physmap-flash",
+       },
+};
 
-               if (num_physmap_partitions != 0)
-               {
-                       printk(KERN_NOTICE
-                              "Using physmap partition definition\n");
-                       add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions);
-                       return 0;
-               }
 
+#ifdef CONFIG_MTD_PHYSMAP_LEN
+#if CONFIG_MTD_PHYSMAP_LEN != 0
+#warning using PHYSMAP compat code
+#define PHYSMAP_COMPAT
+#endif
 #endif
-               add_mtd_device(mymtd);
 
-               return 0;
-       }
+#ifdef PHYSMAP_COMPAT
+static struct physmap_flash_data physmap_flash_data = {
+       .width          = CONFIG_MTD_PHYSMAP_BANKWIDTH,
+};
 
-       iounmap(physmap_map.virt);
-       return -ENXIO;
-}
+static struct resource physmap_flash_resource = {
+       .start          = CONFIG_MTD_PHYSMAP_START,
+       .end            = CONFIG_MTD_PHYSMAP_START + CONFIG_MTD_PHYSMAP_LEN,
+       .flags          = IORESOURCE_MEM,
+};
 
-static void __exit cleanup_physmap(void)
+static struct platform_device physmap_flash = {
+       .name           = "physmap-flash",
+       .id             = 0,
+       .dev            = {
+               .platform_data  = &physmap_flash_data,
+       },
+       .num_resources  = 1,
+       .resource       = &physmap_flash_resource,
+};
+
+void physmap_configure(unsigned long addr, unsigned long size,
+               int bankwidth, void (*set_vpp)(struct map_info *, int))
 {
+       physmap_flash_resource.start = addr;
+       physmap_flash_resource.end = addr + size - 1;
+       physmap_flash_data.width = bankwidth;
+       physmap_flash_data.set_vpp = set_vpp;
+}
+
 #ifdef CONFIG_MTD_PARTITIONS
-       if (mtd_parts_nb) {
-               del_mtd_partitions(mymtd);
-               kfree(mtd_parts);
-       } else if (num_physmap_partitions) {
-               del_mtd_partitions(mymtd);
-       } else {
-               del_mtd_device(mymtd);
-       }
-#else
-       del_mtd_device(mymtd);
+void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
+{
+       physmap_flash_data.nr_parts = num_parts;
+       physmap_flash_data.parts = parts;
+}
+#endif
 #endif
-       map_destroy(mymtd);
 
-       iounmap(physmap_map.virt);
-       physmap_map.virt = NULL;
+static int __init physmap_init(void)
+{
+       int err;
+
+       err = platform_driver_register(&physmap_flash_driver);
+#ifdef PHYSMAP_COMPAT
+       if (err == 0)
+               platform_device_register(&physmap_flash);
+#endif
+
+       return err;
 }
 
-module_init(init_physmap);
-module_exit(cleanup_physmap);
+static void __exit physmap_exit(void)
+{
+#ifdef PHYSMAP_COMPAT
+       platform_device_unregister(&physmap_flash);
+#endif
+       platform_driver_unregister(&physmap_flash_driver);
+}
 
+module_init(physmap_init);
+module_exit(physmap_exit);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
index 2cef280..e5c7846 100644 (file)
@@ -71,7 +71,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
        set_current_state(TASK_INTERRUPTIBLE);
        add_wait_queue(&wait_q, &wait);
 
-       ret = MTD_ERASE(mtd, &erase);
+       ret = mtd->erase(mtd, &erase);
        if (ret) {
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&wait_q, &wait);
@@ -88,7 +88,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
         * Next, writhe data to flash.
         */
 
-       ret = MTD_WRITE (mtd, pos, len, &retlen, buf);
+       ret = mtd->write(mtd, pos, len, &retlen, buf);
        if (ret)
                return ret;
        if (retlen != len)
@@ -138,7 +138,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
                mtd->name, pos, len);
 
        if (!sect_size)
-               return MTD_WRITE (mtd, pos, len, &retlen, buf);
+               return mtd->write(mtd, pos, len, &retlen, buf);
 
        while (len > 0) {
                unsigned long sect_start = (pos/sect_size)*sect_size;
@@ -170,7 +170,8 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
                            mtdblk->cache_offset != sect_start) {
                                /* fill the cache with the current sector */
                                mtdblk->cache_state = STATE_EMPTY;
-                               ret = MTD_READ(mtd, sect_start, sect_size, &retlen, mtdblk->cache_data);
+                               ret = mtd->read(mtd, sect_start, sect_size,
+                                               &retlen, mtdblk->cache_data);
                                if (ret)
                                        return ret;
                                if (retlen != sect_size)
@@ -207,7 +208,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
                        mtd->name, pos, len);
 
        if (!sect_size)
-               return MTD_READ (mtd, pos, len, &retlen, buf);
+               return mtd->read(mtd, pos, len, &retlen, buf);
 
        while (len > 0) {
                unsigned long sect_start = (pos/sect_size)*sect_size;
@@ -226,7 +227,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
                    mtdblk->cache_offset == sect_start) {
                        memcpy (buf, mtdblk->cache_data + offset, size);
                } else {
-                       ret = MTD_READ (mtd, pos, size, &retlen, buf);
+                       ret = mtd->read(mtd, pos, size, &retlen, buf);
                        if (ret)
                                return ret;
                        if (retlen != size)
@@ -288,8 +289,7 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
 
        mutex_init(&mtdblk->cache_mutex);
        mtdblk->cache_state = STATE_EMPTY;
-       if ((mtdblk->mtd->flags & MTD_CAP_RAM) != MTD_CAP_RAM &&
-           mtdblk->mtd->erasesize) {
+       if ( !(mtdblk->mtd->flags & MTD_NO_ERASE) && mtdblk->mtd->erasesize) {
                mtdblk->cache_size = mtdblk->mtd->erasesize;
                mtdblk->cache_data = NULL;
        }
index 0c830ba..29563ed 100644 (file)
@@ -45,9 +45,7 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
        dev->blksize = 512;
        dev->size = mtd->size >> 9;
        dev->tr = tr;
-       if ((mtd->flags & (MTD_CLEAR_BITS|MTD_SET_BITS|MTD_WRITEABLE)) !=
-           (MTD_CLEAR_BITS|MTD_SET_BITS|MTD_WRITEABLE))
-               dev->readonly = 1;
+       dev->readonly = 1;
 
        add_mtd_blktrans_dev(dev);
 }
index 6f04458..aa18d45 100644 (file)
@@ -49,24 +49,18 @@ static struct mtd_notifier notifier = {
 };
 
 /*
- * We use file->private_data to store a pointer to the MTDdevice.
- * Since alighment is at least 32 bits, we have 2 bits free for OTP
- * modes as well.
+ * Data structure to hold the pointer to the mtd device as well
+ * as mode information ofr various use cases.
  */
-
-#define TO_MTD(file) (struct mtd_info *)((long)((file)->private_data) & ~3L)
-
-#define MTD_MODE_OTP_FACT      1
-#define MTD_MODE_OTP_USER      2
-#define MTD_MODE(file)         ((long)((file)->private_data) & 3)
-
-#define SET_MTD_MODE(file, mode) \
-       do { long __p = (long)((file)->private_data); \
-            (file)->private_data = (void *)((__p & ~3L) | mode); } while (0)
+struct mtd_file_info {
+       struct mtd_info *mtd;
+       enum mtd_file_modes mode;
+};
 
 static loff_t mtd_lseek (struct file *file, loff_t offset, int orig)
 {
-       struct mtd_info *mtd = TO_MTD(file);
+       struct mtd_file_info *mfi = file->private_data;
+       struct mtd_info *mtd = mfi->mtd;
 
        switch (orig) {
        case 0:
@@ -97,6 +91,7 @@ static int mtd_open(struct inode *inode, struct file *file)
        int minor = iminor(inode);
        int devnum = minor >> 1;
        struct mtd_info *mtd;
+       struct mtd_file_info *mfi;
 
        DEBUG(MTD_DEBUG_LEVEL0, "MTD_open\n");
 
@@ -117,14 +112,20 @@ static int mtd_open(struct inode *inode, struct file *file)
                return -ENODEV;
        }
 
-       file->private_data = mtd;
-
        /* You can't open it RW if it's not a writeable device */
        if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) {
                put_mtd_device(mtd);
                return -EACCES;
        }
 
+       mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
+       if (!mfi) {
+               put_mtd_device(mtd);
+               return -ENOMEM;
+       }
+       mfi->mtd = mtd;
+       file->private_data = mfi;
+
        return 0;
 } /* mtd_open */
 
@@ -132,16 +133,17 @@ static int mtd_open(struct inode *inode, struct file *file)
 
 static int mtd_close(struct inode *inode, struct file *file)
 {
-       struct mtd_info *mtd;
+       struct mtd_file_info *mfi = file->private_data;
+       struct mtd_info *mtd = mfi->mtd;
 
        DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n");
 
-       mtd = TO_MTD(file);
-
        if (mtd->sync)
                mtd->sync(mtd);
 
        put_mtd_device(mtd);
+       file->private_data = NULL;
+       kfree(mfi);
 
        return 0;
 } /* mtd_close */
@@ -153,7 +155,8 @@ static int mtd_close(struct inode *inode, struct file *file)
 
 static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos)
 {
-       struct mtd_info *mtd = TO_MTD(file);
+       struct mtd_file_info *mfi = file->private_data;
+       struct mtd_info *mtd = mfi->mtd;
        size_t retlen=0;
        size_t total_retlen=0;
        int ret=0;
@@ -170,36 +173,58 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
 
        /* FIXME: Use kiovec in 2.5 to lock down the user's buffers
           and pass them directly to the MTD functions */
+
+       if (count > MAX_KMALLOC_SIZE)
+               kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL);
+       else
+               kbuf=kmalloc(count, GFP_KERNEL);
+
+       if (!kbuf)
+               return -ENOMEM;
+
        while (count) {
+
                if (count > MAX_KMALLOC_SIZE)
                        len = MAX_KMALLOC_SIZE;
                else
                        len = count;
 
-               kbuf=kmalloc(len,GFP_KERNEL);
-               if (!kbuf)
-                       return -ENOMEM;
-
-               switch (MTD_MODE(file)) {
-               case MTD_MODE_OTP_FACT:
+               switch (mfi->mode) {
+               case MTD_MODE_OTP_FACTORY:
                        ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf);
                        break;
                case MTD_MODE_OTP_USER:
                        ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
                        break;
+               case MTD_MODE_RAW:
+               {
+                       struct mtd_oob_ops ops;
+
+                       ops.mode = MTD_OOB_RAW;
+                       ops.datbuf = kbuf;
+                       ops.oobbuf = NULL;
+                       ops.len = len;
+
+                       ret = mtd->read_oob(mtd, *ppos, &ops);
+                       retlen = ops.retlen;
+                       break;
+               }
                default:
-                       ret = MTD_READ(mtd, *ppos, len, &retlen, kbuf);
+                       ret = mtd->read(mtd, *ppos, len, &retlen, kbuf);
                }
                /* Nand returns -EBADMSG on ecc errors, but it returns
                 * the data. For our userspace tools it is important
                 * to dump areas with ecc errors !
+                * For kernel internal usage it also might return -EUCLEAN
+                * to signal the caller that a bitflip has occured and has
+                * been corrected by the ECC algorithm.
                 * Userspace software which accesses NAND this way
                 * must be aware of the fact that it deals with NAND
                 */
-               if (!ret || (ret == -EBADMSG)) {
+               if (!ret || (ret == -EUCLEAN) || (ret == -EBADMSG)) {
                        *ppos += retlen;
                        if (copy_to_user(buf, kbuf, retlen)) {
-                               kfree(kbuf);
+                               kfree(kbuf);
                                return -EFAULT;
                        }
                        else
@@ -215,15 +240,16 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
                        return ret;
                }
 
-               kfree(kbuf);
        }
 
+       kfree(kbuf);
        return total_retlen;
 } /* mtd_read */
 
 static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count,loff_t *ppos)
 {
-       struct mtd_info *mtd = TO_MTD(file);
+       struct mtd_file_info *mfi = file->private_data;
+       struct mtd_info *mtd = mfi->mtd;
        char *kbuf;
        size_t retlen;
        size_t total_retlen=0;
@@ -241,25 +267,28 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
        if (!count)
                return 0;
 
+       if (count > MAX_KMALLOC_SIZE)
+               kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL);
+       else
+               kbuf=kmalloc(count, GFP_KERNEL);
+
+       if (!kbuf)
+               return -ENOMEM;
+
        while (count) {
+
                if (count > MAX_KMALLOC_SIZE)
                        len = MAX_KMALLOC_SIZE;
                else
                        len = count;
 
-               kbuf=kmalloc(len,GFP_KERNEL);
-               if (!kbuf) {
-                       printk("kmalloc is null\n");
-                       return -ENOMEM;
-               }
-
                if (copy_from_user(kbuf, buf, len)) {
                        kfree(kbuf);
                        return -EFAULT;
                }
 
-               switch (MTD_MODE(file)) {
-               case MTD_MODE_OTP_FACT:
+               switch (mfi->mode) {
+               case MTD_MODE_OTP_FACTORY:
                        ret = -EROFS;
                        break;
                case MTD_MODE_OTP_USER:
@@ -269,6 +298,21 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
                        }
                        ret = mtd->write_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
                        break;
+
+               case MTD_MODE_RAW:
+               {
+                       struct mtd_oob_ops ops;
+
+                       ops.mode = MTD_OOB_RAW;
+                       ops.datbuf = kbuf;
+                       ops.oobbuf = NULL;
+                       ops.len = len;
+
+                       ret = mtd->write_oob(mtd, *ppos, &ops);
+                       retlen = ops.retlen;
+                       break;
+               }
+
                default:
                        ret = (*(mtd->write))(mtd, *ppos, len, &retlen, kbuf);
                }
@@ -282,10 +326,9 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
                        kfree(kbuf);
                        return ret;
                }
-
-               kfree(kbuf);
        }
 
+       kfree(kbuf);
        return total_retlen;
 } /* mtd_write */
 
@@ -299,13 +342,45 @@ static void mtdchar_erase_callback (struct erase_info *instr)
        wake_up((wait_queue_head_t *)instr->priv);
 }
 
+#if defined(CONFIG_MTD_OTP) || defined(CONFIG_MTD_ONENAND_OTP)
+static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
+{
+       struct mtd_info *mtd = mfi->mtd;
+       int ret = 0;
+
+       switch (mode) {
+       case MTD_OTP_FACTORY:
+               if (!mtd->read_fact_prot_reg)
+                       ret = -EOPNOTSUPP;
+               else
+                       mfi->mode = MTD_MODE_OTP_FACTORY;
+               break;
+       case MTD_OTP_USER:
+               if (!mtd->read_fact_prot_reg)
+                       ret = -EOPNOTSUPP;
+               else
+                       mfi->mode = MTD_MODE_OTP_USER;
+               break;
+       default:
+               ret = -EINVAL;
+       case MTD_OTP_OFF:
+               break;
+       }
+       return ret;
+}
+#else
+# define otp_select_filemode(f,m)      -EOPNOTSUPP
+#endif
+
 static int mtd_ioctl(struct inode *inode, struct file *file,
                     u_int cmd, u_long arg)
 {
-       struct mtd_info *mtd = TO_MTD(file);
+       struct mtd_file_info *mfi = file->private_data;
+       struct mtd_info *mtd = mfi->mtd;
        void __user *argp = (void __user *)arg;
        int ret = 0;
        u_long size;
+       struct mtd_info_user info;
 
        DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
 
@@ -341,7 +416,15 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
        }
 
        case MEMGETINFO:
-               if (copy_to_user(argp, mtd, sizeof(struct mtd_info_user)))
+               info.type       = mtd->type;
+               info.flags      = mtd->flags;
+               info.size       = mtd->size;
+               info.erasesize  = mtd->erasesize;
+               info.writesize  = mtd->writesize;
+               info.oobsize    = mtd->oobsize;
+               info.ecctype    = mtd->ecctype;
+               info.eccsize    = mtd->eccsize;
+               if (copy_to_user(argp, &info, sizeof(struct mtd_info_user)))
                        return -EFAULT;
                break;
 
@@ -400,8 +483,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
        case MEMWRITEOOB:
        {
                struct mtd_oob_buf buf;
-               void *databuf;
-               ssize_t retlen;
+               struct mtd_oob_ops ops;
 
                if(!(file->f_mode & 2))
                        return -EPERM;
@@ -409,7 +491,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
                if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
                        return -EFAULT;
 
-               if (buf.length > 0x4096)
+               if (buf.length > 4096)
                        return -EINVAL;
 
                if (!mtd->write_oob)
@@ -421,21 +503,32 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
                if (ret)
                        return ret;
 
-               databuf = kmalloc(buf.length, GFP_KERNEL);
-               if (!databuf)
+               ops.len = buf.length;
+               ops.ooblen = buf.length;
+               ops.ooboffs = buf.start & (mtd->oobsize - 1);
+               ops.datbuf = NULL;
+               ops.mode = MTD_OOB_PLACE;
+
+               if (ops.ooboffs && ops.len > (mtd->oobsize - ops.ooboffs))
+                       return -EINVAL;
+
+               ops.oobbuf = kmalloc(buf.length, GFP_KERNEL);
+               if (!ops.oobbuf)
                        return -ENOMEM;
 
-               if (copy_from_user(databuf, buf.ptr, buf.length)) {
-                       kfree(databuf);
+               if (copy_from_user(ops.oobbuf, buf.ptr, buf.length)) {
+                       kfree(ops.oobbuf);
                        return -EFAULT;
                }
 
-               ret = (mtd->write_oob)(mtd, buf.start, buf.length, &retlen, databuf);
+               buf.start &= ~(mtd->oobsize - 1);
+               ret = mtd->write_oob(mtd, buf.start, &ops);
 
-               if (copy_to_user(argp + sizeof(uint32_t), &retlen, sizeof(uint32_t)))
+               if (copy_to_user(argp + sizeof(uint32_t), &ops.retlen,
+                                sizeof(uint32_t)))
                        ret = -EFAULT;
 
-               kfree(databuf);
+               kfree(ops.oobbuf);
                break;
 
        }
@@ -443,13 +536,12 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
        case MEMREADOOB:
        {
                struct mtd_oob_buf buf;
-               void *databuf;
-               ssize_t retlen;
+               struct mtd_oob_ops ops;
 
                if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
                        return -EFAULT;
 
-               if (buf.length > 0x4096)
+               if (buf.length > 4096)
                        return -EINVAL;
 
                if (!mtd->read_oob)
@@ -457,22 +549,32 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
                else
                        ret = access_ok(VERIFY_WRITE, buf.ptr,
                                        buf.length) ? 0 : -EFAULT;
-
                if (ret)
                        return ret;
 
-               databuf = kmalloc(buf.length, GFP_KERNEL);
-               if (!databuf)
+               ops.len = buf.length;
+               ops.ooblen = buf.length;
+               ops.ooboffs = buf.start & (mtd->oobsize - 1);
+               ops.datbuf = NULL;
+               ops.mode = MTD_OOB_PLACE;
+
+               if (ops.ooboffs && ops.len > (mtd->oobsize - ops.ooboffs))
+                       return -EINVAL;
+
+               ops.oobbuf = kmalloc(buf.length, GFP_KERNEL);
+               if (!ops.oobbuf)
                        return -ENOMEM;
 
-               ret = (mtd->read_oob)(mtd, buf.start, buf.length, &retlen, databuf);
+               buf.start &= ~(mtd->oobsize - 1);
+               ret = mtd->read_oob(mtd, buf.start, &ops);
 
-               if (put_user(retlen, (uint32_t __user *)argp))
+               if (put_user(ops.retlen, (uint32_t __user *)argp))
                        ret = -EFAULT;
-               else if (retlen && copy_to_user(buf.ptr, databuf, retlen))
+               else if (ops.retlen && copy_to_user(buf.ptr, ops.oobbuf,
+                                                   ops.retlen))
                        ret = -EFAULT;
 
-               kfree(databuf);
+               kfree(ops.oobbuf);
                break;
        }
 
@@ -504,16 +606,22 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
                break;
        }
 
-       case MEMSETOOBSEL:
-       {
-               if (copy_from_user(&mtd->oobinfo, argp, sizeof(struct nand_oobinfo)))
-                       return -EFAULT;
-               break;
-       }
-
+       /* Legacy interface */
        case MEMGETOOBSEL:
        {
-               if (copy_to_user(argp, &(mtd->oobinfo), sizeof(struct nand_oobinfo)))
+               struct nand_oobinfo oi;
+
+               if (!mtd->ecclayout)
+                       return -EOPNOTSUPP;
+               if (mtd->ecclayout->eccbytes > ARRAY_SIZE(oi.eccpos))
+                       return -EINVAL;
+
+               oi.useecc = MTD_NANDECC_AUTOPLACE;
+               memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos));
+               memcpy(&oi.oobfree, mtd->ecclayout->oobfree,
+                      sizeof(oi.oobfree));
+
+               if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo)))
                        return -EFAULT;
                break;
        }
@@ -544,31 +652,17 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
                break;
        }
 
-#ifdef CONFIG_MTD_OTP
+#if defined(CONFIG_MTD_OTP) || defined(CONFIG_MTD_ONENAND_OTP)
        case OTPSELECT:
        {
                int mode;
                if (copy_from_user(&mode, argp, sizeof(int)))
                        return -EFAULT;
-               SET_MTD_MODE(file, 0);
-               switch (mode) {
-               case MTD_OTP_FACTORY:
-                       if (!mtd->read_fact_prot_reg)
-                               ret = -EOPNOTSUPP;
-                       else
-                               SET_MTD_MODE(file, MTD_MODE_OTP_FACT);
-                       break;
-               case MTD_OTP_USER:
-                       if (!mtd->read_fact_prot_reg)
-                               ret = -EOPNOTSUPP;
-                       else
-                               SET_MTD_MODE(file, MTD_MODE_OTP_USER);
-                       break;
-               default:
-                       ret = -EINVAL;
-               case MTD_OTP_OFF:
-                       break;
-               }
+
+               mfi->mode = MTD_MODE_NORMAL;
+
+               ret = otp_select_filemode(mfi, mode);
+
                file->f_pos = 0;
                break;
        }
@@ -580,8 +674,8 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
                if (!buf)
                        return -ENOMEM;
                ret = -EOPNOTSUPP;
-               switch (MTD_MODE(file)) {
-               case MTD_MODE_OTP_FACT:
+               switch (mfi->mode) {
+               case MTD_MODE_OTP_FACTORY:
                        if (mtd->get_fact_prot_info)
                                ret = mtd->get_fact_prot_info(mtd, buf, 4096);
                        break;
@@ -589,6 +683,8 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
                        if (mtd->get_user_prot_info)
                                ret = mtd->get_user_prot_info(mtd, buf, 4096);
                        break;
+               default:
+                       break;
                }
                if (ret >= 0) {
                        if (cmd == OTPGETREGIONCOUNT) {
@@ -607,7 +703,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
        {
                struct otp_info info;
 
-               if (MTD_MODE(file) != MTD_MODE_OTP_USER)
+               if (mfi->mode != MTD_MODE_OTP_USER)
                        return -EINVAL;
                if (copy_from_user(&info, argp, sizeof(info)))
                        return -EFAULT;
@@ -618,6 +714,49 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
        }
 #endif
 
+       case ECCGETLAYOUT:
+       {
+               if (!mtd->ecclayout)
+                       return -EOPNOTSUPP;
+
+               if (copy_to_user(argp, &mtd->ecclayout,
+                                sizeof(struct nand_ecclayout)))
+                       return -EFAULT;
+               break;
+       }
+
+       case ECCGETSTATS:
+       {
+               if (copy_to_user(argp, &mtd->ecc_stats,
+                                sizeof(struct mtd_ecc_stats)))
+                       return -EFAULT;
+               break;
+       }
+
+       case MTDFILEMODE:
+       {
+               mfi->mode = 0;
+
+               switch(arg) {
+               case MTD_MODE_OTP_FACTORY:
+               case MTD_MODE_OTP_USER:
+                       ret = otp_select_filemode(mfi, arg);
+                       break;
+
+               case MTD_MODE_RAW:
+                       if (!mtd->read_oob || !mtd->write_oob)
+                               return -EOPNOTSUPP;
+                       mfi->mode = arg;
+
+               case MTD_MODE_NORMAL:
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
+               file->f_pos = 0;
+               break;
+       }
+
        default:
                ret = -ENOTTY;
        }
index 9af8403..1fea631 100644 (file)
@@ -19,6 +19,8 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/concat.h>
 
+#include <asm/div64.h>
+
 /*
  * Our storage structure:
  * Subdev points to an array of pointers to struct mtd_info objects
@@ -54,7 +56,7 @@ concat_read(struct mtd_info *mtd, loff_t from, size_t len,
            size_t * retlen, u_char * buf)
 {
        struct mtd_concat *concat = CONCAT(mtd);
-       int err = -EINVAL;
+       int ret = 0, err;
        int i;
 
        *retlen = 0;
@@ -78,19 +80,29 @@ concat_read(struct mtd_info *mtd, loff_t from, size_t len,
 
                err = subdev->read(subdev, from, size, &retsize, buf);
 
-               if (err)
-                       break;
+               /* Save information about bitflips! */
+               if (unlikely(err)) {
+                       if (err == -EBADMSG) {
+                               mtd->ecc_stats.failed++;
+                               ret = err;
+                       } else if (err == -EUCLEAN) {
+                               mtd->ecc_stats.corrected++;
+                               /* Do not overwrite -EBADMSG !! */
+                               if (!ret)
+                                       ret = err;
+                       } else
+                               return err;
+               }
 
                *retlen += retsize;
                len -= size;
                if (len == 0)
-                       break;
+                       return ret;
 
-               err = -EINVAL;
                buf += size;
                from = 0;
        }
-       return err;
+       return -EINVAL;
 }
 
 static int
@@ -141,211 +153,185 @@ concat_write(struct mtd_info *mtd, loff_t to, size_t len,
 }
 
 static int
-concat_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
-               size_t * retlen, u_char * buf, u_char * eccbuf,
-               struct nand_oobinfo *oobsel)
+concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
+               unsigned long count, loff_t to, size_t * retlen)
 {
        struct mtd_concat *concat = CONCAT(mtd);
-       int err = -EINVAL;
+       struct kvec *vecs_copy;
+       unsigned long entry_low, entry_high;
+       size_t total_len = 0;
        int i;
+       int err = -EINVAL;
 
-       *retlen = 0;
-
-       for (i = 0; i < concat->num_subdev; i++) {
-               struct mtd_info *subdev = concat->subdev[i];
-               size_t size, retsize;
-
-               if (from >= subdev->size) {
-                       /* Not destined for this subdev */
-                       size = 0;
-                       from -= subdev->size;
-                       continue;
-               }
-
-               if (from + len > subdev->size)
-                       /* First part goes into this subdev */
-                       size = subdev->size - from;
-               else
-                       /* Entire transaction goes into this subdev */
-                       size = len;
+       if (!(mtd->flags & MTD_WRITEABLE))
+               return -EROFS;
 
-               if (subdev->read_ecc)
-                       err = subdev->read_ecc(subdev, from, size,
-                                              &retsize, buf, eccbuf, oobsel);
-               else
-                       err = -EINVAL;
+       *retlen = 0;
 
-               if (err)
-                       break;
+       /* Calculate total length of data */
+       for (i = 0; i < count; i++)
+               total_len += vecs[i].iov_len;
 
-               *retlen += retsize;
-               len -= size;
-               if (len == 0)
-                       break;
+       /* Do not allow write past end of device */
+       if ((to + total_len) > mtd->size)
+               return -EINVAL;
 
-               err = -EINVAL;
-               buf += size;
-               if (eccbuf) {
-                       eccbuf += subdev->oobsize;
-                       /* in nand.c at least, eccbufs are
-                          tagged with 2 (int)eccstatus'; we
-                          must account for these */
-                       eccbuf += 2 * (sizeof (int));
-               }
-               from = 0;
+       /* Check alignment */
+       if (mtd->writesize > 1) {
+               loff_t __to = to;
+               if (do_div(__to, mtd->writesize) || (total_len % mtd->writesize))
+                       return -EINVAL;
        }
-       return err;
-}
 
-static int
-concat_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
-                size_t * retlen, const u_char * buf, u_char * eccbuf,
-                struct nand_oobinfo *oobsel)
-{
-       struct mtd_concat *concat = CONCAT(mtd);
-       int err = -EINVAL;
-       int i;
-
-       if (!(mtd->flags & MTD_WRITEABLE))
-               return -EROFS;
-
-       *retlen = 0;
+       /* make a copy of vecs */
+       vecs_copy = kmalloc(sizeof(struct kvec) * count, GFP_KERNEL);
+       if (!vecs_copy)
+               return -ENOMEM;
+       memcpy(vecs_copy, vecs, sizeof(struct kvec) * count);
 
+       entry_low = 0;
        for (i = 0; i < concat->num_subdev; i++) {
                struct mtd_info *subdev = concat->subdev[i];
-               size_t size, retsize;
+               size_t size, wsize, retsize, old_iov_len;
 
                if (to >= subdev->size) {
-                       size = 0;
                        to -= subdev->size;
                        continue;
                }
-               if (to + len > subdev->size)
-                       size = subdev->size - to;
-               else
-                       size = len;
+
+               size = min(total_len, (size_t)(subdev->size - to));
+               wsize = size; /* store for future use */
+
+               entry_high = entry_low;
+               while (entry_high < count) {
+                       if (size <= vecs_copy[entry_high].iov_len)
+                               break;
+                       size -= vecs_copy[entry_high++].iov_len;
+               }
+
+               old_iov_len = vecs_copy[entry_high].iov_len;
+               vecs_copy[entry_high].iov_len = size;
 
                if (!(subdev->flags & MTD_WRITEABLE))
                        err = -EROFS;
-               else if (subdev->write_ecc)
-                       err = subdev->write_ecc(subdev, to, size,
-                                               &retsize, buf, eccbuf, oobsel);
                else
-                       err = -EINVAL;
+                       err = subdev->writev(subdev, &vecs_copy[entry_low],
+                               entry_high - entry_low + 1, to, &retsize);
+
+               vecs_copy[entry_high].iov_len = old_iov_len - size;
+               vecs_copy[entry_high].iov_base += size;
+
+               entry_low = entry_high;
 
                if (err)
                        break;
 
                *retlen += retsize;
-               len -= size;
-               if (len == 0)
+               total_len -= wsize;
+
+               if (total_len == 0)
                        break;
 
                err = -EINVAL;
-               buf += size;
-               if (eccbuf)
-                       eccbuf += subdev->oobsize;
                to = 0;
        }
+
+       kfree(vecs_copy);
        return err;
 }
 
 static int
-concat_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
-               size_t * retlen, u_char * buf)
+concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
 {
        struct mtd_concat *concat = CONCAT(mtd);
-       int err = -EINVAL;
-       int i;
+       struct mtd_oob_ops devops = *ops;
+       int i, err, ret = 0;
 
-       *retlen = 0;
+       ops->retlen = 0;
 
        for (i = 0; i < concat->num_subdev; i++) {
                struct mtd_info *subdev = concat->subdev[i];
-               size_t size, retsize;
 
                if (from >= subdev->size) {
-                       /* Not destined for this subdev */
-                       size = 0;
                        from -= subdev->size;
                        continue;
                }
-               if (from + len > subdev->size)
-                       /* First part goes into this subdev */
-                       size = subdev->size - from;
-               else
-                       /* Entire transaction goes into this subdev */
-                       size = len;
 
-               if (subdev->read_oob)
-                       err = subdev->read_oob(subdev, from, size,
-                                              &retsize, buf);
-               else
-                       err = -EINVAL;
+               /* partial read ? */
+               if (from + devops.len > subdev->size)
+                       devops.len = subdev->size - from;
+
+               err = subdev->read_oob(subdev, from, &devops);
+               ops->retlen += devops.retlen;
+
+               /* Save information about bitflips! */
+               if (unlikely(err)) {
+                       if (err == -EBADMSG) {
+                               mtd->ecc_stats.failed++;
+                               ret = err;
+                       } else if (err == -EUCLEAN) {
+                               mtd->ecc_stats.corrected++;
+                               /* Do not overwrite -EBADMSG !! */
+                               if (!ret)
+                                       ret = err;
+                       } else
+                               return err;
+               }
 
-               if (err)
-                       break;
+               devops.len = ops->len - ops->retlen;
+               if (!devops.len)
+                       return ret;
 
-               *retlen += retsize;
-               len -= size;
-               if (len == 0)
-                       break;
+               if (devops.datbuf)
+                       devops.datbuf += devops.retlen;
+               if (devops.oobbuf)
+                       devops.oobbuf += devops.ooblen;
 
-               err = -EINVAL;
-               buf += size;
                from = 0;
        }
-       return err;
+       return -EINVAL;
 }
 
 static int
-concat_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
-                size_t * retlen, const u_char * buf)
+concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
 {
        struct mtd_concat *concat = CONCAT(mtd);
-       int err = -EINVAL;
-       int i;
+       struct mtd_oob_ops devops = *ops;
+       int i, err;
 
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
 
-       *retlen = 0;
+       ops->retlen = 0;
 
        for (i = 0; i < concat->num_subdev; i++) {
                struct mtd_info *subdev = concat->subdev[i];
-               size_t size, retsize;
 
                if (to >= subdev->size) {
-                       size = 0;
                        to -= subdev->size;
                        continue;
                }
-               if (to + len > subdev->size)
-                       size = subdev->size - to;
-               else
-                       size = len;
 
-               if (!(subdev->flags & MTD_WRITEABLE))
-                       err = -EROFS;
-               else if (subdev->write_oob)
-                       err = subdev->write_oob(subdev, to, size, &retsize,
-                                               buf);
-               else
-                       err = -EINVAL;
+               /* partial write ? */
+               if (to + devops.len > subdev->size)
+                       devops.len = subdev->size - to;
 
+               err = subdev->write_oob(subdev, to, &devops);
+               ops->retlen += devops.retlen;
                if (err)
-                       break;
+                       return err;
 
-               *retlen += retsize;
-               len -= size;
-               if (len == 0)
-                       break;
+               devops.len = ops->len - ops->retlen;
+               if (!devops.len)
+                       return 0;
 
-               err = -EINVAL;
-               buf += size;
+               if (devops.datbuf)
+                       devops.datbuf += devops.retlen;
+               if (devops.oobbuf)
+                       devops.oobbuf += devops.ooblen;
                to = 0;
        }
-       return err;
+       return -EINVAL;
 }
 
 static void concat_erase_callback(struct erase_info *instr)
@@ -636,6 +622,60 @@ static void concat_resume(struct mtd_info *mtd)
        }
 }
 
+static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
+{
+       struct mtd_concat *concat = CONCAT(mtd);
+       int i, res = 0;
+
+       if (!concat->subdev[0]->block_isbad)
+               return res;
+
+       if (ofs > mtd->size)
+               return -EINVAL;
+
+       for (i = 0; i < concat->num_subdev; i++) {
+               struct mtd_info *subdev = concat->subdev[i];
+
+               if (ofs >= subdev->size) {
+                       ofs -= subdev->size;
+                       continue;
+               }
+
+               res = subdev->block_isbad(subdev, ofs);
+               break;
+       }
+
+       return res;
+}
+
+static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs)
+{
+       struct mtd_concat *concat = CONCAT(mtd);
+       int i, err = -EINVAL;
+
+       if (!concat->subdev[0]->block_markbad)
+               return 0;
+
+       if (ofs > mtd->size)
+               return -EINVAL;
+
+       for (i = 0; i < concat->num_subdev; i++) {
+               struct mtd_info *subdev = concat->subdev[i];
+
+               if (ofs >= subdev->size) {
+                       ofs -= subdev->size;
+                       continue;
+               }
+
+               err = subdev->block_markbad(subdev, ofs);
+               if (!err)
+                       mtd->ecc_stats.badblocks++;
+               break;
+       }
+
+       return err;
+}
+
 /*
  * This function constructs a virtual MTD device by concatenating
  * num_devs MTD devices. A pointer to the new device object is
@@ -677,18 +717,22 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[],     /* subdevices to c
        concat->mtd.flags = subdev[0]->flags;
        concat->mtd.size = subdev[0]->size;
        concat->mtd.erasesize = subdev[0]->erasesize;
-       concat->mtd.oobblock = subdev[0]->oobblock;
+       concat->mtd.writesize = subdev[0]->writesize;
        concat->mtd.oobsize = subdev[0]->oobsize;
        concat->mtd.ecctype = subdev[0]->ecctype;
        concat->mtd.eccsize = subdev[0]->eccsize;
-       if (subdev[0]->read_ecc)
-               concat->mtd.read_ecc = concat_read_ecc;
-       if (subdev[0]->write_ecc)
-               concat->mtd.write_ecc = concat_write_ecc;
+       if (subdev[0]->writev)
+               concat->mtd.writev = concat_writev;
        if (subdev[0]->read_oob)
                concat->mtd.read_oob = concat_read_oob;
        if (subdev[0]->write_oob)
                concat->mtd.write_oob = concat_write_oob;
+       if (subdev[0]->block_isbad)
+               concat->mtd.block_isbad = concat_block_isbad;
+       if (subdev[0]->block_markbad)
+               concat->mtd.block_markbad = concat_block_markbad;
+
+       concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks;
 
        concat->subdev[0] = subdev[0];
 
@@ -717,12 +761,12 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[],     /* subdevices to c
                                    subdev[i]->flags & MTD_WRITEABLE;
                }
                concat->mtd.size += subdev[i]->size;
-               if (concat->mtd.oobblock   !=  subdev[i]->oobblock ||
+               concat->mtd.ecc_stats.badblocks +=
+                       subdev[i]->ecc_stats.badblocks;
+               if (concat->mtd.writesize   !=  subdev[i]->writesize ||
                    concat->mtd.oobsize    !=  subdev[i]->oobsize ||
                    concat->mtd.ecctype    !=  subdev[i]->ecctype ||
                    concat->mtd.eccsize    !=  subdev[i]->eccsize ||
-                   !concat->mtd.read_ecc  != !subdev[i]->read_ecc ||
-                   !concat->mtd.write_ecc != !subdev[i]->write_ecc ||
                    !concat->mtd.read_oob  != !subdev[i]->read_oob ||
                    !concat->mtd.write_oob != !subdev[i]->write_oob) {
                        kfree(concat);
@@ -734,14 +778,11 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[],     /* subdevices to c
 
        }
 
+       concat->mtd.ecclayout = subdev[0]->ecclayout;
+
        concat->num_subdev = num_devs;
        concat->mtd.name = name;
 
-       /*
-        * NOTE: for now, we do not provide any readv()/writev() methods
-        *       because they are messy to implement and they are not
-        *       used to a great extent anyway.
-        */
        concat->mtd.erase = concat_erase;
        concat->mtd.read = concat_read;
        concat->mtd.write = concat_write;
index 9905870..16a952d 100644 (file)
@@ -47,6 +47,7 @@ int add_mtd_device(struct mtd_info *mtd)
 {
        int i;
 
+       BUG_ON(mtd->writesize == 0);
        mutex_lock(&mtd_table_mutex);
 
        for (i=0; i < MAX_MTD_DEVICES; i++)
@@ -254,37 +255,6 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
        return ret;
 }
 
-
-/* default_mtd_readv - default mtd readv method for MTD devices that dont
- *                    implement their own
- */
-
-int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
-                     unsigned long count, loff_t from, size_t *retlen)
-{
-       unsigned long i;
-       size_t totlen = 0, thislen;
-       int ret = 0;
-
-       if(!mtd->read) {
-               ret = -EIO;
-       } else {
-               for (i=0; i<count; i++) {
-                       if (!vecs[i].iov_len)
-                               continue;
-                       ret = mtd->read(mtd, from, vecs[i].iov_len, &thislen, vecs[i].iov_base);
-                       totlen += thislen;
-                       if (ret || thislen != vecs[i].iov_len)
-                               break;
-                       from += vecs[i].iov_len;
-               }
-       }
-       if (retlen)
-               *retlen = totlen;
-       return ret;
-}
-
-
 EXPORT_SYMBOL(add_mtd_device);
 EXPORT_SYMBOL(del_mtd_device);
 EXPORT_SYMBOL(get_mtd_device);
@@ -292,7 +262,6 @@ EXPORT_SYMBOL(put_mtd_device);
 EXPORT_SYMBOL(register_mtd_user);
 EXPORT_SYMBOL(unregister_mtd_user);
 EXPORT_SYMBOL(default_mtd_writev);
-EXPORT_SYMBOL(default_mtd_readv);
 
 #ifdef CONFIG_PROC_FS
 
index 9939591..77a7123 100644 (file)
@@ -51,16 +51,21 @@ static int part_read (struct mtd_info *mtd, loff_t from, size_t len,
                        size_t *retlen, u_char *buf)
 {
        struct mtd_part *part = PART(mtd);
+       int res;
+
        if (from >= mtd->size)
                len = 0;
        else if (from + len > mtd->size)
                len = mtd->size - from;
-       if (part->master->read_ecc == NULL)
-               return part->master->read (part->master, from + part->offset,
-                                       len, retlen, buf);
-       else
-               return part->master->read_ecc (part->master, from + part->offset,
-                                       len, retlen, buf, NULL, &mtd->oobinfo);
+       res = part->master->read (part->master, from + part->offset,
+                                  len, retlen, buf);
+       if (unlikely(res)) {
+               if (res == -EUCLEAN)
+                       mtd->ecc_stats.corrected++;
+               if (res == -EBADMSG)
+                       mtd->ecc_stats.failed++;
+       }
+       return res;
 }
 
 static int part_point (struct mtd_info *mtd, loff_t from, size_t len,
@@ -74,6 +79,7 @@ static int part_point (struct mtd_info *mtd, loff_t from, size_t len,
        return part->master->point (part->master, from + part->offset,
                                    len, retlen, buf);
 }
+
 static void part_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_t len)
 {
        struct mtd_part *part = PART(mtd);
@@ -81,31 +87,25 @@ static void part_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_
        part->master->unpoint (part->master, addr, from + part->offset, len);
 }
 
-
-static int part_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
-                       size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel)
+static int part_read_oob(struct mtd_info *mtd, loff_t from,
+                        struct mtd_oob_ops *ops)
 {
        struct mtd_part *part = PART(mtd);
-       if (oobsel == NULL)
-               oobsel = &mtd->oobinfo;
-       if (from >= mtd->size)
-               len = 0;
-       else if (from + len > mtd->size)
-               len = mtd->size - from;
-       return part->master->read_ecc (part->master, from + part->offset,
-                                       len, retlen, buf, eccbuf, oobsel);
-}
+       int res;
 
-static int part_read_oob (struct mtd_info *mtd, loff_t from, size_t len,
-                       size_t *retlen, u_char *buf)
-{
-       struct mtd_part *part = PART(mtd);
        if (from >= mtd->size)
-               len = 0;
-       else if (from + len > mtd->size)
-               len = mtd->size - from;
-       return part->master->read_oob (part->master, from + part->offset,
-                                       len, retlen, buf);
+               return -EINVAL;
+       if (from + ops->len > mtd->size)
+               return -EINVAL;
+       res = part->master->read_oob(part->master, from + part->offset, ops);
+
+       if (unlikely(res)) {
+               if (res == -EUCLEAN)
+                       mtd->ecc_stats.corrected++;
+               if (res == -EBADMSG)
+                       mtd->ecc_stats.failed++;
+       }
+       return res;
 }
 
 static int part_read_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len,
@@ -148,44 +148,23 @@ static int part_write (struct mtd_info *mtd, loff_t to, size_t len,
                len = 0;
        else if (to + len > mtd->size)
                len = mtd->size - to;
-       if (part->master->write_ecc == NULL)
-               return part->master->write (part->master, to + part->offset,
-                                       len, retlen, buf);
-       else
-               return part->master->write_ecc (part->master, to + part->offset,
-                                       len, retlen, buf, NULL, &mtd->oobinfo);
-
+       return part->master->write (part->master, to + part->offset,
+                                   len, retlen, buf);
 }
 
-static int part_write_ecc (struct mtd_info *mtd, loff_t to, size_t len,
-                       size_t *retlen, const u_char *buf,
-                        u_char *eccbuf, struct nand_oobinfo *oobsel)
+static int part_write_oob(struct mtd_info *mtd, loff_t to,
+                        struct mtd_oob_ops *ops)
 {
        struct mtd_part *part = PART(mtd);
-       if (!(mtd->flags & MTD_WRITEABLE))
-               return -EROFS;
-       if (oobsel == NULL)
-               oobsel = &mtd->oobinfo;
-       if (to >= mtd->size)
-               len = 0;
-       else if (to + len > mtd->size)
-               len = mtd->size - to;
-       return part->master->write_ecc (part->master, to + part->offset,
-                                       len, retlen, buf, eccbuf, oobsel);
-}
 
-static int part_write_oob (struct mtd_info *mtd, loff_t to, size_t len,
-                       size_t *retlen, const u_char *buf)
-{
-       struct mtd_part *part = PART(mtd);
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
+
        if (to >= mtd->size)
-               len = 0;
-       else if (to + len > mtd->size)
-               len = mtd->size - to;
-       return part->master->write_oob (part->master, to + part->offset,
-                                       len, retlen, buf);
+               return -EINVAL;
+       if (to + ops->len > mtd->size)
+               return -EINVAL;
+       return part->master->write_oob(part->master, to + part->offset, ops);
 }
 
 static int part_write_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len,
@@ -208,52 +187,8 @@ static int part_writev (struct mtd_info *mtd,  const struct kvec *vecs,
        struct mtd_part *part = PART(mtd);
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
-       if (part->master->writev_ecc == NULL)
-               return part->master->writev (part->master, vecs, count,
+       return part->master->writev (part->master, vecs, count,
                                        to + part->offset, retlen);
-       else
-               return part->master->writev_ecc (part->master, vecs, count,
-                                       to + part->offset, retlen,
-                                       NULL, &mtd->oobinfo);
-}
-
-static int part_readv (struct mtd_info *mtd,  struct kvec *vecs,
-                        unsigned long count, loff_t from, size_t *retlen)
-{
-       struct mtd_part *part = PART(mtd);
-       if (part->master->readv_ecc == NULL)
-               return part->master->readv (part->master, vecs, count,
-                                       from + part->offset, retlen);
-       else
-               return part->master->readv_ecc (part->master, vecs, count,
-                                       from + part->offset, retlen,
-                                       NULL, &mtd->oobinfo);
-}
-
-static int part_writev_ecc (struct mtd_info *mtd,  const struct kvec *vecs,
-                        unsigned long count, loff_t to, size_t *retlen,
-                        u_char *eccbuf,  struct nand_oobinfo *oobsel)
-{
-       struct mtd_part *part = PART(mtd);
-       if (!(mtd->flags & MTD_WRITEABLE))
-               return -EROFS;
-       if (oobsel == NULL)
-               oobsel = &mtd->oobinfo;
-       return part->master->writev_ecc (part->master, vecs, count,
-                                       to + part->offset, retlen,
-                                       eccbuf, oobsel);
-}
-
-static int part_readv_ecc (struct mtd_info *mtd,  struct kvec *vecs,
-                        unsigned long count, loff_t from, size_t *retlen,
-                        u_char *eccbuf,  struct nand_oobinfo *oobsel)
-{
-       struct mtd_part *part = PART(mtd);
-       if (oobsel == NULL)
-               oobsel = &mtd->oobinfo;
-       return part->master->readv_ecc (part->master, vecs, count,
-                                       from + part->offset, retlen,
-                                       eccbuf, oobsel);
 }
 
 static int part_erase (struct mtd_info *mtd, struct erase_info *instr)
@@ -329,12 +264,17 @@ static int part_block_isbad (struct mtd_info *mtd, loff_t ofs)
 static int part_block_markbad (struct mtd_info *mtd, loff_t ofs)
 {
        struct mtd_part *part = PART(mtd);
+       int res;
+
        if (!(mtd->flags & MTD_WRITEABLE))
                return -EROFS;
        if (ofs >= mtd->size)
                return -EINVAL;
        ofs += part->offset;
-       return part->master->block_markbad(part->master, ofs);
+       res = part->master->block_markbad(part->master, ofs);
+       if (!res)
+               mtd->ecc_stats.badblocks++;
+       return res;
 }
 
 /*
@@ -398,7 +338,7 @@ int add_mtd_partitions(struct mtd_info *master,
                slave->mtd.type = master->type;
                slave->mtd.flags = master->flags & ~parts[i].mask_flags;
                slave->mtd.size = parts[i].size;
-               slave->mtd.oobblock = master->oobblock;
+               slave->mtd.writesize = master->writesize;
                slave->mtd.oobsize = master->oobsize;
                slave->mtd.ecctype = master->ecctype;
                slave->mtd.eccsize = master->eccsize;
@@ -415,10 +355,6 @@ int add_mtd_partitions(struct mtd_info *master,
                        slave->mtd.unpoint = part_unpoint;
                }
 
-               if (master->read_ecc)
-                       slave->mtd.read_ecc = part_read_ecc;
-               if (master->write_ecc)
-                       slave->mtd.write_ecc = part_write_ecc;
                if (master->read_oob)
                        slave->mtd.read_oob = part_read_oob;
                if (master->write_oob)
@@ -443,12 +379,6 @@ int add_mtd_partitions(struct mtd_info *master,
                }
                if (master->writev)
                        slave->mtd.writev = part_writev;
-               if (master->readv)
-                       slave->mtd.readv = part_readv;
-               if (master->writev_ecc)
-                       slave->mtd.writev_ecc = part_writev_ecc;
-               if (master->readv_ecc)
-                       slave->mtd.readv_ecc = part_readv_ecc;
                if (master->lock)
                        slave->mtd.lock = part_lock;
                if (master->unlock)
@@ -528,8 +458,17 @@ int add_mtd_partitions(struct mtd_info *master,
                                parts[i].name);
                }
 
-               /* copy oobinfo from master */
-               memcpy(&slave->mtd.oobinfo, &master->oobinfo, sizeof(slave->mtd.oobinfo));
+               slave->mtd.ecclayout = master->ecclayout;
+               if (master->block_isbad) {
+                       uint32_t offs = 0;
+
+                       while(offs < slave->mtd.size) {
+                               if (master->block_isbad(master,
+                                                       offs + slave->offset))
+                                       slave->mtd.ecc_stats.badblocks++;
+                               offs += slave->mtd.erasesize;
+                       }
+               }
 
                if(parts[i].mtdp)
                {       /* store the object pointer (caller may or may not register it */
index cfe288a..3db77ee 100644 (file)
@@ -23,6 +23,14 @@ config MTD_NAND_VERIFY_WRITE
          device thinks the write was successful, a bit could have been
          flipped accidentaly due to device wear or something else.
 
+config MTD_NAND_ECC_SMC
+       bool "NAND ECC Smart Media byte order"
+       depends on MTD_NAND
+       default n
+       help
+         Software ECC according to the Smart Media Specification.
+         The original Linux implementation had byte 0 and 1 swapped.
+
 config MTD_NAND_AUTCPU12
        tristate "SmartMediaCard on autronix autcpu12 board"
        depends on MTD_NAND && ARCH_AUTCPU12
@@ -49,12 +57,24 @@ config MTD_NAND_SPIA
        help
          If you had to ask, you don't have one. Say 'N'.
 
+config MTD_NAND_AMS_DELTA
+       tristate "NAND Flash device on Amstrad E3"
+       depends on MACH_AMS_DELTA && MTD_NAND
+       help
+         Support for NAND flash on Amstrad E3 (Delta).
+
 config MTD_NAND_TOTO
        tristate "NAND Flash device on TOTO board"
-       depends on ARCH_OMAP && MTD_NAND
+       depends on ARCH_OMAP && MTD_NAND && BROKEN
        help
          Support for NAND flash on Texas Instruments Toto platform.
 
+config MTD_NAND_TS7250
+       tristate "NAND Flash device on TS-7250 board"
+       depends on MACH_TS72XX && MTD_NAND
+       help
+         Support for NAND flash on Technologic Systems TS-7250 platform.
+
 config MTD_NAND_IDS
        tristate
 
@@ -76,7 +96,7 @@ config MTD_NAND_RTC_FROM4
 
 config MTD_NAND_PPCHAMELEONEVB
        tristate "NAND Flash device on PPChameleonEVB board"
-       depends on PPCHAMELEONEVB && MTD_NAND
+       depends on PPCHAMELEONEVB && MTD_NAND && BROKEN
        help
          This enables the NAND flash driver on the PPChameleon EVB Board.
 
@@ -87,7 +107,7 @@ config MTD_NAND_S3C2410
          This enables the NAND flash controller on the S3C2410 and S3C2440
          SoCs
 
-         No board specfic support is done by this driver, each board
+         No board specific support is done by this driver, each board
          must advertise a platform_device for the driver to attach.
 
 config MTD_NAND_S3C2410_DEBUG
@@ -109,6 +129,22 @@ config MTD_NAND_S3C2410_HWECC
          currently not be able to switch to software, as there is no
          implementation for ECC method used by the S3C2410
 
+config MTD_NAND_NDFC
+       tristate "NDFC NanD Flash Controller"
+       depends on MTD_NAND && 44x
+       help
+        NDFC Nand Flash Controllers are integrated in EP44x SoCs
+
+config MTD_NAND_S3C2410_CLKSTOP
+       bool "S3C2410 NAND IDLE clock stop"
+       depends on MTD_NAND_S3C2410
+       default n
+       help
+         Stop the clock to the NAND controller when there is no chip
+         selected to save power. This will mean there is a small delay
+         when the is NAND chip selected or released, but will save
+         approximately 5mA of power when there is nothing happening.
+
 config MTD_NAND_DISKONCHIP
        tristate "DiskOnChip 2000, Millennium and Millennium Plus (NAND reimplementation) (EXPERIMENTAL)"
        depends on MTD_NAND && EXPERIMENTAL
@@ -183,11 +219,24 @@ config MTD_NAND_SHARPSL
        tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)"
        depends on MTD_NAND && ARCH_PXA
 
+config MTD_NAND_CS553X
+       tristate "NAND support for CS5535/CS5536 (AMD Geode companion chip)"
+       depends on MTD_NAND && X86_32 && (X86_PC || X86_GENERICARCH)
+       help
+         The CS553x companion chips for the AMD Geode processor
+         include NAND flash controllers with built-in hardware ECC
+         capabilities; enabling this option will allow you to use
+         these. The driver will check the MSRs to verify that the
+         controller is enabled for NAND, and currently requires that
+         the controller be in MMIO mode.
+
+         If you say "m", the module will be called "cs553x_nand.ko".
+
 config MTD_NAND_NANDSIM
        tristate "Support for NAND Flash Simulator"
        depends on MTD_NAND && MTD_PARTITIONS
        help
-         The simulator may simulate verious NAND flash chips for the
+         The simulator may simulate various NAND flash chips for the
          MTD nand layer.
 
 endmenu
index 4174202..f747593 100644 (file)
@@ -7,6 +7,7 @@ obj-$(CONFIG_MTD_NAND)                  += nand.o nand_ecc.o
 obj-$(CONFIG_MTD_NAND_IDS)             += nand_ids.o
 
 obj-$(CONFIG_MTD_NAND_SPIA)            += spia.o
+obj-$(CONFIG_MTD_NAND_AMS_DELTA)       += ams-delta.o
 obj-$(CONFIG_MTD_NAND_TOTO)            += toto.o
 obj-$(CONFIG_MTD_NAND_AUTCPU12)                += autcpu12.o
 obj-$(CONFIG_MTD_NAND_EDB7312)         += edb7312.o
@@ -17,6 +18,9 @@ obj-$(CONFIG_MTD_NAND_DISKONCHIP)     += diskonchip.o
 obj-$(CONFIG_MTD_NAND_H1900)           += h1910.o
 obj-$(CONFIG_MTD_NAND_RTC_FROM4)       += rtc_from4.o
 obj-$(CONFIG_MTD_NAND_SHARPSL)         += sharpsl.o
+obj-$(CONFIG_MTD_NAND_TS7250)          += ts7250.o
 obj-$(CONFIG_MTD_NAND_NANDSIM)         += nandsim.o
+obj-$(CONFIG_MTD_NAND_CS553X)          += cs553x_nand.o
+obj-$(CONFIG_MTD_NAND_NDFC)            += ndfc.o
 
 nand-objs = nand_base.o nand_bbt.o
diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
new file mode 100644 (file)
index 0000000..d7897dc
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+ *  drivers/mtd/nand/ams-delta.c
+ *
+ *  Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
+ *
+ *  Derived from drivers/mtd/toto.c
+ *
+ * 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
+ *   Amstrad E3 (Delta).
+ */
+
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/partitions.h>
+#include <asm/io.h>
+#include <asm/arch/hardware.h>
+#include <asm/sizes.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/board-ams-delta.h>
+
+/*
+ * MTD structure for E3 (Delta)
+ */
+static struct mtd_info *ams_delta_mtd = NULL;
+
+#define NAND_MASK (AMS_DELTA_LATCH2_NAND_NRE | AMS_DELTA_LATCH2_NAND_NWE | AMS_DELTA_LATCH2_NAND_CLE | AMS_DELTA_LATCH2_NAND_ALE | AMS_DELTA_LATCH2_NAND_NCE | AMS_DELTA_LATCH2_NAND_NWP)
+
+/*
+ * Define partitions for flash devices
+ */
+
+static struct mtd_partition partition_info[] = {
+       { .name         = "Kernel",
+         .offset       = 0,
+         .size         = 3 * SZ_1M + SZ_512K },
+       { .name         = "u-boot",
+         .offset       = 3 * SZ_1M + SZ_512K,
+         .size         = SZ_256K },
+       { .name         = "u-boot params",
+         .offset       = 3 * SZ_1M + SZ_512K + SZ_256K,
+         .size         = SZ_256K },
+       { .name         = "Amstrad LDR",
+         .offset       = 4 * SZ_1M,
+         .size         = SZ_256K },
+       { .name         = "File system",
+         .offset       = 4 * SZ_1M + 1 * SZ_256K,
+         .size         = 27 * SZ_1M },
+       { .name         = "PBL reserved",
+         .offset       = 32 * SZ_1M - 3 * SZ_256K,
+         .size         =  3 * SZ_256K },
+};
+
+static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte)
+{
+       struct nand_chip *this = mtd->priv;
+
+       omap_writew(0, (OMAP_MPUIO_BASE + OMAP_MPUIO_IO_CNTL));
+       omap_writew(byte, this->IO_ADDR_W);
+       ams_delta_latch2_write(AMS_DELTA_LATCH2_NAND_NWE, 0);
+       ndelay(40);
+       ams_delta_latch2_write(AMS_DELTA_LATCH2_NAND_NWE,
+                              AMS_DELTA_LATCH2_NAND_NWE);
+}
+
+static u_char ams_delta_read_byte(struct mtd_info *mtd)
+{
+       u_char res;
+       struct nand_chip *this = mtd->priv;
+
+       ams_delta_latch2_write(AMS_DELTA_LATCH2_NAND_NRE, 0);
+       ndelay(40);
+       omap_writew(~0, (OMAP_MPUIO_BASE + OMAP_MPUIO_IO_CNTL));
+       res = omap_readw(this->IO_ADDR_R);
+       ams_delta_latch2_write(AMS_DELTA_LATCH2_NAND_NRE,
+                              AMS_DELTA_LATCH2_NAND_NRE);
+
+       return res;
+}
+
+static void ams_delta_write_buf(struct mtd_info *mtd, const u_char *buf,
+                               int len)
+{
+       int i;
+
+       for (i=0; i<len; i++)
+               ams_delta_write_byte(mtd, buf[i]);
+}
+
+static void ams_delta_read_buf(struct mtd_info *mtd, u_char *buf, int len)
+{
+       int i;
+
+       for (i=0; i<len; i++)
+               buf[i] = ams_delta_read_byte(mtd);
+}
+
+static int ams_delta_verify_buf(struct mtd_info *mtd, const u_char *buf,
+                               int len)
+{
+       int i;
+
+       for (i=0; i<len; i++)
+               if (buf[i] != ams_delta_read_byte(mtd))
+                       return -EFAULT;
+
+       return 0;
+}
+
+/*
+ * Command control function
+ *
+ * ctrl:
+ * NAND_NCE: bit 0 -> bit 2
+ * NAND_CLE: bit 1 -> bit 7
+ * NAND_ALE: bit 2 -> bit 6
+ */
+static void ams_delta_hwcontrol(struct mtd_info *mtd, int cmd,
+                               unsigned int ctrl)
+{
+
+       if (ctrl & NAND_CTRL_CHANGE) {
+               unsigned long bits;
+
+               bits = (~ctrl & NAND_NCE) << 2;
+               bits |= (ctrl & NAND_CLE) << 7;
+               bits |= (ctrl & NAND_ALE) << 6;
+
+               ams_delta_latch2_write(0xC2, bits);
+       }
+
+       if (cmd != NAND_CMD_NONE)
+               ams_delta_write_byte(mtd, cmd);
+}
+
+static int ams_delta_nand_ready(struct mtd_info *mtd)
+{
+       return omap_get_gpio_datain(AMS_DELTA_GPIO_PIN_NAND_RB);
+}
+
+/*
+ * Main initialization routine
+ */
+static int __init ams_delta_init(void)
+{
+       struct nand_chip *this;
+       int err = 0;
+
+       /* Allocate memory for MTD device structure and private data */
+       ams_delta_mtd = kmalloc(sizeof(struct mtd_info) +
+                               sizeof(struct nand_chip), GFP_KERNEL);
+       if (!ams_delta_mtd) {
+               printk (KERN_WARNING "Unable to allocate E3 NAND MTD device structure.\n");
+               err = -ENOMEM;
+               goto out;
+       }
+
+       ams_delta_mtd->owner = THIS_MODULE;
+
+       /* Get pointer to private data */
+       this = (struct nand_chip *) (&ams_delta_mtd[1]);
+
+       /* Initialize structures */
+       memset(ams_delta_mtd, 0, sizeof(struct mtd_info));
+       memset(this, 0, sizeof(struct nand_chip));
+
+       /* Link the private data with the MTD structure */
+       ams_delta_mtd->priv = this;
+
+       /* Set address of NAND IO lines */
+       this->IO_ADDR_R = (OMAP_MPUIO_BASE + OMAP_MPUIO_INPUT_LATCH);
+       this->IO_ADDR_W = (OMAP_MPUIO_BASE + OMAP_MPUIO_OUTPUT);
+       this->read_byte = ams_delta_read_byte;
+       this->write_buf = ams_delta_write_buf;
+       this->read_buf = ams_delta_read_buf;
+       this->verify_buf = ams_delta_verify_buf;
+       this->cmd_ctrl = ams_delta_hwcontrol;
+       if (!omap_request_gpio(AMS_DELTA_GPIO_PIN_NAND_RB)) {
+               this->dev_ready = ams_delta_nand_ready;
+       } else {
+               this->dev_ready = NULL;
+               printk(KERN_NOTICE "Couldn't request gpio for Delta NAND ready.\n");
+       }
+       /* 25 us command delay time */
+       this->chip_delay = 30;
+       this->ecc.mode = NAND_ECC_SOFT;
+
+       /* Set chip enabled, but  */
+       ams_delta_latch2_write(NAND_MASK, AMS_DELTA_LATCH2_NAND_NRE |
+                                         AMS_DELTA_LATCH2_NAND_NWE |
+                                         AMS_DELTA_LATCH2_NAND_NCE |
+                                         AMS_DELTA_LATCH2_NAND_NWP);
+
+       /* Scan to find existance of the device */
+       if (nand_scan(ams_delta_mtd, 1)) {
+               err = -ENXIO;
+               goto out_mtd;
+       }
+
+       /* Register the partitions */
+       add_mtd_partitions(ams_delta_mtd, partition_info,
+                          ARRAY_SIZE(partition_info));
+
+       goto out;
+
+ out_mtd:
+       kfree(ams_delta_mtd);
+ out:
+       return err;
+}
+
+module_init(ams_delta_init);
+
+/*
+ * Clean up routine
+ */
+static void __exit ams_delta_cleanup(void)
+{
+       /* Release resources, unregister device */
+       nand_release(ams_delta_mtd);
+
+       /* Free the MTD device structure */
+       kfree(ams_delta_mtd);
+}
+module_exit(ams_delta_cleanup);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>");
+MODULE_DESCRIPTION("Glue layer for NAND flash on Amstrad E3 (Delta)");
index bde3550..3122833 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/interrupt.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
  */
 static struct mtd_info *au1550_mtd = NULL;
 static void __iomem *p_nand;
-static int nand_width = 1; /* default x8*/
+static int nand_width = 1;     /* default x8 */
+static void (*au1550_write_byte)(struct mtd_info *, u_char);
 
 /*
  * Define partitions for flash device
  */
 static const struct mtd_partition partition_info[] = {
        {
-               .name   = "NAND FS 0",
-               .offset = 0,
-               .size   = 8*1024*1024
-       },
+        .name = "NAND FS 0",
+        .offset = 0,
+        .size = 8 * 1024 * 1024},
        {
-               .name   = "NAND FS 1",
-               .offset =  MTDPART_OFS_APPEND,
-               .size   =    MTDPART_SIZ_FULL
-       }
+        .name = "NAND FS 1",
+        .offset = MTDPART_OFS_APPEND,
+        .size = MTDPART_SIZ_FULL}
 };
 
 /**
@@ -130,21 +130,6 @@ static u16 au_read_word(struct mtd_info *mtd)
 }
 
 /**
- * au_write_word -  write one word to the chip
- * @mtd:       MTD device structure
- * @word:      data word to write
- *
- *  write function for 16bit buswith without
- * endianess conversion
- */
-static void au_write_word(struct mtd_info *mtd, u16 word)
-{
-       struct nand_chip *this = mtd->priv;
-       writew(word, this->IO_ADDR_W);
-       au_sync();
-}
-
-/**
  * au_write_buf -  write buffer to chip
  * @mtd:       MTD device structure
  * @buf:       data buffer
@@ -157,7 +142,7 @@ static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
        int i;
        struct nand_chip *this = mtd->priv;
 
-       for (i=0; i<len; i++) {
+       for (i = 0; i < len; i++) {
                writeb(buf[i], this->IO_ADDR_W);
                au_sync();
        }
@@ -176,7 +161,7 @@ static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len)
        int i;
        struct nand_chip *this = mtd->priv;
 
-       for (i=0; i<len; i++) {
+       for (i = 0; i < len; i++) {
                buf[i] = readb(this->IO_ADDR_R);
                au_sync();
        }
@@ -195,7 +180,7 @@ static int au_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
        int i;
        struct nand_chip *this = mtd->priv;
 
-       for (i=0; i<len; i++) {
+       for (i = 0; i < len; i++) {
                if (buf[i] != readb(this->IO_ADDR_R))
                        return -EFAULT;
                au_sync();
@@ -219,7 +204,7 @@ static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
        u16 *p = (u16 *) buf;
        len >>= 1;
 
-       for (i=0; i<len; i++) {
+       for (i = 0; i < len; i++) {
                writew(p[i], this->IO_ADDR_W);
                au_sync();
        }
@@ -241,7 +226,7 @@ static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
        u16 *p = (u16 *) buf;
        len >>= 1;
 
-       for (i=0; i<len; i++) {
+       for (i = 0; i < len; i++) {
                p[i] = readw(this->IO_ADDR_R);
                au_sync();
        }
@@ -262,7 +247,7 @@ static int au_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len)
        u16 *p = (u16 *) buf;
        len >>= 1;
 
-       for (i=0; i<len; i++) {
+       for (i = 0; i < len; i++) {
                if (p[i] != readw(this->IO_ADDR_R))
                        return -EFAULT;
                au_sync();
@@ -270,32 +255,52 @@ static int au_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len)
        return 0;
 }
 
+/* Select the chip by setting nCE to low */
+#define NAND_CTL_SETNCE                1
+/* Deselect the chip by setting nCE to high */
+#define NAND_CTL_CLRNCE                2
+/* Select the command latch by setting CLE to high */
+#define NAND_CTL_SETCLE                3
+/* Deselect the command latch by setting CLE to low */
+#define NAND_CTL_CLRCLE                4
+/* Select the address latch by setting ALE to high */
+#define NAND_CTL_SETALE                5
+/* Deselect the address latch by setting ALE to low */
+#define NAND_CTL_CLRALE                6
 
 static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
 {
        register struct nand_chip *this = mtd->priv;
 
-       switch(cmd){
+       switch (cmd) {
 
-       case NAND_CTL_SETCLE: this->IO_ADDR_W = p_nand + MEM_STNAND_CMD; break;
-       case NAND_CTL_CLRCLE: this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; break;
+       case NAND_CTL_SETCLE:
+               this->IO_ADDR_W = p_nand + MEM_STNAND_CMD;
+               break;
+
+       case NAND_CTL_CLRCLE:
+               this->IO_ADDR_W = p_nand + MEM_STNAND_DATA;
+               break;
+
+       case NAND_CTL_SETALE:
+               this->IO_ADDR_W = p_nand + MEM_STNAND_ADDR;
+               break;
 
-       case NAND_CTL_SETALE: this->IO_ADDR_W = p_nand + MEM_STNAND_ADDR; break;
        case NAND_CTL_CLRALE:
                this->IO_ADDR_W = p_nand + MEM_STNAND_DATA;
-               /* FIXME: Nobody knows why this is neccecary,
+               /* FIXME: Nobody knows why this is necessary,
                 * but it works only that way */
                udelay(1);
                break;
 
        case NAND_CTL_SETNCE:
                /* assert (force assert) chip enable */
-               au_writel((1<<(4+NAND_CS)) , MEM_STNDCTL); break;
+               au_writel((1 << (4 + NAND_CS)), MEM_STNDCTL);
                break;
 
        case NAND_CTL_CLRNCE:
-               /* deassert chip enable */
-               au_writel(0, MEM_STNDCTL); break;
+               /* deassert chip enable */
+               au_writel(0, MEM_STNDCTL);
                break;
        }
 
@@ -312,69 +317,200 @@ int au1550_device_ready(struct mtd_info *mtd)
        return ret;
 }
 
+/**
+ * au1550_select_chip - control -CE line
+ *     Forbid driving -CE manually permitting the NAND controller to do this.
+ *     Keeping -CE asserted during the whole sector reads interferes with the
+ *     NOR flash and PCMCIA drivers as it causes contention on the static bus.
+ *     We only have to hold -CE low for the NAND read commands since the flash
+ *     chip needs it to be asserted during chip not ready time but the NAND
+ *     controller keeps it released.
+ *
+ * @mtd:       MTD device structure
+ * @chip:      chipnumber to select, -1 for deselect
+ */
+static void au1550_select_chip(struct mtd_info *mtd, int chip)
+{
+}
+
+/**
+ * au1550_command - Send command to NAND device
+ * @mtd:       MTD device structure
+ * @command:   the command to be sent
+ * @column:    the column address for this command, -1 if none
+ * @page_addr: the page address for this command, -1 if none
+ */
+static void au1550_command(struct mtd_info *mtd, unsigned command, int column, int page_addr)
+{
+       register struct nand_chip *this = mtd->priv;
+       int ce_override = 0, i;
+       ulong flags;
+
+       /* Begin command latch cycle */
+       au1550_hwcontrol(mtd, NAND_CTL_SETCLE);
+       /*
+        * Write out the command to the device.
+        */
+       if (command == NAND_CMD_SEQIN) {
+               int readcmd;
+
+               if (column >= mtd->writesize) {
+                       /* OOB area */
+                       column -= mtd->writesize;
+                       readcmd = NAND_CMD_READOOB;
+               } else if (column < 256) {
+                       /* First 256 bytes --> READ0 */
+                       readcmd = NAND_CMD_READ0;
+               } else {
+                       column -= 256;
+                       readcmd = NAND_CMD_READ1;
+               }
+               au1550_write_byte(mtd, readcmd);
+       }
+       au1550_write_byte(mtd, command);
+
+       /* Set ALE and clear CLE to start address cycle */
+       au1550_hwcontrol(mtd, NAND_CTL_CLRCLE);
+
+       if (column != -1 || page_addr != -1) {
+               au1550_hwcontrol(mtd, NAND_CTL_SETALE);
+
+               /* Serially input address */
+               if (column != -1) {
+                       /* Adjust columns for 16 bit buswidth */
+                       if (this->options & NAND_BUSWIDTH_16)
+                               column >>= 1;
+                       au1550_write_byte(mtd, column);
+               }
+               if (page_addr != -1) {
+                       au1550_write_byte(mtd, (u8)(page_addr & 0xff));
+
+                       if (command == NAND_CMD_READ0 ||
+                           command == NAND_CMD_READ1 ||
+                           command == NAND_CMD_READOOB) {
+                               /*
+                                * NAND controller will release -CE after
+                                * the last address byte is written, so we'll
+                                * have to forcibly assert it. No interrupts
+                                * are allowed while we do this as we don't
+                                * want the NOR flash or PCMCIA drivers to
+                                * steal our precious bytes of data...
+                                */
+                               ce_override = 1;
+                               local_irq_save(flags);
+                               au1550_hwcontrol(mtd, NAND_CTL_SETNCE);
+                       }
+
+                       au1550_write_byte(mtd, (u8)(page_addr >> 8));
+
+                       /* One more address cycle for devices > 32MiB */
+                       if (this->chipsize > (32 << 20))
+                               au1550_write_byte(mtd, (u8)((page_addr >> 16) & 0x0f));
+               }
+               /* Latch in address */
+               au1550_hwcontrol(mtd, NAND_CTL_CLRALE);
+       }
+
+       /*
+        * Program and erase have their own busy handlers.
+        * Status and sequential in need no delay.
+        */
+       switch (command) {
+
+       case NAND_CMD_PAGEPROG:
+       case NAND_CMD_ERASE1:
+       case NAND_CMD_ERASE2:
+       case NAND_CMD_SEQIN:
+       case NAND_CMD_STATUS:
+               return;
+
+       case NAND_CMD_RESET:
+               break;
+
+       case NAND_CMD_READ0:
+       case NAND_CMD_READ1:
+       case NAND_CMD_READOOB:
+               /* Check if we're really driving -CE low (just in case) */
+               if (unlikely(!ce_override))
+                       break;
+
+               /* Apply a short delay always to ensure that we do wait tWB. */
+               ndelay(100);
+               /* Wait for a chip to become ready... */
+               for (i = this->chip_delay; !this->dev_ready(mtd) && i > 0; --i)
+                       udelay(1);
+
+               /* Release -CE and re-enable interrupts. */
+               au1550_hwcontrol(mtd, NAND_CTL_CLRNCE);
+               local_irq_restore(flags);
+               return;
+       }
+       /* Apply this short delay always to ensure that we do wait tWB. */
+       ndelay(100);
+
+       while(!this->dev_ready(mtd));
+}
+
+
 /*
  * Main initialization routine
  */
-int __init au1xxx_nand_init (void)
+static int __init au1xxx_nand_init(void)
 {
        struct nand_chip *this;
-       u16 boot_swapboot = 0; /* default value */
+       u16 boot_swapboot = 0;  /* default value */
        int retval;
        u32 mem_staddr;
        u32 nand_phys;
 
        /* Allocate memory for MTD device structure and private data */
-       au1550_mtd = kmalloc (sizeof(struct mtd_info) +
-                       sizeof (struct nand_chip), GFP_KERNEL);
+       au1550_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
        if (!au1550_mtd) {
-               printk ("Unable to allocate NAND MTD dev structure.\n");
+               printk("Unable to allocate NAND MTD dev structure.\n");
                return -ENOMEM;
        }
 
        /* Get pointer to private data */
-       this = (struct nand_chip *) (&au1550_mtd[1]);
+       this = (struct nand_chip *)(&au1550_mtd[1]);
 
        /* Initialize structures */
-       memset((char *) au1550_mtd, 0, sizeof(struct mtd_info));
-       memset((char *) this, 0, sizeof(struct nand_chip));
+       memset(au1550_mtd, 0, sizeof(struct mtd_info));
+       memset(this, 0, sizeof(struct nand_chip));
 
        /* Link the private data with the MTD structure */
        au1550_mtd->priv = this;
+       au1550_mtd->owner = THIS_MODULE;
 
 
-       /* disable interrupts */
-       au_writel(au_readl(MEM_STNDCTL) & ~(1<<8), MEM_STNDCTL);
-
-       /* disable NAND boot */
-       au_writel(au_readl(MEM_STNDCTL) & ~(1<<0), MEM_STNDCTL);
+       /* MEM_STNDCTL: disable ints, disable nand boot */
+       au_writel(0, MEM_STNDCTL);
 
 #ifdef CONFIG_MIPS_PB1550
        /* set gpio206 high */
-       au_writel(au_readl(GPIO2_DIR) & ~(1<<6), GPIO2_DIR);
+       au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR);
 
-       boot_swapboot = (au_readl(MEM_STSTAT) & (0x7<<1)) |
-               ((bcsr->status >> 6)  & 0x1);
+       boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr->status >> 6) & 0x1);
        switch (boot_swapboot) {
-               case 0:
-               case 2:
-               case 8:
-               case 0xC:
-               case 0xD:
-                       /* x16 NAND Flash */
-                       nand_width = 0;
-                       break;
-               case 1:
-               case 9:
-               case 3:
-               case 0xE:
-               case 0xF:
-                       /* x8 NAND Flash */
-                       nand_width = 1;
-                       break;
-               default:
-                       printk("Pb1550 NAND: bad boot:swap\n");
-                       retval = -EINVAL;
-                       goto outmem;
+       case 0:
+       case 2:
+       case 8:
+       case 0xC:
+       case 0xD:
+               /* x16 NAND Flash */
+               nand_width = 0;
+               break;
+       case 1:
+       case 9:
+       case 3:
+       case 0xE:
+       case 0xF:
+               /* x8 NAND Flash */
+               nand_width = 1;
+               break;
+       default:
+               printk("Pb1550 NAND: bad boot:swap\n");
+               retval = -EINVAL;
+               goto outmem;
        }
 #endif
 
@@ -424,21 +560,22 @@ int __init au1xxx_nand_init (void)
 
        /* make controller and MTD agree */
        if (NAND_CS == 0)
-               nand_width = au_readl(MEM_STCFG0) & (1<<22);
+               nand_width = au_readl(MEM_STCFG0) & (1 << 22);
        if (NAND_CS == 1)
-               nand_width = au_readl(MEM_STCFG1) & (1<<22);
+               nand_width = au_readl(MEM_STCFG1) & (1 << 22);
        if (NAND_CS == 2)
-               nand_width = au_readl(MEM_STCFG2) & (1<<22);
+               nand_width = au_readl(MEM_STCFG2) & (1 << 22);
        if (NAND_CS == 3)
-               nand_width = au_readl(MEM_STCFG3) & (1<<22);
-
+               nand_width = au_readl(MEM_STCFG3) & (1 << 22);
 
        /* Set address of hardware control function */
-       this->hwcontrol = au1550_hwcontrol;
        this->dev_ready = au1550_device_ready;
+       this->select_chip = au1550_select_chip;
+       this->cmdfunc = au1550_command;
+
        /* 30 us command delay time */
        this->chip_delay = 30;
-       this->eccmode = NAND_ECC_SOFT;
+       this->ecc.mode = NAND_ECC_SOFT;
 
        this->options = NAND_NO_AUTOINCR;
 
@@ -446,15 +583,14 @@ int __init au1xxx_nand_init (void)
                this->options |= NAND_BUSWIDTH_16;
 
        this->read_byte = (!nand_width) ? au_read_byte16 : au_read_byte;
-       this->write_byte = (!nand_width) ? au_write_byte16 : au_write_byte;
-       this->write_word = au_write_word;
+       au1550_write_byte = (!nand_width) ? au_write_byte16 : au_write_byte;
        this->read_word = au_read_word;
        this->write_buf = (!nand_width) ? au_write_buf16 : au_write_buf;
        this->read_buf = (!nand_width) ? au_read_buf16 : au_read_buf;
        this->verify_buf = (!nand_width) ? au_verify_buf16 : au_verify_buf;
 
        /* Scan to find existence of the device */
-       if (nand_scan (au1550_mtd, 1)) {
+       if (nand_scan(au1550_mtd, 1)) {
                retval = -ENXIO;
                goto outio;
        }
@@ -465,10 +601,10 @@ int __init au1xxx_nand_init (void)
        return 0;
 
  outio:
-       iounmap ((void *)p_nand);
+       iounmap((void *)p_nand);
 
  outmem:
-       kfree (au1550_mtd);
+       kfree(au1550_mtd);
        return retval;
 }
 
@@ -477,22 +613,21 @@ module_init(au1xxx_nand_init);
 /*
  * Clean up routine
  */
-#ifdef MODULE
-static void __exit au1550_cleanup (void)
+static void __exit au1550_cleanup(void)
 {
-       struct nand_chip *this = (struct nand_chip *) &au1550_mtd[1];
+       struct nand_chip *this = (struct nand_chip *)&au1550_mtd[1];
 
        /* Release resources, unregister device */
-       nand_release (au1550_mtd);
+       nand_release(au1550_mtd);
 
        /* Free the MTD device structure */
-       kfree (au1550_mtd);
+       kfree(au1550_mtd);
 
        /* Unmap */
-       iounmap ((void *)p_nand);
+       iounmap((void *)p_nand);
 }
+
 module_exit(au1550_cleanup);
-#endif
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Embedded Edge, LLC");
index a3c7fea..fe94ae9 100644 (file)
@@ -4,7 +4,7 @@
  *  Copyright (c) 2002 Thomas Gleixner <tgxl@linutronix.de>
  *
  *  Derived from drivers/mtd/spia.c
- *      Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
+ *      Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
  *
  * $Id: autcpu12.c,v 1.23 2005/11/07 11:14:30 gleixner Exp $
  *
  * MTD structure for AUTCPU12 board
  */
 static struct mtd_info *autcpu12_mtd = NULL;
-
-static int autcpu12_io_base = CS89712_VIRT_BASE;
-static int autcpu12_fio_pbase = AUTCPU12_PHYS_SMC;
-static int autcpu12_fio_ctrl = AUTCPU12_SMC_SELECT_OFFSET;
-static int autcpu12_pedr = AUTCPU12_SMC_PORT_OFFSET;
-static void __iomem * autcpu12_fio_base;
+static void __iomem *autcpu12_fio_base;
 
 /*
  * Define partitions for flash devices
@@ -94,108 +89,131 @@ static struct mtd_partition partition_info128k[] = {
 #define NUM_PARTITIONS128K 2
 /*
  *     hardware specific access to control-lines
-*/
-static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd)
+ *
+ *     ALE bit 4 autcpu12_pedr
+ *     CLE bit 5 autcpu12_pedr
+ *     NCE bit 0 fio_ctrl
+ *
+ */
+static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd,
+                              unsigned int ctrl)
 {
+       struct nand_chip *chip = mtd->priv;
 
-       switch(cmd){
-
-               case NAND_CTL_SETCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) |=  AUTCPU12_SMC_CLE; break;
-               case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) &= ~AUTCPU12_SMC_CLE; break;
+       if (ctrl & NAND_CTRL_CHANGE) {
+               void __iomem *addr
+               unsigned char bits;
 
-               case NAND_CTL_SETALE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) |=  AUTCPU12_SMC_ALE; break;
-               case NAND_CTL_CLRALE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) &= ~AUTCPU12_SMC_ALE; break;
+               addr = CS89712_VIRT_BASE + AUTCPU12_SMC_PORT_OFFSET;
+               bits = (ctrl & NAND_CLE) << 4;
+               bits |= (ctrl & NAND_ALE) << 2;
+               writeb((readb(addr) & ~0x30) | bits, addr);
 
-               case NAND_CTL_SETNCE: (*(volatile unsigned char *) (autcpu12_fio_base + autcpu12_fio_ctrl)) = 0x01; break;
-               case NAND_CTL_CLRNCE: (*(volatile unsigned char *) (autcpu12_fio_base + autcpu12_fio_ctrl)) = 0x00; break;
+               addr = autcpu12_fio_base + AUTCPU12_SMC_SELECT_OFFSET;
+               writeb((readb(addr) & ~0x1) | (ctrl & NAND_NCE), addr);
        }
+
+       if (cmd != NAND_CMD_NONE)
+               writeb(cmd, chip->IO_ADDR_W);
 }
 
 /*
-*      read device ready pin
-*/
+ *     read device ready pin
+ */
 int autcpu12_device_ready(struct mtd_info *mtd)
 {
+       void __iomem *addr = CS89712_VIRT_BASE + AUTCPU12_SMC_PORT_OFFSET;
 
-       return ( (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) & AUTCPU12_SMC_RDY) ? 1 : 0;
-
+       return readb(addr) & AUTCPU12_SMC_RDY;
 }
 
 /*
  * Main initialization routine
  */
-int __init autcpu12_init (void)
+static int __init autcpu12_init(void)
 {
        struct nand_chip *this;
        int err = 0;
 
        /* Allocate memory for MTD device structure and private data */
-       autcpu12_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
-                               GFP_KERNEL);
+       autcpu12_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip),
+                              GFP_KERNEL);
        if (!autcpu12_mtd) {
-               printk ("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
+               printk("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
                err = -ENOMEM;
                goto out;
        }
 
        /* map physical adress */
-       autcpu12_fio_base = ioremap(autcpu12_fio_pbase,SZ_1K);
-       if(!autcpu12_fio_base){
+       autcpu12_fio_base = ioremap(AUTCPU12_PHYS_SMC, SZ_1K);
+       if (!autcpu12_fio_base) {
                printk("Ioremap autcpu12 SmartMedia Card failed\n");
                err = -EIO;
                goto out_mtd;
        }
 
        /* Get pointer to private data */
-       this = (struct nand_chip *) (&autcpu12_mtd[1]);
+       this = (struct nand_chip *)(&autcpu12_mtd[1]);
 
        /* Initialize structures */
-       memset((char *) autcpu12_mtd, 0, sizeof(struct mtd_info));
-       memset((char *) this, 0, sizeof(struct nand_chip));
+       memset(autcpu12_mtd, 0, sizeof(struct mtd_info));
+       memset(this, 0, sizeof(struct nand_chip));
 
        /* Link the private data with the MTD structure */
        autcpu12_mtd->priv = this;
+       autcpu12_mtd->owner = THIS_MODULE;
 
        /* Set address of NAND IO lines */
        this->IO_ADDR_R = autcpu12_fio_base;
        this->IO_ADDR_W = autcpu12_fio_base;
-       this->hwcontrol = autcpu12_hwcontrol;
+       this->cmd_ctrl = autcpu12_hwcontrol;
        this->dev_ready = autcpu12_device_ready;
        /* 20 us command delay time */
        this->chip_delay = 20;
-       this->eccmode = NAND_ECC_SOFT;
+       this->ecc.mode = NAND_ECC_SOFT;
 
        /* Enable the following for a flash based bad block table */
        /*
-       this->options = NAND_USE_FLASH_BBT;
-       */
+          this->options = NAND_USE_FLASH_BBT;
+        */
        this->options = NAND_USE_FLASH_BBT;
 
        /* Scan to find existance of the device */
-       if (nand_scan (autcpu12_mtd, 1)) {
+       if (nand_scan(autcpu12_mtd, 1)) {
                err = -ENXIO;
                goto out_ior;
        }
 
        /* Register the partitions */
-       switch(autcpu12_mtd->size){
-               case SZ_16M: add_mtd_partitions(autcpu12_mtd, partition_info16k, NUM_PARTITIONS16K); break;
-               case SZ_32M: add_mtd_partitions(autcpu12_mtd, partition_info32k, NUM_PARTITIONS32K); break;
-               case SZ_64M: add_mtd_partitions(autcpu12_mtd, partition_info64k, NUM_PARTITIONS64K); break;
-               case SZ_128M: add_mtd_partitions(autcpu12_mtd, partition_info128k, NUM_PARTITIONS128K); break;
-               default: {
-                       printk ("Unsupported SmartMedia device\n");
+       switch (autcpu12_mtd->size) {
+               case SZ_16M:
+                       add_mtd_partitions(autcpu12_mtd, partition_info16k,
+                                          NUM_PARTITIONS16K);
+                       break;
+               case SZ_32M:
+                       add_mtd_partitions(autcpu12_mtd, partition_info32k,
+                                          NUM_PARTITIONS32K);
+                       break;
+               case SZ_64M:
+                       add_mtd_partitions(autcpu12_mtd, partition_info64k,
+                                          NUM_PARTITIONS64K);
+                       break;
+               case SZ_128M:
+                       add_mtd_partitions(autcpu12_mtd, partition_info128k,
+                                          NUM_PARTITIONS128K);
+                       break;
+               default:
+                       printk("Unsupported SmartMedia device\n");
                        err = -ENXIO;
                        goto out_ior;
-               }
        }
        goto out;
 
-out_ior:
-       iounmap((void *)autcpu12_fio_base);
-out_mtd:
-       kfree (autcpu12_mtd);
-out:
+ out_ior:
+       iounmap(autcpu12_fio_base);
+ out_mtd:
+       kfree(autcpu12_mtd);
+ out:
        return err;
 }
 
@@ -204,20 +222,19 @@ module_init(autcpu12_init);
 /*
  * Clean up routine
  */
-#ifdef MODULE
-static void __exit autcpu12_cleanup (void)
+static void __exit autcpu12_cleanup(void)
 {
        /* Release resources, unregister device */
-       nand_release (autcpu12_mtd);
+       nand_release(autcpu12_mtd);
 
        /* unmap physical adress */
-       iounmap((void *)autcpu12_fio_base);
+       iounmap(autcpu12_fio_base);
 
        /* Free the MTD device structure */
-       kfree (autcpu12_mtd);
+       kfree(autcpu12_mtd);
 }
+
 module_exit(autcpu12_cleanup);
-#endif
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
new file mode 100644 (file)
index 0000000..e0a1d38
--- /dev/null
@@ -0,0 +1,353 @@
+/*
+ * drivers/mtd/nand/cs553x_nand.c
+ *
+ * (C) 2005, 2006 Red Hat Inc.
+ *
+ * Author: David Woodhouse <dwmw2@infradead.org>
+ *        Tom Sylla <tom.sylla@amd.com>
+ *
+ * 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 controller found on 
+ *   the AMD CS5535/CS5536 companion chipsets for the Geode processor.
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/nand_ecc.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/msr.h>
+#include <asm/io.h>
+
+#define NR_CS553X_CONTROLLERS  4
+
+#define MSR_DIVIL_GLD_CAP      0x51400000      /* DIVIL capabilitiies */
+#define CAP_CS5535             0x2df000ULL
+#define CAP_CS5536             0x5df500ULL
+
+/* NAND Timing MSRs */
+#define MSR_NANDF_DATA         0x5140001b      /* NAND Flash Data Timing MSR */
+#define MSR_NANDF_CTL          0x5140001c      /* NAND Flash Control Timing */
+#define MSR_NANDF_RSVD         0x5140001d      /* Reserved */
+
+/* NAND BAR MSRs */
+#define MSR_DIVIL_LBAR_FLSH0   0x51400010      /* Flash Chip Select 0 */
+#define MSR_DIVIL_LBAR_FLSH1   0x51400011      /* Flash Chip Select 1 */
+#define MSR_DIVIL_LBAR_FLSH2   0x51400012      /* Flash Chip Select 2 */
+#define MSR_DIVIL_LBAR_FLSH3   0x51400013      /* Flash Chip Select 3 */
+       /* Each made up of... */
+#define FLSH_LBAR_EN           (1ULL<<32)
+#define FLSH_NOR_NAND          (1ULL<<33)      /* 1 for NAND */
+#define FLSH_MEM_IO            (1ULL<<34)      /* 1 for MMIO */
+       /* I/O BARs have BASE_ADDR in bits 15:4, IO_MASK in 47:36 */
+       /* MMIO BARs have BASE_ADDR in bits 31:12, MEM_MASK in 63:44 */
+
+/* Pin function selection MSR (IDE vs. flash on the IDE pins) */
+#define MSR_DIVIL_BALL_OPTS    0x51400015
+#define PIN_OPT_IDE            (1<<0)  /* 0 for flash, 1 for IDE */
+
+/* Registers within the NAND flash controller BAR -- memory mapped */
+#define MM_NAND_DATA           0x00    /* 0 to 0x7ff, in fact */
+#define MM_NAND_CTL            0x800   /* Any even address 0x800-0x80e */
+#define MM_NAND_IO             0x801   /* Any odd address 0x801-0x80f */
+#define MM_NAND_STS            0x810
+#define MM_NAND_ECC_LSB                0x811
+#define MM_NAND_ECC_MSB                0x812
+#define MM_NAND_ECC_COL                0x813
+#define MM_NAND_LAC            0x814
+#define MM_NAND_ECC_CTL                0x815
+
+/* Registers within the NAND flash controller BAR -- I/O mapped */
+#define IO_NAND_DATA           0x00    /* 0 to 3, in fact */
+#define IO_NAND_CTL            0x04
+#define IO_NAND_IO             0x05
+#define IO_NAND_STS            0x06
+#define IO_NAND_ECC_CTL                0x08
+#define IO_NAND_ECC_LSB                0x09
+#define IO_NAND_ECC_MSB                0x0a
+#define IO_NAND_ECC_COL                0x0b
+#define IO_NAND_LAC            0x0c
+
+#define CS_NAND_CTL_DIST_EN    (1<<4)  /* Enable NAND Distract interrupt */
+#define CS_NAND_CTL_RDY_INT_MASK       (1<<3)  /* Enable RDY/BUSY# interrupt */
+#define CS_NAND_CTL_ALE                (1<<2)
+#define CS_NAND_CTL_CLE                (1<<1)
+#define CS_NAND_CTL_CE         (1<<0)  /* Keep low; 1 to reset */
+
+#define CS_NAND_STS_FLASH_RDY  (1<<3)
+#define CS_NAND_CTLR_BUSY      (1<<2)
+#define CS_NAND_CMD_COMP       (1<<1)
+#define CS_NAND_DIST_ST                (1<<0)
+
+#define CS_NAND_ECC_PARITY     (1<<2)
+#define CS_NAND_ECC_CLRECC     (1<<1)
+#define CS_NAND_ECC_ENECC      (1<<0)
+
+static void cs553x_read_buf(struct mtd_info *mtd, u_char *buf, int len)
+{
+       struct nand_chip *this = mtd->priv;
+
+       while (unlikely(len > 0x800)) {
+               memcpy_fromio(buf, this->IO_ADDR_R, 0x800);
+               buf += 0x800;
+               len -= 0x800;
+       }
+       memcpy_fromio(buf, this->IO_ADDR_R, len);
+}
+
+static void cs553x_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
+{
+       struct nand_chip *this = mtd->priv;
+
+       while (unlikely(len > 0x800)) {
+               memcpy_toio(this->IO_ADDR_R, buf, 0x800);
+               buf += 0x800;
+               len -= 0x800;
+       }
+       memcpy_toio(this->IO_ADDR_R, buf, len);
+}
+
+static unsigned char cs553x_read_byte(struct mtd_info *mtd)
+{
+       struct nand_chip *this = mtd->priv;
+       return readb(this->IO_ADDR_R);
+}
+
+static void cs553x_write_byte(struct mtd_info *mtd, u_char byte)
+{
+       struct nand_chip *this = mtd->priv;
+       int i = 100000;
+
+       while (i && readb(this->IO_ADDR_R + MM_NAND_STS) & CS_NAND_CTLR_BUSY) {
+               udelay(1);
+               i--;
+       }
+       writeb(byte, this->IO_ADDR_W + 0x801);
+}
+
+static void cs553x_hwcontrol(struct mtd_info *mtd, int cmd,
+                            unsigned int ctrl)
+{
+       struct nand_chip *this = mtd->priv;
+       void __iomem *mmio_base = this->IO_ADDR_R;
+       if (ctrl & NAND_CTRL_CHANGE) {
+               unsigned char ctl = (ctrl & ~NAND_CTRL_CHANGE ) ^ 0x01;
+               writeb(ctl, mmio_base + MM_NAND_CTL);
+       }
+       if (cmd != NAND_CMD_NONE)
+               cs553x_write_byte(mtd, cmd);
+}
+
+static int cs553x_device_ready(struct mtd_info *mtd)
+{
+       struct nand_chip *this = mtd->priv;
+       void __iomem *mmio_base = this->IO_ADDR_R;
+       unsigned char foo = readb(mmio_base + MM_NAND_STS);
+
+       return (foo & CS_NAND_STS_FLASH_RDY) && !(foo & CS_NAND_CTLR_BUSY);
+}
+
+static void cs_enable_hwecc(struct mtd_info *mtd, int mode)
+{
+       struct nand_chip *this = mtd->priv;
+       void __iomem *mmio_base = this->IO_ADDR_R;
+
+       writeb(0x07, mmio_base + MM_NAND_ECC_CTL);
+}
+
+static int cs_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
+{
+       uint32_t ecc;
+       struct nand_chip *this = mtd->priv;
+       void __iomem *mmio_base = this->IO_ADDR_R;
+
+       ecc = readl(mmio_base + MM_NAND_STS);
+
+       ecc_code[1] = ecc >> 8;
+       ecc_code[0] = ecc >> 16;
+       ecc_code[2] = ecc >> 24;
+       return 0;
+}
+
+static struct mtd_info *cs553x_mtd[4];
+
+static int __init cs553x_init_one(int cs, int mmio, unsigned long adr)
+{
+       int err = 0;
+       struct nand_chip *this;
+       struct mtd_info *new_mtd;
+
+       printk(KERN_NOTICE "Probing CS553x NAND controller CS#%d at %sIO 0x%08lx\n", cs, mmio?"MM":"P", adr);
+
+       if (!mmio) {
+               printk(KERN_NOTICE "PIO mode not yet implemented for CS553X NAND controller\n");
+               return -ENXIO;
+       }
+
+       /* Allocate memory for MTD device structure and private data */
+       new_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
+       if (!new_mtd) {
+               printk(KERN_WARNING "Unable to allocate CS553X NAND MTD device structure.\n");
+               err = -ENOMEM;
+               goto out;
+       }
+
+       /* Get pointer to private data */
+       this = (struct nand_chip *)(&new_mtd[1]);
+
+       /* Initialize structures */
+       memset(new_mtd, 0, sizeof(struct mtd_info));
+       memset(this, 0, sizeof(struct nand_chip));
+
+       /* Link the private data with the MTD structure */
+       new_mtd->priv = this;
+       new_mtd->owner = THIS_MODULE;
+
+       /* map physical address */
+       this->IO_ADDR_R = this->IO_ADDR_W = ioremap(adr, 4096);
+       if (!this->IO_ADDR_R) {
+               printk(KERN_WARNING "ioremap cs553x NAND @0x%08lx failed\n", adr);
+               err = -EIO;
+               goto out_mtd;
+       }
+
+       this->cmd_ctrl = cs553x_hwcontrol;
+       this->dev_ready = cs553x_device_ready;
+       this->read_byte = cs553x_read_byte;
+       this->read_buf = cs553x_read_buf;
+       this->write_buf = cs553x_write_buf;
+
+       this->chip_delay = 0;
+
+       this->ecc.mode = NAND_ECC_HW;
+       this->ecc.size = 256;
+       this->ecc.bytes = 3;
+       this->ecc.hwctl  = cs_enable_hwecc;
+       this->ecc.calculate = cs_calculate_ecc;
+       this->ecc.correct  = nand_correct_data;
+
+       /* Enable the following for a flash based bad block table */
+       this->options = NAND_USE_FLASH_BBT | NAND_NO_AUTOINCR;
+
+       /* Scan to find existance of the device */
+       if (nand_scan(new_mtd, 1)) {
+               err = -ENXIO;
+               goto out_ior;
+       }
+
+       cs553x_mtd[cs] = new_mtd;
+       goto out;
+
+out_ior:
+       iounmap((void *)this->IO_ADDR_R);
+out_mtd:
+       kfree(new_mtd);
+out:
+       return err;
+}
+
+static int is_geode(void)
+{
+       /* These are the CPUs which will have a CS553[56] companion chip */
+       if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+           boot_cpu_data.x86 == 5 &&
+           boot_cpu_data.x86_model == 10)
+               return 1; /* Geode LX */
+
+       if ((boot_cpu_data.x86_vendor == X86_VENDOR_NSC ||
+            boot_cpu_data.x86_vendor == X86_VENDOR_CYRIX) &&
+           boot_cpu_data.x86 == 5 &&
+           boot_cpu_data.x86_model == 5)
+               return 1; /* Geode GX (née GX2) */
+
+       return 0;
+}
+
+static int __init cs553x_init(void)
+{
+       int err = -ENXIO;
+       int i;
+       uint64_t val;
+
+       /* If the CPU isn't a Geode GX or LX, abort */
+       if (!is_geode())
+               return -ENXIO;
+
+       /* If it doesn't have the CS553[56], abort */
+       rdmsrl(MSR_DIVIL_GLD_CAP, val);
+       val &= ~0xFFULL;
+       if (val != CAP_CS5535 && val != CAP_CS5536)
+               return -ENXIO;
+
+       /* If it doesn't have the NAND controller enabled, abort */
+       rdmsrl(MSR_DIVIL_BALL_OPTS, val);
+       if (val & 1) {
+               printk(KERN_INFO "CS553x NAND controller: Flash I/O not enabled in MSR_DIVIL_BALL_OPTS.\n");
+               return -ENXIO;
+       }
+
+       for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
+               rdmsrl(MSR_DIVIL_LBAR_FLSH0 + i, val);
+
+               if ((val & (FLSH_LBAR_EN|FLSH_NOR_NAND)) == (FLSH_LBAR_EN|FLSH_NOR_NAND))
+                       err = cs553x_init_one(i, !!(val & FLSH_MEM_IO), val & 0xFFFFFFFF);
+       }
+
+       /* Register all devices together here. This means we can easily hack it to 
+          do mtdconcat etc. if we want to. */
+       for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
+               if (cs553x_mtd[i]) {
+                       add_mtd_device(cs553x_mtd[i]);
+
+                       /* If any devices registered, return success. Else the last error. */
+                       err = 0;
+               }
+       }
+
+       return err;
+}
+
+module_init(cs553x_init);
+
+static void __exit cs553x_cleanup(void)
+{
+       int i;
+
+       for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
+               struct mtd_info *mtd = cs553x_mtd[i];
+               struct nand_chip *this;
+               void __iomem *mmio_base;
+
+               if (!mtd)
+                       break;
+
+               this = cs553x_mtd[i]->priv;
+               mmio_base = this->IO_ADDR_R;
+
+               /* Release resources, unregister device */
+               nand_release(cs553x_mtd[i]);
+               cs553x_mtd[i] = NULL;
+
+               /* unmap physical adress */
+               iounmap(mmio_base);
+
+               /* Free the MTD device structure */
+               kfree(mtd);
+       }
+}
+
+module_exit(cs553x_cleanup);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
+MODULE_DESCRIPTION("NAND controller driver for AMD CS5535/CS5536 companion chip");
index ec5e45e..6107f53 100644 (file)
@@ -58,10 +58,10 @@ static unsigned long __initdata doc_locations[] = {
        0xe4000000,
 #elif defined(CONFIG_MOMENCO_OCELOT)
        0x2f000000,
-        0xff000000,
+       0xff000000,
 #elif defined(CONFIG_MOMENCO_OCELOT_G) || defined (CONFIG_MOMENCO_OCELOT_C)
-        0xff000000,
-##else
+       0xff000000,
+#else
 #warning Unknown architecture for DiskOnChip. No default probe locations defined
 #endif
        0xffffffff };
@@ -73,7 +73,7 @@ struct doc_priv {
        unsigned long physadr;
        u_char ChipID;
        u_char CDSNControl;
-       int chips_per_floor; /* The number of chips detected on each floor */
+       int chips_per_floor;    /* The number of chips detected on each floor */
        int curfloor;
        int curchip;
        int mh0_page;
@@ -84,6 +84,7 @@ struct doc_priv {
 /* This is the syndrome computed by the HW ecc generator upon reading an empty
    page, one with all 0xff for data and stored ecc code. */
 static u_char empty_read_syndrome[6] = { 0x26, 0xff, 0x6d, 0x47, 0x73, 0x7a };
+
 /* This is the ecc value computed by the HW ecc generator upon writing an empty
    page, one with all 0xff for data. */
 static u_char empty_write_ecc[6] = { 0x4b, 0x00, 0xe2, 0x0e, 0x93, 0xf7 };
@@ -94,28 +95,29 @@ static u_char empty_write_ecc[6] = { 0x4b, 0x00, 0xe2, 0x0e, 0x93, 0xf7 };
 #define DoC_is_Millennium(doc) ((doc)->ChipID == DOC_ChipID_DocMil)
 #define DoC_is_2000(doc) ((doc)->ChipID == DOC_ChipID_Doc2k)
 
-static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd);
+static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd,
+                             unsigned int bitmask);
 static void doc200x_select_chip(struct mtd_info *mtd, int chip);
 
-static int debug=0;
+static int debug = 0;
 module_param(debug, int, 0);
 
-static int try_dword=1;
+static int try_dword = 1;
 module_param(try_dword, int, 0);
 
-static int no_ecc_failures=0;
+static int no_ecc_failures = 0;
 module_param(no_ecc_failures, int, 0);
 
-static int no_autopart=0;
+static int no_autopart = 0;
 module_param(no_autopart, int, 0);
 
-static int show_firmware_partition=0;
+static int show_firmware_partition = 0;
 module_param(show_firmware_partition, int, 0);
 
 #ifdef MTD_NAND_DISKONCHIP_BBTWRITE
-static int inftl_bbt_write=1;
+static int inftl_bbt_write = 1;
 #else
-static int inftl_bbt_write=0;
+static int inftl_bbt_write = 0;
 #endif
 module_param(inftl_bbt_write, int, 0);
 
@@ -123,7 +125,6 @@ static unsigned long doc_config_location = CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDR
 module_param(doc_config_location, ulong, 0);
 MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip");
 
-
 /* Sector size for HW ECC */
 #define SECTOR_SIZE 512
 /* The sector bytes are packed into NB_DATA 10 bit words */
@@ -147,7 +148,7 @@ static struct rs_control *rs_decoder;
  * some comments, improved a minor bit and converted it to make use
  * of the generic Reed-Solomon libary. tglx
  */
-static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
+static int doc_ecc_decode(struct rs_control *rs, uint8_t *data, uint8_t *ecc)
 {
        int i, j, nerr, errpos[8];
        uint8_t parity;
@@ -168,18 +169,18 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
         *  s[i] = ds[3]x^3 + ds[2]x^2 + ds[1]x^1 + ds[0]
         *  where x = alpha^(FCR + i)
         */
-       for(j = 1; j < NROOTS; j++) {
-               if(ds[j] == 0)
+       for (j = 1; j < NROOTS; j++) {
+               if (ds[j] == 0)
                        continue;
                tmp = rs->index_of[ds[j]];
-               for(i = 0; i < NROOTS; i++)
+               for (i = 0; i < NROOTS; i++)
                        s[i] ^= rs->alpha_to[rs_modnn(rs, tmp + (FCR + i) * j)];
        }
 
        /* Calc s[i] = s[i] / alpha^(v + i) */
        for (i = 0; i < NROOTS; i++) {
                if (syn[i])
-                       syn[i] = rs_modnn(rs, rs->index_of[s[i]] + (NN - FCR - i));
+                       syn[i] = rs_modnn(rs, rs->index_of[s[i]] + (NN - FCR - i));
        }
        /* Call the decoder library */
        nerr = decode_rs16(rs, NULL, NULL, 1019, syn, 0, errpos, 0, errval);
@@ -193,7 +194,7 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
         * but they are given by the design of the de/encoder circuit
         * in the DoC ASIC's.
         */
-       for(i = 0;i < nerr; i++) {
+       for (i = 0; i < nerr; i++) {
                int index, bitpos, pos = 1015 - errpos[i];
                uint8_t val;
                if (pos >= NB_DATA && pos < 1019)
@@ -205,8 +206,7 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
                           can be modified since pos is even */
                        index = (pos >> 3) ^ 1;
                        bitpos = pos & 7;
-                       if ((index >= 0 && index < SECTOR_SIZE) ||
-                           index == (SECTOR_SIZE + 1)) {
+                       if ((index >= 0 && index < SECTOR_SIZE) || index == (SECTOR_SIZE + 1)) {
                                val = (uint8_t) (errval[i] >> (2 + bitpos));
                                parity ^= val;
                                if (index < SECTOR_SIZE)
@@ -216,9 +216,8 @@ static int doc_ecc_decode (struct rs_control *rs, uint8_t *data, uint8_t *ecc)
                        bitpos = (bitpos + 10) & 7;
                        if (bitpos == 0)
                                bitpos = 8;
-                       if ((index >= 0 && index < SECTOR_SIZE) ||
-                           index == (SECTOR_SIZE + 1)) {
-                               val = (uint8_t)(errval[i] << (8 - bitpos));
+                       if ((index >= 0 && index < SECTOR_SIZE) || index == (SECTOR_SIZE + 1)) {
+                               val = (uint8_t) (errval[i] << (8 - bitpos));
                                parity ^= val;
                                if (index < SECTOR_SIZE)
                                        data[index] ^= val;
@@ -250,10 +249,11 @@ static void DoC_Delay(struct doc_priv *doc, unsigned short cycles)
 /* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */
 static int _DoC_WaitReady(struct doc_priv *doc)
 {
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        unsigned long timeo = jiffies + (HZ * 10);
 
-       if(debug) printk("_DoC_WaitReady...\n");
+       if (debug)
+               printk("_DoC_WaitReady...\n");
        /* Out-of-line routine to wait for chip response */
        if (DoC_is_MillenniumPlus(doc)) {
                while ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) {
@@ -280,7 +280,7 @@ static int _DoC_WaitReady(struct doc_priv *doc)
 
 static inline int DoC_WaitReady(struct doc_priv *doc)
 {
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int ret = 0;
 
        if (DoC_is_MillenniumPlus(doc)) {
@@ -298,7 +298,8 @@ static inline int DoC_WaitReady(struct doc_priv *doc)
                DoC_Delay(doc, 2);
        }
 
-       if(debug) printk("DoC_WaitReady OK\n");
+       if (debug)
+               printk("DoC_WaitReady OK\n");
        return ret;
 }
 
@@ -306,9 +307,10 @@ static void doc2000_write_byte(struct mtd_info *mtd, u_char datum)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
 
-       if(debug)printk("write_byte %02x\n", datum);
+       if (debug)
+               printk("write_byte %02x\n", datum);
        WriteDOC(datum, docptr, CDSNSlowIO);
        WriteDOC(datum, docptr, 2k_CDSN_IO);
 }
@@ -317,77 +319,78 @@ static u_char doc2000_read_byte(struct mtd_info *mtd)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        u_char ret;
 
        ReadDOC(docptr, CDSNSlowIO);
        DoC_Delay(doc, 2);
        ret = ReadDOC(docptr, 2k_CDSN_IO);
-       if (debug) printk("read_byte returns %02x\n", ret);
+       if (debug)
+               printk("read_byte returns %02x\n", ret);
        return ret;
 }
 
-static void doc2000_writebuf(struct mtd_info *mtd,
-                            const u_char *buf, int len)
+static void doc2000_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int i;
-       if (debug)printk("writebuf of %d bytes: ", len);
-       for (i=0; i < len; i++) {
+       if (debug)
+               printk("writebuf of %d bytes: ", len);
+       for (i = 0; i < len; i++) {
                WriteDOC_(buf[i], docptr, DoC_2k_CDSN_IO + i);
                if (debug && i < 16)
                        printk("%02x ", buf[i]);
        }
-       if (debug) printk("\n");
+       if (debug)
+               printk("\n");
 }
 
-static void doc2000_readbuf(struct mtd_info *mtd,
-                           u_char *buf, int len)
+static void doc2000_readbuf(struct mtd_info *mtd, u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
-       int i;
+       void __iomem *docptr = doc->virtadr;
+       int i;
 
-       if (debug)printk("readbuf of %d bytes: ", len);
+       if (debug)
+               printk("readbuf of %d bytes: ", len);
 
-       for (i=0; i < len; i++) {
+       for (i = 0; i < len; i++) {
                buf[i] = ReadDOC(docptr, 2k_CDSN_IO + i);
        }
 }
 
-static void doc2000_readbuf_dword(struct mtd_info *mtd,
-                           u_char *buf, int len)
+static void doc2000_readbuf_dword(struct mtd_info *mtd, u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
-       int i;
+       void __iomem *docptr = doc->virtadr;
+       int i;
 
-       if (debug) printk("readbuf_dword of %d bytes: ", len);
+       if (debug)
+               printk("readbuf_dword of %d bytes: ", len);
 
-       if (unlikely((((unsigned long)buf)|len) & 3)) {
-               for (i=0; i < len; i++) {
-                       *(uint8_t *)(&buf[i]) = ReadDOC(docptr, 2k_CDSN_IO + i);
+       if (unlikely((((unsigned long)buf) | len) & 3)) {
+               for (i = 0; i < len; i++) {
+                       *(uint8_t *) (&buf[i]) = ReadDOC(docptr, 2k_CDSN_IO + i);
                }
        } else {
-               for (i=0; i < len; i+=4) {
-                       *(uint32_t*)(&buf[i]) = readl(docptr + DoC_2k_CDSN_IO + i);
+               for (i = 0; i < len; i += 4) {
+                       *(uint32_t *) (&buf[i]) = readl(docptr + DoC_2k_CDSN_IO + i);
                }
        }
 }
 
-static int doc2000_verifybuf(struct mtd_info *mtd,
-                             const u_char *buf, int len)
+static int doc2000_verifybuf(struct mtd_info *mtd, const u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int i;
 
-       for (i=0; i < len; i++)
+       for (i = 0; i < len; i++)
                if (buf[i] != ReadDOC(docptr, 2k_CDSN_IO))
                        return -EFAULT;
        return 0;
@@ -400,12 +403,10 @@ static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr)
        uint16_t ret;
 
        doc200x_select_chip(mtd, nr);
-       doc200x_hwcontrol(mtd, NAND_CTL_SETCLE);
-       this->write_byte(mtd, NAND_CMD_READID);
-       doc200x_hwcontrol(mtd, NAND_CTL_CLRCLE);
-       doc200x_hwcontrol(mtd, NAND_CTL_SETALE);
-       this->write_byte(mtd, 0);
-       doc200x_hwcontrol(mtd, NAND_CTL_CLRALE);
+       doc200x_hwcontrol(mtd, NAND_CMD_READID,
+                         NAND_CTRL_CLE | NAND_CTRL_CHANGE);
+       doc200x_hwcontrol(mtd, 0, NAND_CTRL_ALE | NAND_CTRL_CHANGE);
+       doc200x_hwcontrol(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE);
 
        /* We cant' use dev_ready here, but at least we wait for the
         * command to complete
@@ -423,12 +424,11 @@ static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr)
                } ident;
                void __iomem *docptr = doc->virtadr;
 
-               doc200x_hwcontrol(mtd, NAND_CTL_SETCLE);
-               doc2000_write_byte(mtd, NAND_CMD_READID);
-               doc200x_hwcontrol(mtd, NAND_CTL_CLRCLE);
-               doc200x_hwcontrol(mtd, NAND_CTL_SETALE);
-               doc2000_write_byte(mtd, 0);
-               doc200x_hwcontrol(mtd, NAND_CTL_CLRALE);
+               doc200x_hwcontrol(mtd, NAND_CMD_READID,
+                                 NAND_CTRL_CLE | NAND_CTRL_CHANGE);
+               doc200x_hwcontrol(mtd, 0, NAND_CTRL_ALE | NAND_CTRL_CHANGE);
+               doc200x_hwcontrol(mtd, NAND_CMD_NONE,
+                                 NAND_NCE | NAND_CTRL_CHANGE);
 
                udelay(50);
 
@@ -464,7 +464,7 @@ static void __init doc2000_count_chips(struct mtd_info *mtd)
        printk(KERN_DEBUG "Detected %d chips per floor.\n", i);
 }
 
-static int doc200x_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
+static int doc200x_wait(struct mtd_info *mtd, struct nand_chip *this)
 {
        struct doc_priv *doc = this->priv;
 
@@ -482,7 +482,7 @@ static void doc2001_write_byte(struct mtd_info *mtd, u_char datum)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
 
        WriteDOC(datum, docptr, CDSNSlowIO);
        WriteDOC(datum, docptr, Mil_CDSN_IO);
@@ -493,7 +493,7 @@ static u_char doc2001_read_byte(struct mtd_info *mtd)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
 
        //ReadDOC(docptr, CDSNSlowIO);
        /* 11.4.5 -- delay twice to allow extended length cycle */
@@ -503,50 +503,47 @@ static u_char doc2001_read_byte(struct mtd_info *mtd)
        return ReadDOC(docptr, LastDataRead);
 }
 
-static void doc2001_writebuf(struct mtd_info *mtd,
-                            const u_char *buf, int len)
+static void doc2001_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int i;
 
-       for (i=0; i < len; i++)
+       for (i = 0; i < len; i++)
                WriteDOC_(buf[i], docptr, DoC_Mil_CDSN_IO + i);
        /* Terminate write pipeline */
        WriteDOC(0x00, docptr, WritePipeTerm);
 }
 
-static void doc2001_readbuf(struct mtd_info *mtd,
-                           u_char *buf, int len)
+static void doc2001_readbuf(struct mtd_info *mtd, u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int i;
 
        /* Start read pipeline */
        ReadDOC(docptr, ReadPipeInit);
 
-       for (i=0; i < len-1; i++)
+       for (i = 0; i < len - 1; i++)
                buf[i] = ReadDOC(docptr, Mil_CDSN_IO + (i & 0xff));
 
        /* Terminate read pipeline */
        buf[i] = ReadDOC(docptr, LastDataRead);
 }
 
-static int doc2001_verifybuf(struct mtd_info *mtd,
-                            const u_char *buf, int len)
+static int doc2001_verifybuf(struct mtd_info *mtd, const u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int i;
 
        /* Start read pipeline */
        ReadDOC(docptr, ReadPipeInit);
 
-       for (i=0; i < len-1; i++)
+       for (i = 0; i < len - 1; i++)
                if (buf[i] != ReadDOC(docptr, Mil_CDSN_IO)) {
                        ReadDOC(docptr, LastDataRead);
                        return i;
@@ -560,87 +557,90 @@ static u_char doc2001plus_read_byte(struct mtd_info *mtd)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        u_char ret;
 
-        ReadDOC(docptr, Mplus_ReadPipeInit);
-        ReadDOC(docptr, Mplus_ReadPipeInit);
-        ret = ReadDOC(docptr, Mplus_LastDataRead);
-       if (debug) printk("read_byte returns %02x\n", ret);
+       ReadDOC(docptr, Mplus_ReadPipeInit);
+       ReadDOC(docptr, Mplus_ReadPipeInit);
+       ret = ReadDOC(docptr, Mplus_LastDataRead);
+       if (debug)
+               printk("read_byte returns %02x\n", ret);
        return ret;
 }
 
-static void doc2001plus_writebuf(struct mtd_info *mtd,
-                            const u_char *buf, int len)
+static void doc2001plus_writebuf(struct mtd_info *mtd, const u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int i;
 
-       if (debug)printk("writebuf of %d bytes: ", len);
-       for (i=0; i < len; i++) {
+       if (debug)
+               printk("writebuf of %d bytes: ", len);
+       for (i = 0; i < len; i++) {
                WriteDOC_(buf[i], docptr, DoC_Mil_CDSN_IO + i);
                if (debug && i < 16)
                        printk("%02x ", buf[i]);
        }
-       if (debug) printk("\n");
+       if (debug)
+               printk("\n");
 }
 
-static void doc2001plus_readbuf(struct mtd_info *mtd,
-                           u_char *buf, int len)
+static void doc2001plus_readbuf(struct mtd_info *mtd, u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int i;
 
-       if (debug)printk("readbuf of %d bytes: ", len);
+       if (debug)
+               printk("readbuf of %d bytes: ", len);
 
        /* Start read pipeline */
        ReadDOC(docptr, Mplus_ReadPipeInit);
        ReadDOC(docptr, Mplus_ReadPipeInit);
 
-       for (i=0; i < len-2; i++) {
+       for (i = 0; i < len - 2; i++) {
                buf[i] = ReadDOC(docptr, Mil_CDSN_IO);
                if (debug && i < 16)
                        printk("%02x ", buf[i]);
        }
 
        /* Terminate read pipeline */
-       buf[len-2] = ReadDOC(docptr, Mplus_LastDataRead);
+       buf[len - 2] = ReadDOC(docptr, Mplus_LastDataRead);
        if (debug && i < 16)
-               printk("%02x ", buf[len-2]);
-       buf[len-1] = ReadDOC(docptr, Mplus_LastDataRead);
+               printk("%02x ", buf[len - 2]);
+       buf[len - 1] = ReadDOC(docptr, Mplus_LastDataRead);
        if (debug && i < 16)
-               printk("%02x ", buf[len-1]);
-       if (debug) printk("\n");
+               printk("%02x ", buf[len - 1]);
+       if (debug)
+               printk("\n");
 }
 
-static int doc2001plus_verifybuf(struct mtd_info *mtd,
-                            const u_char *buf, int len)
+static int doc2001plus_verifybuf(struct mtd_info *mtd, const u_char *buf, int len)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int i;
 
-       if (debug)printk("verifybuf of %d bytes: ", len);
+       if (debug)
+               printk("verifybuf of %d bytes: ", len);
 
        /* Start read pipeline */
        ReadDOC(docptr, Mplus_ReadPipeInit);
        ReadDOC(docptr, Mplus_ReadPipeInit);
 
-       for (i=0; i < len-2; i++)
+       for (i = 0; i < len - 2; i++)
                if (buf[i] != ReadDOC(docptr, Mil_CDSN_IO)) {
                        ReadDOC(docptr, Mplus_LastDataRead);
                        ReadDOC(docptr, Mplus_LastDataRead);
                        return i;
                }
-       if (buf[len-2] != ReadDOC(docptr, Mplus_LastDataRead))
-               return len-2;
-       if (buf[len-1] != ReadDOC(docptr, Mplus_LastDataRead))
-               return len-1;
+       if (buf[len - 2] != ReadDOC(docptr, Mplus_LastDataRead))
+               return len - 2;
+       if (buf[len - 1] != ReadDOC(docptr, Mplus_LastDataRead))
+               return len - 1;
        return 0;
 }
 
@@ -648,10 +648,11 @@ static void doc2001plus_select_chip(struct mtd_info *mtd, int chip)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int floor = 0;
 
-       if(debug)printk("select chip (%d)\n", chip);
+       if (debug)
+               printk("select chip (%d)\n", chip);
 
        if (chip == -1) {
                /* Disable flash internally */
@@ -660,7 +661,7 @@ static void doc2001plus_select_chip(struct mtd_info *mtd, int chip)
        }
 
        floor = chip / doc->chips_per_floor;
-       chip -= (floor *  doc->chips_per_floor);
+       chip -= (floor * doc->chips_per_floor);
 
        /* Assert ChipEnable and deassert WriteProtect */
        WriteDOC((DOC_FLASH_CE), docptr, Mplus_FlashSelect);
@@ -674,72 +675,61 @@ static void doc200x_select_chip(struct mtd_info *mtd, int chip)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
        int floor = 0;
 
-       if(debug)printk("select chip (%d)\n", chip);
+       if (debug)
+               printk("select chip (%d)\n", chip);
 
        if (chip == -1)
                return;
 
        floor = chip / doc->chips_per_floor;
-       chip -= (floor *  doc->chips_per_floor);
+       chip -= (floor * doc->chips_per_floor);
 
        /* 11.4.4 -- deassert CE before changing chip */
-       doc200x_hwcontrol(mtd, NAND_CTL_CLRNCE);
+       doc200x_hwcontrol(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE);
 
        WriteDOC(floor, docptr, FloorSelect);
        WriteDOC(chip, docptr, CDSNDeviceSelect);
 
-       doc200x_hwcontrol(mtd, NAND_CTL_SETNCE);
+       doc200x_hwcontrol(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE);
 
        doc->curchip = chip;
        doc->curfloor = floor;
 }
 
-static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd)
+#define CDSN_CTRL_MSK (CDSN_CTRL_CE | CDSN_CTRL_CLE | CDSN_CTRL_ALE)
+
+static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd,
+                             unsigned int ctrl)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
 
-       switch(cmd) {
-       case NAND_CTL_SETNCE:
-               doc->CDSNControl |= CDSN_CTRL_CE;
-               break;
-       case NAND_CTL_CLRNCE:
-               doc->CDSNControl &= ~CDSN_CTRL_CE;
-               break;
-       case NAND_CTL_SETCLE:
-               doc->CDSNControl |= CDSN_CTRL_CLE;
-               break;
-       case NAND_CTL_CLRCLE:
-               doc->CDSNControl &= ~CDSN_CTRL_CLE;
-               break;
-       case NAND_CTL_SETALE:
-               doc->CDSNControl |= CDSN_CTRL_ALE;
-               break;
-       case NAND_CTL_CLRALE:
-               doc->CDSNControl &= ~CDSN_CTRL_ALE;
-               break;
-       case NAND_CTL_SETWP:
-               doc->CDSNControl |= CDSN_CTRL_WP;
-               break;
-       case NAND_CTL_CLRWP:
-               doc->CDSNControl &= ~CDSN_CTRL_WP;
-               break;
+       if (ctrl & NAND_CTRL_CHANGE) {
+               doc->CDSNControl &= ~CDSN_CTRL_MSK;
+               doc->CDSNControl |= ctrl & CDSN_CTRL_MSK;
+               if (debug)
+                       printk("hwcontrol(%d): %02x\n", cmd, doc->CDSNControl);
+               WriteDOC(doc->CDSNControl, docptr, CDSNControl);
+               /* 11.4.3 -- 4 NOPs after CSDNControl write */
+               DoC_Delay(doc, 4);
+       }
+       if (cmd != NAND_CMD_NONE) {
+               if (DoC_is_2000(doc))
+                       doc2000_write_byte(mtd, cmd);
+               else
+                       doc2001_write_byte(mtd, cmd);
        }
-       if (debug)printk("hwcontrol(%d): %02x\n", cmd, doc->CDSNControl);
-       WriteDOC(doc->CDSNControl, docptr, CDSNControl);
-       /* 11.4.3 -- 4 NOPs after CSDNControl write */
-       DoC_Delay(doc, 4);
 }
 
-static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int column, int page_addr)
+static void doc2001plus_command(struct mtd_info *mtd, unsigned command, int column, int page_addr)
 {
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
-        void __iomem *docptr = doc->virtadr;
+       void __iomem *docptr = doc->virtadr;
 
        /*
         * Must terminate write pipeline before sending any commands
@@ -756,9 +746,9 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col
        if (command == NAND_CMD_SEQIN) {
                int readcmd;
 
-               if (column >= mtd->oobblock) {
+               if (column >= mtd->writesize) {
                        /* OOB area */
-                       column -= mtd->oobblock;
+                       column -= mtd->writesize;
                        readcmd = NAND_CMD_READOOB;
                } else if (column < 256) {
                        /* First 256 bytes --> READ0 */
@@ -782,25 +772,26 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col
                        WriteDOC(column, docptr, Mplus_FlashAddress);
                }
                if (page_addr != -1) {
-                       WriteDOC((unsigned char) (page_addr & 0xff), docptr, Mplus_FlashAddress);
-                       WriteDOC((unsigned char) ((page_addr >> 8) & 0xff), docptr, Mplus_FlashAddress);
+                       WriteDOC((unsigned char)(page_addr & 0xff), docptr, Mplus_FlashAddress);
+                       WriteDOC((unsigned char)((page_addr >> 8) & 0xff), docptr, Mplus_FlashAddress);
                        /* One more address cycle for higher density devices */
                        if (this->chipsize & 0x0c000000) {
-                               WriteDOC((unsigned char) ((page_addr >> 16) & 0x0f), docptr, Mplus_FlashAddress);
+                               WriteDOC((unsigned char)((page_addr >> 16) & 0x0f), docptr, Mplus_FlashAddress);
                                printk("high density\n");
                        }
                }
                WriteDOC(0, docptr, Mplus_WritePipeTerm);
                WriteDOC(0, docptr, Mplus_WritePipeTerm);
                /* deassert ALE */
-               if (command == NAND_CMD_READ0 || command == NAND_CMD_READ1 || command == NAND_CMD_READOOB || command == NAND_CMD_READID)
+               if (command == NAND_CMD_READ0 || command == NAND_CMD_READ1 ||
+                   command == NAND_CMD_READOOB || command == NAND_CMD_READID)
                        WriteDOC(0, docptr, Mplus_FlashControl);
        }
 
        /*
         * program and erase have their own busy handlers
         * status and sequential in needs no delay
-       */
+        */
        switch (command) {
 
        case NAND_CMD_PAGEPROG:
@@ -817,55 +808,57 @@ static void doc2001plus_command (struct mtd_info *mtd, unsigned command, int col
                WriteDOC(NAND_CMD_STATUS, docptr, Mplus_FlashCmd);