cfi_flash: Fix logical continuations
[oweals/u-boot.git] / drivers / mtd / nand / nand_spl_simple.c
index bc6a09a1b5b6951dc2c52a17ac8be9583038ac41..56e86d1760993f592d45294f76dc3ca67fe5167f 100644 (file)
@@ -26,7 +26,7 @@ static struct nand_chip nand_chip;
 static int nand_command(int block, int page, uint32_t offs,
        u8 cmd)
 {
-       struct nand_chip *this = mtd->priv();
+       struct nand_chip *this = mtd_to_nand(mtd);
        int page_addr = page + block * CONFIG_SYS_NAND_PAGE_COUNT;
 
        while (!this->dev_ready(mtd))
@@ -63,7 +63,7 @@ static int nand_command(int block, int page, uint32_t offs,
 static int nand_command(int block, int page, uint32_t offs,
        u8 cmd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int page_addr = page + block * CONFIG_SYS_NAND_PAGE_COUNT;
        void (*hwctrl)(struct mtd_info *mtd, int cmd,
                        unsigned int ctrl) = this->cmd_ctrl;
@@ -114,7 +114,7 @@ static int nand_command(int block, int page, uint32_t offs,
 
 static int nand_is_bad_block(int block)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u_char bb_data[2];
 
        nand_command(block, 0, CONFIG_SYS_NAND_BAD_BLOCK_POS,
@@ -139,7 +139,7 @@ static int nand_is_bad_block(int block)
 #if defined(CONFIG_SYS_NAND_HW_ECC_OOBFIRST)
 static int nand_read_page(int block, int page, uchar *dst)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u_char ecc_calc[ECCTOTAL];
        u_char ecc_code[ECCTOTAL];
        u_char oob_data[CONFIG_SYS_NAND_OOBSIZE];
@@ -170,7 +170,7 @@ static int nand_read_page(int block, int page, uchar *dst)
 #else
 static int nand_read_page(int block, int page, void *dst)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u_char ecc_calc[ECCTOTAL];
        u_char ecc_code[ECCTOTAL];
        u_char oob_data[CONFIG_SYS_NAND_OOBSIZE];
@@ -209,48 +209,13 @@ static int nand_read_page(int block, int page, void *dst)
 }
 #endif
 
-int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
-{
-       unsigned int block, lastblock;
-       unsigned int page;
-
-       /*
-        * offs has to be aligned to a page address!
-        */
-       block = offs / CONFIG_SYS_NAND_BLOCK_SIZE;
-       lastblock = (offs + size - 1) / CONFIG_SYS_NAND_BLOCK_SIZE;
-       page = (offs % CONFIG_SYS_NAND_BLOCK_SIZE) / CONFIG_SYS_NAND_PAGE_SIZE;
-
-       while (block <= lastblock) {
-               if (!nand_is_bad_block(block)) {
-                       /*
-                        * Skip bad blocks
-                        */
-                       while (page < CONFIG_SYS_NAND_PAGE_COUNT) {
-                               nand_read_page(block, page, dst);
-                               dst += CONFIG_SYS_NAND_PAGE_SIZE;
-                               page++;
-                       }
-
-                       page = 0;
-               } else {
-                       lastblock++;
-               }
-
-               block++;
-       }
-
-       return 0;
-}
-
 /* nand_init() - initialize data to make nand usable by SPL */
 void nand_init(void)
 {
        /*
         * Init board specific nand support
         */
-       mtd = &nand_chip.mtd;
-       mtd->priv = &nand_chip;
+       mtd = nand_to_mtd(&nand_chip);
        nand_chip.IO_ADDR_R = nand_chip.IO_ADDR_W =
                (void  __iomem *)CONFIG_SYS_NAND_BASE;
        board_nand_init(&nand_chip);
@@ -272,3 +237,5 @@ void nand_deselect(void)
        if (nand_chip.select_chip)
                nand_chip.select_chip(mtd, -1);
 }
+
+#include "nand_spl_loaders.c"