spl, nand, atmel_nand: add erase one block function
authorHeiko Schocher <hs@denx.de>
Fri, 31 Oct 2014 07:31:02 +0000 (08:31 +0100)
committerTom Rini <trini@ti.com>
Mon, 17 Nov 2014 13:47:17 +0000 (08:47 -0500)
erase one nand block in spl code. keep it simple, as size matters
This is used on the upcoming taurus spl support.

Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Scott Wood <scottwood@freescale.com>
Reviewed-by: Bo Shen <voice.shen@atmel.com>
Reviewed-by: Andreas Bießmann <andreas.devel@googlemail.com>
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
drivers/mtd/nand/atmel_nand.c
include/nand.h

index d506e42b5e2f30fe91d42739aa26eec347563976..d6d6f85a9e3ef1390e659c8dddfea8b0dcff5c64 100644 (file)
@@ -1274,6 +1274,39 @@ static int nand_read_page(int block, int page, void *dst)
 
        return 0;
 }
+
+int spl_nand_erase_one(int block, int page)
+{
+       struct nand_chip *this = mtd.priv;
+       void (*hwctrl)(struct mtd_info *mtd, int cmd,
+                       unsigned int ctrl) = this->cmd_ctrl;
+       int page_addr;
+
+       if (nand_chip.select_chip)
+               nand_chip.select_chip(&mtd, 0);
+
+       page_addr = page + block * CONFIG_SYS_NAND_PAGE_COUNT;
+       hwctrl(&mtd, NAND_CMD_ERASE1, NAND_CTRL_CLE | NAND_CTRL_CHANGE);
+       /* Row address */
+       hwctrl(&mtd, (page_addr & 0xff), NAND_CTRL_ALE | NAND_CTRL_CHANGE);
+       hwctrl(&mtd, ((page_addr >> 8) & 0xff),
+              NAND_CTRL_ALE | NAND_CTRL_CHANGE);
+#ifdef CONFIG_SYS_NAND_5_ADDR_CYCLE
+       /* One more address cycle for devices > 128MiB */
+       hwctrl(&mtd, (page_addr >> 16) & 0x0f,
+              NAND_CTRL_ALE | NAND_CTRL_CHANGE);
+#endif
+
+       hwctrl(&mtd, NAND_CMD_ERASE2, NAND_CTRL_CLE | NAND_CTRL_CHANGE);
+       udelay(2000);
+
+       while (!this->dev_ready(&mtd))
+               ;
+
+       nand_deselect();
+
+       return 0;
+}
 #else
 static int nand_read_page(int block, int page, void *dst)
 {
index fc735d1ec4479099b2b1813754596721258d4214..15e31ab538ba5e84c09ae512b7f5a2dad0c21c47 100644 (file)
@@ -167,3 +167,4 @@ __attribute__((noreturn)) void nand_boot(void);
 #define ENV_OFFSET_SIZE 8
 int get_nand_env_oob(nand_info_t *nand, unsigned long *result);
 #endif
+int spl_nand_erase_one(int block, int page);