]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/mtd/nand/diskonchip.c
Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux...
[linux-2.6-omap-h63xx.git] / drivers / mtd / nand / diskonchip.c
index d160930276d658945b808f5dbe07cb697c788e94..595208f965a55cdd31f5359cd704d283785a3d34 100644 (file)
@@ -95,7 +95,8 @@ 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;
@@ -113,7 +114,7 @@ module_param(no_autopart, int, 0);
 static int show_firmware_partition = 0;
 module_param(show_firmware_partition, int, 0);
 
-#ifdef MTD_NAND_DISKONCHIP_BBTWRITE
+#ifdef CONFIG_MTD_NAND_DISKONCHIP_BBTWRITE
 static int inftl_bbt_write = 1;
 #else
 static int inftl_bbt_write = 0;
@@ -402,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
@@ -425,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);
 
@@ -466,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;
 
@@ -690,54 +688,41 @@ static void doc200x_select_chip(struct mtd_info *mtd, int chip)
        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;
 
-       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)
@@ -983,12 +968,14 @@ static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, unsign
        return 0;
 }
 
-static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc)
+static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat,
+                               u_char *read_ecc, u_char *isnull)
 {
        int i, ret = 0;
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
        void __iomem *docptr = doc->virtadr;
+       uint8_t calc_ecc[6];
        volatile u_char dummy;
        int emptymatch = 1;
 
@@ -1071,8 +1058,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_
  * safer.  The only problem with it is that any code that parses oobfree must
  * be able to handle out-of-order segments.
  */
-static struct nand_oobinfo doc200x_oobinfo = {
-       .useecc = MTD_NANDECC_AUTOPLACE,
+static struct nand_ecclayout doc200x_oobinfo = {
        .eccbytes = 6,
        .eccpos = {0, 1, 2, 3, 4, 5},
        .oobfree = {{8, 8}, {6, 2}}
@@ -1454,7 +1440,6 @@ static inline int __init doc2000_init(struct mtd_info *mtd)
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
 
-       this->write_byte = doc2000_write_byte;
        this->read_byte = doc2000_read_byte;
        this->write_buf = doc2000_writebuf;
        this->read_buf = doc2000_readbuf;
@@ -1472,7 +1457,6 @@ static inline int __init doc2001_init(struct mtd_info *mtd)
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
 
-       this->write_byte = doc2001_write_byte;
        this->read_byte = doc2001_read_byte;
        this->write_buf = doc2001_writebuf;
        this->read_buf = doc2001_readbuf;
@@ -1504,16 +1488,15 @@ static inline int __init doc2001plus_init(struct mtd_info *mtd)
        struct nand_chip *this = mtd->priv;
        struct doc_priv *doc = this->priv;
 
-       this->write_byte = NULL;
        this->read_byte = doc2001plus_read_byte;
        this->write_buf = doc2001plus_writebuf;
        this->read_buf = doc2001plus_readbuf;
        this->verify_buf = doc2001plus_verifybuf;
        this->scan_bbt = inftl_scan_bbt;
-       this->hwcontrol = NULL;
+       this->cmd_ctrl = NULL;
        this->select_chip = doc2001plus_select_chip;
        this->cmdfunc = doc2001plus_command;
-       this->enable_hwecc = doc2001plus_enable_hwecc;
+       this->ecc.hwctl = doc2001plus_enable_hwecc;
 
        doc->chips_per_floor = 1;
        mtd->name = "DiskOnChip Millennium Plus";
@@ -1652,13 +1635,12 @@ static int __init doc_probe(unsigned long physadr)
 
        len = sizeof(struct mtd_info) +
            sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr));
-       mtd = kmalloc(len, GFP_KERNEL);
+       mtd = kzalloc(len, GFP_KERNEL);
        if (!mtd) {
                printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len);
                ret = -ENOMEM;
                goto fail;
        }
-       memset(mtd, 0, len);
 
        nand                    = (struct nand_chip *) (mtd + 1);
        doc                     = (struct doc_priv *) (nand + 1);
@@ -1670,17 +1652,19 @@ static int __init doc_probe(unsigned long physadr)
 
        nand->priv              = doc;
        nand->select_chip       = doc200x_select_chip;
-       nand->hwcontrol         = doc200x_hwcontrol;
+       nand->cmd_ctrl          = doc200x_hwcontrol;
        nand->dev_ready         = doc200x_dev_ready;
        nand->waitfunc          = doc200x_wait;
        nand->block_bad         = doc200x_block_bad;
-       nand->enable_hwecc      = doc200x_enable_hwecc;
-       nand->calculate_ecc     = doc200x_calculate_ecc;
-       nand->correct_data      = doc200x_correct_data;
-
-       nand->autooob           = &doc200x_oobinfo;
-       nand->eccmode           = NAND_ECC_HW6_512;
-       nand->options           = NAND_USE_FLASH_BBT | NAND_HWECC_SYNDROME;
+       nand->ecc.hwctl         = doc200x_enable_hwecc;
+       nand->ecc.calculate     = doc200x_calculate_ecc;
+       nand->ecc.correct       = doc200x_correct_data;
+
+       nand->ecc.layout        = &doc200x_oobinfo;
+       nand->ecc.mode          = NAND_ECC_HW_SYNDROME;
+       nand->ecc.size          = 512;
+       nand->ecc.bytes         = 6;
+       nand->options           = NAND_USE_FLASH_BBT;
 
        doc->physadr            = physadr;
        doc->virtadr            = virtadr;