]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
sf: unify erase commands
authorMike Frysinger <vapier@gentoo.org>
Mon, 5 Mar 2012 03:35:50 +0000 (22:35 -0500)
committerMike Frysinger <vapier@gentoo.org>
Mon, 5 Mar 2012 03:35:50 +0000 (22:35 -0500)
Analysis of the flash drivers shows that they all use 0x20 if the erase
size is 4KiB, or 0xd8 if it's larger.  So with this info in hand, we can
unify all the erase functionality in one place.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
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 eccdf833df05a742b20a606ec5d4232784cd3e4d..d9d43ca57e19de46864939c6fab4791697621366 100644 (file)
 
 #include "spi_flash_internal.h"
 
-/* EN25Q128-specific commands */
-#define CMD_EN25Q128_SE                0x20    /* Sector Erase */
-#define CMD_EN25Q128_BE                0xd8    /* Block Erase */
-
 struct eon_spi_flash_params {
        u8 idcode1;
        u16 nr_sectors;
@@ -38,11 +34,6 @@ static const struct eon_spi_flash_params eon_spi_flash_table[] = {
        },
 };
 
-static int eon_erase(struct spi_flash *flash, u32 offset, size_t 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)
 {
        const struct eon_spi_flash_params *params;
@@ -70,7 +61,7 @@ struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
        flash->name = params->name;
 
        flash->write = spi_flash_cmd_write_multi;
-       flash->erase = eon_erase;
+       flash->erase = spi_flash_cmd_erase;
        flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 256;
        flash->sector_size = 256 * 16 * 16;
index 894b1ca2b4ca63839b4d30331c1ed1ed41ca20f4..5268c661ea301fd9380a1f15390932dca170cda8 100644 (file)
 
 #include "spi_flash_internal.h"
 
-/* MX25xx-specific commands */
-#define CMD_MX25XX_SE          0x20    /* Sector Erase */
-#define CMD_MX25XX_BE          0xD8    /* Block Erase */
-#define CMD_MX25XX_CE          0xc7    /* Chip Erase */
-
 struct macronix_spi_flash_params {
        u16 idcode;
        u16 nr_blocks;
@@ -123,11 +118,6 @@ static int macronix_unlock(struct spi_flash *flash)
        return ret;
 }
 
-static int macronix_erase(struct spi_flash *flash, u32 offset, size_t 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)
 {
        const struct macronix_spi_flash_params *params;
@@ -156,7 +146,7 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
        flash->name = params->name;
 
        flash->write = spi_flash_cmd_write_multi;
-       flash->erase = macronix_erase;
+       flash->erase = spi_flash_cmd_erase;
        flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 256;
        flash->sector_size = 256 * 16 * 16;
index bedde0760db6d2408dc8f8ac3c311b2d2273027e..9a114ac6a1f48da45d7855ccfe47d6fcc066ebd5 100644 (file)
 
 #include "spi_flash_internal.h"
 
-/* S25FLxx-specific commands */
-#define CMD_S25FLXX_SE         0xd8    /* Sector Erase */
-#define CMD_S25FLXX_BE         0xc7    /* Bulk Erase */
-
 struct spansion_spi_flash_params {
        u16 idcode1;
        u16 idcode2;
@@ -102,11 +98,6 @@ static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
        },
 };
 
-static int spansion_erase(struct spi_flash *flash, u32 offset, size_t 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)
 {
        const struct spansion_spi_flash_params *params;
@@ -140,7 +131,7 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
        flash->name = params->name;
 
        flash->write = spi_flash_cmd_write_multi;
-       flash->erase = spansion_erase;
+       flash->erase = spi_flash_cmd_erase;
        flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 256;
        flash->sector_size = 256 * params->pages_per_sector;
index f689cc47cfccac051e4257de47bedfcecb5bd13a..4ab4e13b46c2bb4e829182fb49a5439d365ce433 100644 (file)
@@ -190,8 +190,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
                CMD_READ_STATUS, STATUS_WIP);
 }
 
-int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
-                       u32 offset, size_t len)
+int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
        u32 start, end, erase_size;
        int ret;
@@ -209,7 +208,10 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
                return ret;
        }
 
-       cmd[0] = erase_cmd;
+       if (erase_size == 4096)
+               cmd[0] = CMD_ERASE_4K;
+       else
+               cmd[0] = CMD_ERASE_64K;
        start = offset;
        end = start + len;
 
index 0c78249791e81f98a19130231473163e8ce12080..3c6bccf0c88585468bb6fcfd792c805e52b592d6 100644 (file)
 #define CMD_WRITE_DISABLE              0x04
 #define CMD_READ_STATUS                        0x05
 #define CMD_WRITE_ENABLE               0x06
