@@ -498,6 +498,7 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
asf->flash.size = page_size * params->pages_per_block
* params->blocks_per_sector
* params->nr_sectors;
+ asf->flash.sector_size = page_size;
printf("SF: Detected %s with page size %u, total ",
params->name, page_size);
@@ -217,6 +217,7 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
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;
+ mcx->flash.sector_size = mcx->flash.size/params->nr_blocks;
printf("SF: Detected %s with page size %u, total ",
params->name, params->page_size);
@@ -199,8 +199,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,
+ return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, flash->sector_size,
offset, len);
}
@@ -242,6 +241,7 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
spsn->flash.read = spi_flash_cmd_read_fast;
spsn->flash.size = params->page_size * params->pages_per_sector
* params->nr_sectors;
+ spsn->flash.sector_size = spsn->flash.size/params->nr_sectors;
printf("SF: Detected %s with page size %u, total ",
params->name, params->page_size);
@@ -201,7 +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,
+ return spi_flash_cmd_erase(flash, CMD_SST_SE, flash->sector_size,
offset, len);
}
@@ -257,6 +257,7 @@ 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;
+ stm->flash.sector_size = SST_SECTOR_SIZE;
printf("SF: Detected %s with page size %u, total ",
params->name, SST_SECTOR_SIZE);
@@ -200,8 +200,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,
+ return spi_flash_cmd_erase(flash, CMD_M25PXX_SE, flash->sector_size,
offset, len);
}
@@ -251,6 +250,7 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
stm->flash.read = spi_flash_cmd_read_fast;
stm->flash.size = params->page_size * params->pages_per_sector
* params->nr_sectors;
+ stm->flash.sector_size = stm->flash.size/params->nr_sectors;
printf("SF: Detected %s with page size %u, total ",
params->name, params->page_size);
@@ -173,8 +173,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,
+ return spi_flash_cmd_erase(flash, CMD_W25_SE, flash->sector_size,
offset, len);
}
@@ -216,6 +215,8 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
stm->flash.size = page_size * params->pages_per_sector
* params->sectors_per_block
* params->nr_blocks;
+ stm->flash.sector_size = (1 << stm->params->l2_page_size) *
+ stm->params->pages_per_sector;
printf("SF: Detected %s with page size %u, total ",
params->name, page_size);
@@ -38,6 +38,8 @@ struct spi_flash {
u32 size;
+ u16 sector_size;
+
int (*read)(struct spi_flash *flash, u32 offset,
size_t len, void *buf);
int (*write)(struct spi_flash *flash, u32 offset,