sf: unify read functions
authorMike Frysinger <vapier@gentoo.org>
Mon, 10 Jan 2011 07:20:14 +0000 (02:20 -0500)
committerWolfgang Denk <wd@denx.de>
Mon, 11 Apr 2011 19:00:55 +0000 (21:00 +0200)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
drivers/mtd/spi/atmel.c
drivers/mtd/spi/eon.c
drivers/mtd/spi/macronix.c
drivers/mtd/spi/spansion.c
drivers/mtd/spi/spi_flash.c
drivers/mtd/spi/spi_flash_internal.h
drivers/mtd/spi/sst.c
drivers/mtd/spi/stmicro.c
drivers/mtd/spi/winbond.c

index 7827b750f6b6a37bb0e2cee58332e7f390e355d5..a9910b11b80dc3e1cd9a5137b3d5abaf25edb631 100644 (file)
@@ -143,20 +143,6 @@ static void at45_build_address(struct atmel_spi_flash *asf, u8 *cmd, u32 offset)
        cmd[2] = byte_addr;
 }
 
-static int dataflash_read_fast_p2(struct spi_flash *flash,
-               u32 offset, size_t len, void *buf)
-{
-       u8 cmd[5];
-
-       cmd[0] = CMD_READ_ARRAY_FAST;
-       cmd[1] = offset >> 16;
-       cmd[2] = offset >> 8;
-       cmd[3] = offset;
-       cmd[4] = 0x00;
-
-       return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int dataflash_read_fast_at45(struct spi_flash *flash,
                u32 offset, size_t len, void *buf)
 {
@@ -492,7 +478,7 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
                        asf->flash.erase = dataflash_erase_at45;
                        page_size += 1 << (params->l2_page_size - 5);
                } else {
-                       asf->flash.read = dataflash_read_fast_p2;
+                       asf->flash.read = spi_flash_cmd_read_fast;
                        asf->flash.write = dataflash_write_p2;
                        asf->flash.erase = dataflash_erase_p2;
                }
@@ -501,7 +487,7 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
 
        case DF_FAMILY_AT26F:
        case DF_FAMILY_AT26DF:
-               asf->flash.read = dataflash_read_fast_p2;
+               asf->flash.read = spi_flash_cmd_read_fast;
                break;
 
        default:
index 0c0b05f010d6353f0fd9115d71ab2b6e8d847a51..01caed5abe83b157afdb69c8daab32878edc2c67 100644 (file)
@@ -56,26 +56,6 @@ static const struct eon_spi_flash_params eon_spi_flash_table[] = {
        },
 };
 
-static int eon_read_fast(struct spi_flash *flash,
-                        u32 offset, size_t len, void *buf)
-{
-       struct eon_spi_flash *eon = to_eon_spi_flash(flash);
-       unsigned long page_addr;
-       unsigned long page_size;
-       u8 cmd[5];
-
-       page_size = eon->params->page_size;
-       page_addr = offset / page_size;
-
-       cmd[0] = CMD_READ_ARRAY_FAST;
-       cmd[1] = page_addr >> 8;
-       cmd[2] = page_addr;
-       cmd[3] = offset % page_size;
-       cmd[4] = 0x00;
-
-       return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int eon_write(struct spi_flash *flash,
                     u32 offset, size_t len, const void *buf)
 {
@@ -177,7 +157,7 @@ struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
 
        eon->flash.write = eon_write;
        eon->flash.erase = eon_erase;
-       eon->flash.read = eon_read_fast;
+       eon->flash.read = spi_flash_cmd_read_fast;
        eon->flash.size = params->page_size * params->pages_per_sector
            * params->nr_sectors;
 
index 573e1dba7ebeda9674e7c606c5452be8114fcf36..4155d4d9a4663b1868132a9132ed767f98d975bd 100644 (file)
@@ -112,26 +112,6 @@ static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
        },
 };
 
