]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sf: add struct spi_flash.sector_size parameter
authorRichard Retanubun <RichardRetanubun@ruggedcom.com>
Wed, 16 Feb 2011 21:37:22 +0000 (16:37 -0500)
committerMike Frysinger <vapier@gentoo.org>
Tue, 12 Apr 2011 06:15:37 +0000 (02:15 -0400)
This patch adds a new member to struct spi_flash (u16 sector_size)
and updates the spi flash drivers to start populating it.

This parameter can be used by spi flash commands that need to round
up units of operation to the flash's sector_size.

Having this number in one place also allows duplicated code to be
further collapsed into one common location (such as erase parameter
and the detected message).

Signed-off-by: Richard Retanubun <RichardRetanubun@RuggedCom.com>
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/ramtron.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
include/spi_flash.h

index 10df3879e0ed4ba6c9eaf91cbc9438fcd39f6a58..d17ebf616d6e58a077f66451887994c58be28027 100644 (file)
@@ -522,14 +522,11 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
                goto err;
        }
 
+       asf->flash.sector_size = page_size;
        asf->flash.size = page_size * params->pages_per_block
                                * params->blocks_per_sector
                                * params->nr_sectors;
 
-       printf("SF: Detected %s with page size %u, total ",
-              params->name, page_size);
-       print_size(asf->flash.size, "\n");
-
        return &asf->flash;
 
 err:
index 01caed5abe83b157afdb69c8daab32878edc2c67..a3640f416fb3de686e2e4881b3bea8ff88c0192e 100644 (file)
@@ -121,11 +121,7 @@ static int eon_write(struct spi_flash *flash,
 
 int eon_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-       struct eon_spi_flash *eon = to_eon_spi_flash(flash);
-       return spi_flash_cmd_erase(flash, CMD_EN25Q128_BE,
-               eon->params->page_size * eon->params->pages_per_sector *
-                       eon->params->sectors_per_block;
-               offset, len);
+       return spi_flash_cmd_erase(flash, CMD_EN25Q128_BE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
@@ -158,11 +154,10 @@ 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 = spi_flash_cmd_read_fast;
+       eon->flash.sector_size = params->page_size * params->pages_per_sector
+           * params->sectors_per_block;
        eon->flash.size = params->page_size * params->pages_per_sector
            * params->nr_sectors;
 
-       debug("SF: Detected %s with page size %u, total %u bytes\n",
-             params->name, params->page_size, eon->flash.size);
-
        return &eon->flash;
 }
index 4155d4d9a4663b1868132a9132ed767f98d975bd..a0512d1e3a5299a14ffa09e3fa28c0626a906de1 100644 (file)
@@ -177,11 +177,7 @@ static int macronix_write(struct spi_flash *flash,
 
 int macronix_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-       struct macronix_spi_flash *mcx = to_macronix_spi_flash(flash);
-       return spi_flash_cmd_erase(flash, CMD_MX25XX_BE,
-               mcx->params->page_size * mcx->params->pages_per_sector *
-                       mcx->params->sectors_per_block,
-               offset, len);
+       return spi_flash_cmd_erase(flash, CMD_MX25XX_BE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
@@ -215,12 +211,9 @@ 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 = spi_flash_cmd_read_fast;
-       mcx->flash.size = params->page_size * params->pages_per_sector
-           * params->sectors_per_block * params->nr_blocks;
-
-       printf("SF: Detected %s with page size %u, total ",
-              params->name, params->page_size);
-       print_size(mcx->flash.size, "\n");
+       mcx->flash.sector_size = params->page_size * params->pages_per_sector
+               * params->sectors_per_block;
+       mcx->flash.size = mcx->flash.sector_size * params->nr_blocks;
 
        return &mcx->flash;
 }
index 171390d5c326ac3f57645e88df9eda13dc990c5b..453dd3f44e27261a7b6d64d121319495a90deb66 100644 (file)
@@ -312,8 +312,5 @@ found:
        sn->flash.erase = ramtron_erase;
        sn->flash.size = params->size;
 
-       printf("SF: Detected %s with size ", params->name);
-       print_size(sn->flash.size, "\n");
-
        return &sn->flash;
 }
index d54a5fad23adf06ba2cfda450bb113d1b1a30884..f138d7344ef1bb866245e01d67edfedf9bcef3f5 100644 (file)
@@ -198,10 +198,7 @@ static int spansion_write(struct spi_flash *flash,
 
 int spansion_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-       struct spansion_spi_flash *spsn = to_spansion_spi_flash(flash);
-       return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE,
-               spsn->params->page_size * spsn->params->pages_per_sector,
-               offset, len);
+       return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
@@ -240,12 +237,8 @@ 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 = spi_flash_cmd_read_fast;
-       spsn->flash.size = params->page_size * params->pages_per_sector
-           * params->nr_sectors;
-
-       printf("SF: Detected %s with page size %u, total ",
-              params->name, params->page_size);
-       print_size(spsn->flash.size, "\n");
+       spsn->flash.sector_size = params->page_size * params->pages_per_sector;
+       spsn->flash.size = spsn->flash.sector_size * params->nr_sectors;
 
        return &spsn->flash;
 }
