summaryrefslogtreecommitdiff
path: root/drivers/mtd/spi/sst.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2011-01-10 02:20:13 -0500
committerWolfgang Denk <wd@denx.de>2011-04-11 21:00:54 +0200
commite7b44eddbef88b1a922f8d82088ba236aad01caf (patch)
tree4ba07d5e3ed3d4b9992afb6f2a47f556aa3d6741 /drivers/mtd/spi/sst.c
parent6163045bcd276818d9ad6bdd1bf36ddcd60d014b (diff)
downloadu-boot-imx-e7b44eddbef88b1a922f8d82088ba236aad01caf.zip
u-boot-imx-e7b44eddbef88b1a922f8d82088ba236aad01caf.tar.gz
u-boot-imx-e7b44eddbef88b1a922f8d82088ba236aad01caf.tar.bz2
sf: unify erase functions
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'drivers/mtd/spi/sst.c')
-rw-r--r--drivers/mtd/spi/sst.c63
1 files changed, 3 insertions, 60 deletions
diff --git a/drivers/mtd/spi/sst.c b/drivers/mtd/spi/sst.c
index 4a82f8a..d550550 100644
--- a/drivers/mtd/spi/sst.c
+++ b/drivers/mtd/spi/sst.c
@@ -212,67 +212,10 @@ sst_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf)
return ret;
}
-int
-sst_erase(struct spi_flash *flash, u32 offset, size_t len)
+int sst_erase(struct spi_flash *flash, u32 offset, size_t len)
{
- unsigned long sector_size;
- u32 start, end;
- int ret;
- u8 cmd[4];
-
- /*
- * This function currently uses sector erase only.
- * Probably speed things up by using bulk erase
- * when possible.
- */
-
- sector_size = SST_SECTOR_SIZE;
-
- if (offset % sector_size) {
- debug("SF: Erase offset not multiple of sector size\n");
- return -1;
- }
-
- ret = spi_claim_bus(flash->spi);
- if (ret) {
- debug("SF: Unable to claim SPI bus\n");
- return ret;
- }
-
- cmd[0] = CMD_SST_SE;
- cmd[3] = 0;
- start = offset;
- end = start + len;
-
- ret = 0;
- while (offset < end) {
- cmd[1] = offset >> 16;
- cmd[2] = offset >> 8;
- offset += sector_size;
-
- debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
- cmd[2], cmd[3], offset);
-
- ret = sst_enable_writing(flash);
- if (ret)
- break;
-
- ret = spi_flash_cmd_write(flash->spi, cmd, sizeof(cmd), NULL, 0);
- if (ret) {
- debug("SF: sst page erase failed\n");
- break;
- }
-
- ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PAGE_ERASE_TIMEOUT);
- if (ret)
- break;
- }
-
- debug("SF: sst: Successfully erased %lu bytes @ 0x%x\n",
- len * sector_size, start);
-
- spi_release_bus(flash->spi);
- return ret;
+ return spi_flash_cmd_erase(flash, CMD_SST_SE, SST_SECTOR_SIZE,
+ offset, len);
}
static int