-static int macronix_read_fast(struct spi_flash *flash,
-                             u32 offset, size_t len, void *buf)
-{
-       struct macronix_spi_flash *mcx = to_macronix_spi_flash(flash);
-       unsigned long page_addr;
-       unsigned long page_size;
-       u8 cmd[5];
-
-       page_size = mcx->params->page_size;
-       page_addr = offset / page_size;
-
-       cmd[0] = CMD_READ_ARRAY_FAST;
-       cmd[1] = page_addr >> 8;
-       cmd[2] = page_addr;
-       cmd[3] = offset % page_size;
-       cmd[4] = 0x00;
-
-       return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int macronix_write(struct spi_flash *flash,
                          u32 offset, size_t len, const void *buf)
 {
@@ -234,7 +214,7 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
 
        mcx->flash.write = macronix_write;
        mcx->flash.erase = macronix_erase;
-       mcx->flash.read = macronix_read_fast;
+       mcx->flash.read = spi_flash_cmd_read_fast;
        mcx->flash.size = params->page_size * params->pages_per_sector
            * params->sectors_per_block * params->nr_blocks;
 
index be4fc67ef703d3dda9e47cd26934cf7a994b4a68..d54a5fad23adf06ba2cfda450bb113d1b1a30884 100644 (file)
@@ -133,30 +133,6 @@ static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
        },
 };
 
-static int spansion_read_fast(struct spi_flash *flash,
-                            u32 offset, size_t len, void *buf)
-{
-       struct spansion_spi_flash *spsn = to_spansion_spi_flash(flash);
-       unsigned long page_addr;
-       unsigned long page_size;
-       u8 cmd[5];
-
-       page_size = spsn->params->page_size;
-       page_addr = offset / page_size;
-
-       cmd[0] = CMD_READ_ARRAY_FAST;
-       cmd[1] = page_addr >> 8;
-       cmd[2] = page_addr;
-       cmd[3] = offset % page_size;
-       cmd[4] = 0x00;
-
-       debug
-               ("READ: 0x%x => cmd = { 0x%02x 0x%02x%02x%02x%02x } len = 0x%x\n",
-                offset, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], len);
-
-       return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int spansion_write(struct spi_flash *flash,
                         u32 offset, size_t len, const void *buf)
 {
@@ -263,7 +239,7 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
 
        spsn->flash.write = spansion_write;
        spsn->flash.erase = spansion_erase;
-       spsn->flash.read = spansion_read_fast;
+       spsn->flash.read = spi_flash_cmd_read_fast;
        spsn->flash.size = params->page_size * params->pages_per_sector
            * params->nr_sectors;
 
index ca4bbb206a6f642e251eec2e36a677f6d61f4456..5c261f14a63b54c5d619dcc809f25e829e7c8faf 100644 (file)
@@ -77,6 +77,18 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
        return ret;
 }
 
+int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
+               size_t len, void *data)
+{
+       u8 cmd[5];
+
+       cmd[0] = CMD_READ_ARRAY_FAST;
+       spi_flash_addr(offset, cmd);
+       cmd[4] = 0x00;
+
+       return spi_flash_read_common(flash, cmd, sizeof(cmd), data, len);
+}
+
 int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
                           u8 cmd, u8 poll_bit)
 {
index 114b63459afb04cb45c162c4162cf6b25152a6bd..d7bcd6d6afdeee746954d33421d9ba3ac1152514 100644 (file)
@@ -35,6 +35,9 @@ int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len);
 int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
                size_t cmd_len, void *data, size_t data_len);
 