index 5c261f14a63b54c5d619dcc809f25e829e7c8faf..ccb7e314085066879e4842ec4b1ad2c5da003783 100644 (file)
@@ -131,12 +131,13 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 }
 
 int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
-                       u32 erase_size, u32 offset, size_t len)
+                       u32 offset, size_t len)
 {
-       u32 start, end;
+       u32 start, end, erase_size;
        int ret;
        u8 cmd[4];
 
+       erase_size = flash->sector_size;
        if (offset % erase_size || len % erase_size) {
                debug("SF: Erase offset/length not multiple of erase size\n");
                return -1;
@@ -296,6 +297,10 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
                goto err_manufacturer_probe;
        }
 
+       printf("SF: Detected %s with page size %u, total ",
+              flash->name, flash->sector_size);
+       print_size(flash->size, "\n");
+
        spi_release_bus(spi);
 
        return flash;
index d7bcd6d6afdeee746954d33421d9ba3ac1152514..fc109cef53e73eb62914d48f2b6d357284b673e2 100644 (file)
@@ -64,7 +64,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout);
 
 /* Erase sectors. */
 int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
-                       u32 erase_size, u32 offset, size_t len);
+                       u32 offset, size_t len);
 
 /* Manufacturer-specific probe functions */
 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode);
index 792d04dd2beae3256a6d3d247ae1ddac6df49b13..29bb88b5393d2c41bd39659d724313b2e0f2d20b 100644 (file)
@@ -201,8 +201,7 @@ sst_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf)
 
 int sst_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-       return spi_flash_cmd_erase(flash, CMD_SST_SE, SST_SECTOR_SIZE,
-               offset, len);
+       return spi_flash_cmd_erase(flash, CMD_SST_SE, offset, len);
 }
 
 static int
@@ -256,11 +255,8 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
 
        stm->flash.write = sst_write;
        stm->flash.erase = sst_erase;
-       stm->flash.size = SST_SECTOR_SIZE * params->nr_sectors;
-
-       printf("SF: Detected %s with page size %u, total ",
-              params->name, SST_SECTOR_SIZE);
-       print_size(stm->flash.size, "\n");
+       stm->flash.sector_size = SST_SECTOR_SIZE;
+       stm->flash.size = stm->flash.sector_size * params->nr_sectors;
 
        /* Flash powers up read-only, so clear BP# bits */
        sst_unlock(&stm->flash);
index 7ef690d9bfd08a698ea1ee0a1c44220b103febec..a1980b1ed78a6da72f6bd149e778b677c9146190 100644 (file)
@@ -199,10 +199,7 @@ static int stmicro_write(struct spi_flash *flash,
 
 int stmicro_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-       struct stmicro_spi_flash *stm = to_stmicro_spi_flash(flash);
-       return spi_flash_cmd_erase(flash, CMD_M25PXX_SE,
-               stm->params->page_size * stm->params->pages_per_sector,
-               offset, len);
+       return spi_flash_cmd_erase(flash, CMD_M25PXX_SE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
@@ -249,12 +246,8 @@ 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 = spi_flash_cmd_read_fast;
-       stm->flash.size = params->page_size * params->pages_per_sector
-           * params->nr_sectors;
-
-       printf("SF: Detected %s with page size %u, total ",
-              params->name, params->page_size);
-       print_size(stm->flash.size, "\n");
+       stm->flash.sector_size = params->page_size * params->pages_per_sector;
+       stm->flash.size = stm->flash.sector_size * params->nr_sectors;
 
        return &stm->flash;
 }
index e88802f0e67bdf5a7d62420fcdfa8bbf2222d16f..72d94ad216e217a64ff70ffba2e2c381ce96b0f3 100644 (file)
@@ -172,10 +172,7 @@ out:
 
 int winbond_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-       struct winbond_spi_flash *stm = to_winbond_spi_flash(flash);
-       return spi_flash_cmd_erase(flash, CMD_W25_SE,
-               (1 << stm->params->l2_page_size) * stm->params->pages_per_sector,
-               offset, len);
+       return spi_flash_cmd_erase(flash, CMD_W25_SE, offset, len);
 }
 
 struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
@@ -213,13 +210,11 @@ 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 = spi_flash_cmd_read_fast;
+       stm->flash.sector_size = (1 << stm->params->l2_page_size) *
+               stm->params->pages_per_sector;
        stm->flash.size = page_size * params->pages_per_sector
                                * params->sectors_per_block
                                * params->nr_blocks;
 
-       printf("SF: Detected %s with page size %u, total ",
-              params->name, page_size);
-       print_size(stm->flash.size, "\n");
-
        return &stm->flash;
 }
index 89cc3a7cc3340238b9de031ef2d0a1ab56a595d1..a384071fbee4b908eff02cd86db82f15677e0d2d 100644 (file)
@@ -33,6 +33,8 @@ struct spi_flash {
 
        u32             size;
 
+       u32             sector_size;
+
        int             (*read)(struct spi_flash *flash, u32 offset,
                                size_t len, void *buf);
        int             (*write)(struct spi_flash *flash, u32 offset,