Merge tag 'dm-9oct18' of git://git.denx.de/u-boot-dm
[platform/kernel/u-boot.git] / drivers / mtd / spi / spi_flash.c
index 2911729..9230060 100644 (file)
@@ -128,6 +128,7 @@ static int clean_bar(struct spi_flash *flash)
        if (flash->bank_curr == 0)
                return 0;
        cmd = flash->bank_write_cmd;
+       flash->bank_curr = 0;
 
        return spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1);
 }
@@ -467,17 +468,17 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
                size_t len, void *data)
 {
        struct spi_slave *spi = flash->spi;
-       u8 *cmd, cmdsz;
+       u8 cmdsz;
        u32 remain_len, read_len, read_addr;
        int bank_sel = 0;
-       int ret = -1;
+       int ret = 0;
 
        /* Handle memory-mapped SPI */
        if (flash->memory_map) {
                ret = spi_claim_bus(spi);
                if (ret) {
                        debug("SF: unable to claim SPI bus\n");
-                       return ret;
+                       return log_ret(ret);
                }
                spi_xfer(spi, 0, NULL, NULL, SPI_XFER_MMAP);
                spi_flash_copy_mmap(data, flash->memory_map + offset, len);
@@ -487,11 +488,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
        }
 
        cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte;
-       cmd = calloc(1, cmdsz);
-       if (!cmd) {
-               debug("SF: Failed to allocate cmd\n");
-               return -ENOMEM;
-       }
+       u8 cmd[cmdsz];
 
        cmd[0] = flash->read_cmd;
        while (len) {
@@ -504,7 +501,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 #ifdef CONFIG_SPI_FLASH_BAR
                ret = write_bar(flash, read_addr);
                if (ret < 0)
-                       return ret;
+                       return log_ret(ret);
                bank_sel = flash->bank_curr;
 #endif
                remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) *
@@ -534,8 +531,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
        ret = clean_bar(flash);
 #endif
 
-       free(cmd);
-       return ret;
+       return log_ret(ret);
 }
 
 #ifdef CONFIG_SPI_FLASH_SST
@@ -1202,14 +1198,15 @@ int spi_flash_scan(struct spi_flash *flash)
        flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0;
        flash->page_size = info->page_size;
        /*
-        * The Spansion S25FL032P and S25FL064P have 256b pages, yet use the
-        * 0x4d00 Extended JEDEC code. The rest of the Spansion flashes with
-        * the 0x4d00 Extended JEDEC code have 512b pages. All of the others
-        * have 256b pages.
+        * The Spansion S25FS512S, S25FL032P and S25FL064P have 256b pages,
+        * yet use the 0x4d00 Extended JEDEC code. The rest of the Spansion
+        * flashes with the 0x4d00 Extended JEDEC code have 512b pages.
+        * All of the others have 256b pages.
         */
        if (JEDEC_EXT(info) == 0x4d00) {
                if ((JEDEC_ID(info) != 0x0215) &&
-                   (JEDEC_ID(info) != 0x0216))
+                   (JEDEC_ID(info) != 0x0216) &&
+                   (JEDEC_ID(info) != 0x0220))
                        flash->page_size = 512;
        }
        flash->page_size <<= flash->shift;