+int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
+               size_t len, void *data);
+
 /*
  * Send a multi-byte command to the device followed by (optional)
  * data. Used for programming the flash array, etc.
index d55055035cdb4c7120d1bb379aad7e679cbd3e68..792d04dd2beae3256a6d3d247ae1ddac6df49b13 100644 (file)
@@ -107,19 +107,6 @@ sst_disable_writing(struct spi_flash *flash)
        return ret;
 }
 
-static int
-sst_read_fast(struct spi_flash *flash, u32 offset, size_t len, void *buf)
-{
-       u8 cmd[5] = {
-               CMD_READ_ARRAY_FAST,
-               offset >> 16,
-               offset >> 8,
-               offset,
-               0x00,
-       };
-       return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int
 sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)
 {
@@ -269,7 +256,6 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
 
        stm->flash.write = sst_write;
        stm->flash.erase = sst_erase;
-       stm->flash.read = sst_read_fast;
        stm->flash.size = SST_SECTOR_SIZE * params->nr_sectors;
 
        printf("SF: Detected %s with page size %u, total ",
index 494005c4a4718b0e8e4932d19eee9b300fb080c1..7ef690d9bfd08a698ea1ee0a1c44220b103febec 100644 (file)
@@ -134,26 +134,6 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
        },
 };
 
-static int stmicro_read_fast(struct spi_flash *flash,
-                            u32 offset, size_t len, void *buf)
-{
-       struct stmicro_spi_flash *stm = to_stmicro_spi_flash(flash);
-       unsigned long page_addr;
-       unsigned long page_size;
-       u8 cmd[5];
-
-       page_size = stm->params->page_size;
-       page_addr = offset / page_size;
-
-       cmd[0] = CMD_READ_ARRAY_FAST;
-       cmd[1] = page_addr >> 8;
-       cmd[2] = page_addr;
-       cmd[3] = offset % page_size;
-       cmd[4] = 0x00;
-
-       return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int stmicro_write(struct spi_flash *flash,
                         u32 offset, size_t len, const void *buf)
 {
@@ -268,7 +248,7 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
 
        stm->flash.write = stmicro_write;
        stm->flash.erase = stmicro_erase;
-       stm->flash.read = stmicro_read_fast;
+       stm->flash.read = spi_flash_cmd_read_fast;
        stm->flash.size = params->page_size * params->pages_per_sector
            * params->nr_sectors;
 
index 8470a826bff7ad291133b90a852c4097bd5c6791..e88802f0e67bdf5a7d62420fcdfa8bbf2222d16f 100644 (file)
@@ -105,44 +105,6 @@ static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
        },
 };
 
-/*
- * Assemble the address part of a command for Winbond devices in
- * non-power-of-two page size mode.
- */
-static void winbond_build_address(struct winbond_spi_flash *stm, u8 *cmd, u32 offset)
-{
-       unsigned long page_addr;
-       unsigned long byte_addr;
-       unsigned long page_size;
-       unsigned int page_shift;
-
-       /*
-        * The "extra" space per page is the power-of-two page size
-        * divided by 32.
-        */
-       page_shift = stm->params->l2_page_size;
-       page_size = (1 << page_shift);
-       page_addr = offset / page_size;
-       byte_addr = offset % page_size;
-
-       cmd[0] = page_addr >> (16 - page_shift);
-       cmd[1] = page_addr << (page_shift - 8) | (byte_addr >> 8);
-       cmd[2] = byte_addr;
-}
-
-static int winbond_read_fast(struct spi_flash *flash,
-               u32 offset, size_t len, void *buf)
-{
-       struct winbond_spi_flash *stm = to_winbond_spi_flash(flash);
-       u8 cmd[5];
-
-       cmd[0] = CMD_READ_ARRAY_FAST;
-       winbond_build_address(stm, cmd + 1, offset);
-       cmd[4] = 0x00;
-
-       return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int winbond_write(struct spi_flash *flash,
                u32 offset, size_t len, const void *buf)
 {
@@ -250,7 +212,7 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
 
        stm->flash.write = winbond_write;
        stm->flash.erase = winbond_erase;
-       stm->flash.read = winbond_read_fast;
+       stm->flash.read = spi_flash_cmd_read_fast;
        stm->flash.size = page_size * params->pages_per_sector
                                * params->sectors_per_block
                                * params->nr_blocks;