]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
sf: Sync the spi_flash_addr() changes w.r.t mainline code
authorJagannadha Sutradharudu Teki <jaganna@xilinx.com>
Wed, 15 May 2013 17:52:10 +0000 (23:22 +0530)
committerMichal Simek <michal.simek@xilinx.com>
Mon, 27 May 2013 11:21:19 +0000 (13:21 +0200)
Change the spi_flash_addr() logic based on the mainline code.

Signed-off-by: Jagannadha Sutradharudu Teki <jaganna@xilinx.com>
drivers/mtd/spi/spi_flash.c

index 763c22a7e2b746fc4cff546b442b969f276aa531..2eb3e2b8ad86953727c917c6c2f1332acbba0bed 100644 (file)
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static void spi_flash_addr(unsigned long page_addr,
-                       unsigned long byte_addr, u8 *cmd)
+static void spi_flash_addr(u32 addr, u8 *cmd)
 {
        /* cmd[0] is actual command */
-       cmd[1] = page_addr >> 8;
-       cmd[2] = page_addr;
-       cmd[3] = byte_addr;
+       cmd[1] = addr >> 16;
+       cmd[2] = addr >> 8;
+       cmd[3] = addr >> 0;
 }
 
 static int spi_flash_read_write(struct spi_slave *spi,
@@ -122,7 +121,9 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
                if (flash->spi->max_write_size)
                        chunk_len = min(chunk_len, flash->spi->max_write_size);
 
-               spi_flash_addr(page_addr, byte_addr, cmd);
+               cmd[1] = page_addr >> 8;
+               cmd[2] = page_addr;
+               cmd[3] = byte_addr;
 
                debug("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",
                      buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);
@@ -133,7 +134,7 @@ int spi_flash_cmd_write_multi(struct spi_flash *flash, u32 offset,
                        break;
                }
 
-               ret = spi_flash_cmd_write(flash->spi, cmd, sizeof(cmd),
+               ret = spi_flash_cmd_write(flash->spi, cmd, 4,
                                          buf + actual, chunk_len);
                if (ret < 0) {
                        debug("SF: write failed\n");
@@ -170,7 +171,6 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
                size_t len, void *data)
 {
-       unsigned long page_addr, page_size, byte_addr;
        u8 cmd[5];
        u8 bank_sel;
        u32 remain_len, read_len;
@@ -180,7 +180,6 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
        if (flash->memory_map)
                memcpy(data, flash->memory_map + offset, len);
 
-       page_size = flash->page_size;
        cmd[0] = CMD_READ_ARRAY_FAST;
        cmd[sizeof(cmd)-1] = 0x00;
 
@@ -212,10 +211,7 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
                else
                        read_len = remain_len;
 
-               page_addr = (offset & SPI_FLASH_16MB_MASK) / page_size;
-               byte_addr = (offset & SPI_FLASH_16MB_MASK) % page_size;
-
-               spi_flash_addr(page_addr, byte_addr, cmd);
+               spi_flash_addr(offset, cmd);
 
                ret = spi_flash_read_common(flash, cmd, sizeof(cmd),
                                                        data, read_len);
@@ -276,12 +272,9 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
        u32 start, end, erase_size;
        int ret;
-       unsigned long page_addr;
        u8 cmd[4];
        u8 bank_sel;
 
-       start = offset;
-       end = len;
        erase_size = flash->sector_size;
        if (offset % erase_size || len % erase_size) {
                debug("SF: Erase offset/length not multiple of erase size\n");
@@ -298,6 +291,8 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
                cmd[0] = CMD_ERASE_4K;
        else
                cmd[0] = CMD_ERASE_64K;
+       start = offset;
+       end = start + len;
 
        while (len) {
                if (flash->spi->is_dual == 1) {
@@ -319,8 +314,7 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
                        return ret;
                }
 
-               page_addr = (offset & SPI_FLASH_16MB_MASK) / flash->page_size;
-               spi_flash_addr(page_addr, 0, cmd);
+               spi_flash_addr(offset, cmd);
 
                debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
                      cmd[2], cmd[3], offset);