+#define CMD_ERASE_4K                   0x20
+#define CMD_ERASE_32K                  0x52
+#define CMD_ERASE_64K                  0xd8
+#define CMD_ERASE_CHIP                 0xc7
 
 /* Common status */
 #define STATUS_WIP                     0x01
@@ -88,8 +92,7 @@ int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
 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 offset, size_t len);
+int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len);
 
 /* Manufacturer-specific probe functions */
 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode);
index e51dfc7f29fbd15ef0ebbc3b0d8f4b64e28928d1..dcc0bbe4b136ad19a5893123989f26fd2ebf52bb 100644 (file)
@@ -20,7 +20,6 @@
 
 #define CMD_SST_BP             0x02    /* Byte Program */
 #define CMD_SST_AAI_WP         0xAD    /* Auto Address Increment Word Program */
-#define CMD_SST_SE             0x20    /* Sector Erase */
 
 #define SST_SR_WIP             (1 << 0)        /* Write-in-Progress */
 #define SST_SR_WEL             (1 << 1)        /* Write enable */
@@ -45,13 +44,6 @@ struct sst_spi_flash {
        const struct sst_spi_flash_params *params;
 };
 
-static inline struct sst_spi_flash *to_sst_spi_flash(struct spi_flash *flash)
-{
-       return container_of(flash, struct sst_spi_flash, flash);
-}
-
-#define SST_SECTOR_SIZE (4 * 1024)
-#define SST_PAGE_SIZE   256
 static const struct sst_spi_flash_params sst_spi_flash_table[] = {
        {
                .idcode1 = 0x8d,
@@ -211,11 +203,6 @@ sst_write_wp(struct spi_flash *flash, u32 offset, size_t len, const void *buf)
        return ret;
 }
 
-static int sst_erase(struct spi_flash *flash, u32 offset, size_t len)
-{
-       return spi_flash_cmd_erase(flash, CMD_SST_SE, offset, len);
-}
-
 static int
 sst_unlock(struct spi_flash *flash)
 {
@@ -269,10 +256,10 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
                stm->flash.write = sst_write_wp;
        else
                stm->flash.write = spi_flash_cmd_write_multi;
-       stm->flash.erase = sst_erase;
+       stm->flash.erase = spi_flash_cmd_erase;
        stm->flash.read = spi_flash_cmd_read_fast;
-       stm->flash.page_size = SST_PAGE_SIZE;
-       stm->flash.sector_size = SST_SECTOR_SIZE;
+       stm->flash.page_size = 256;
+       stm->flash.sector_size = 4096;
        stm->flash.size = stm->flash.sector_size * params->nr_sectors;
 
        /* Flash powers up read-only, so clear BP# bits */
index 6f7b807da2ce12bcaf6eeeccf14672d458bd0527..75d6822a7d686a328cd5c4c305d9a1837bf8a62f 100644 (file)
@@ -34,8 +34,6 @@
 #include "spi_flash_internal.h"
 
 /* M25Pxx-specific commands */
-#define CMD_M25PXX_SE          0xd8    /* Sector Erase */
-#define CMD_M25PXX_BE          0xc7    /* Bulk Erase */
 #define CMD_M25PXX_RES         0xab    /* Release from DP, and Read Signature */
 
 struct stmicro_spi_flash_params {
@@ -96,11 +94,6 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
        },
 };
 
-static int stmicro_erase(struct spi_flash *flash, u32 offset, size_t 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)
 {
        const struct stmicro_spi_flash_params *params;
@@ -142,7 +135,7 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
        flash->name = params->name;
 
        flash->write = spi_flash_cmd_write_multi;
-       flash->erase = stmicro_erase;
+       flash->erase = spi_flash_cmd_erase;
        flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 256;
        flash->sector_size = 256 * params->pages_per_sector;
index d1358ea24b74f5ac838c6f54ed66a8dbdc3f3509..427b71fcdcd4f78fdd79e05263cf3767d5117cfb 100644 (file)
 
 #include "spi_flash_internal.h"
 
-/* M25Pxx-specific commands */
-#define CMD_W25_SE             0x20    /* Sector (4K) Erase */
-#define CMD_W25_BE             0xd8    /* Block (64K) Erase */
-#define CMD_W25_CE             0xc7    /* Chip Erase */
-
 struct winbond_spi_flash_params {
        uint16_t        id;
        uint16_t        nr_blocks;
@@ -69,11 +64,6 @@ static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
        },
 };
 
-static int winbond_erase(struct spi_flash *flash, u32 offset, size_t 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)
 {
        const struct winbond_spi_flash_params *params;
@@ -102,7 +92,7 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
        flash->name = params->name;
 
        flash->write = spi_flash_cmd_write_multi;
-       flash->erase = winbond_erase;
+       flash->erase = spi_flash_cmd_erase;
        flash->read = spi_flash_cmd_read_fast;
        flash->page_size = 4096;
        flash->sector_size = 4096;