spi_flash: Move (de-)assertion of /CS to single location

This consolidates all calls to spi_claim_bus() and spi_release_bus()
to a single location where spi_xfer() is called. This avoids confusing
(and potentially redundant) calls that were being done throughout the
generic spi_flash.c functions and chip-specific functions.

I don't think the current approach could even work since many chip
drivers assert /CS once and then issue multiple commands such as page
program followed by reading the status register. I suspect the reason
we didn't notice it on x86 is because the ICH/PCH handled each
individual command correctly (spi_claim_bus() and spi_release_bus()
are noops) in spite of the broken code.

BUG=none
BRANCH=none
TEST=tested on nyan and link
Signed-off-by: David Hendricks <dhendrix@chromium.org>

Change-Id: I3257e2f6a2820834f4c9018069f90fcf2bab05f6
Reviewed-on: https://chromium-review.googlesource.com/194510
Reviewed-by: David Hendricks <dhendrix@chromium.org>
Commit-Queue: David Hendricks <dhendrix@chromium.org>
Tested-by: David Hendricks <dhendrix@chromium.org>
This commit is contained in:
David Hendricks 2014-04-11 19:48:55 -07:00 committed by chrome-internal-fetch
commit d3394d34fb
8 changed files with 11 additions and 71 deletions

View file

@ -63,7 +63,7 @@ static int eon_write(struct spi_flash *flash,
unsigned long page_size;
size_t chunk_len;
size_t actual;
int ret;
int ret = 0;
u8 cmd[4];
page_size = eon->params->page_size;
@ -71,13 +71,7 @@ static int eon_write(struct spi_flash *flash,
byte_addr = offset % page_size;
flash->spi->rw = SPI_WRITE_FLAG;
ret = spi_claim_bus(flash->spi);
if (ret) {
printk(BIOS_WARNING, "SF: Unable to claim SPI bus\n");
return ret;
}
ret = 0;
for (actual = 0; actual < len; actual += chunk_len) {
chunk_len = min(len - actual, page_size - byte_addr);
@ -118,7 +112,6 @@ static int eon_write(struct spi_flash *flash,
len, offset);
#endif
spi_release_bus(flash->spi);
return ret;
}

View file

@ -125,19 +125,13 @@ static int gigadevice_write(struct spi_flash *flash, u32 offset,
unsigned long page_size;
size_t chunk_len;
size_t actual;
int ret;
int ret = 0;
u8 cmd[4];
page_size = min(1 << stm->params->l2_page_size, CONTROLLER_PAGE_LIMIT);
byte_addr = offset % page_size;
flash->spi->rw = SPI_WRITE_FLAG;
ret = spi_claim_bus(flash->spi);
if (ret) {
printk(BIOS_WARNING,
"SF gigadevice.c: Unable to claim SPI bus\n");
return ret;
}
for (actual = 0; actual < len; actual += chunk_len) {
chunk_len = min(len - actual, page_size - byte_addr);
@ -185,7 +179,6 @@ static int gigadevice_write(struct spi_flash *flash, u32 offset,
ret = 0;
out:
spi_release_bus(flash->spi);
return ret;
}

View file

@ -128,20 +128,14 @@ static int macronix_write(struct spi_flash *flash,
unsigned long page_size;
size_t chunk_len;
size_t actual;
int ret;
int ret = 0;
u8 cmd[4];
page_size = min(mcx->params->page_size, CONTROLLER_PAGE_LIMIT);
byte_addr = offset % page_size;
flash->spi->rw = SPI_WRITE_FLAG;
ret = spi_claim_bus(flash->spi);
if (ret) {
printk(BIOS_WARNING, "SF: Unable to claim SPI bus\n");
return ret;
}
ret = 0;
for (actual = 0; actual < len; actual += chunk_len) {
chunk_len = min(len - actual, page_size - byte_addr);
@ -182,7 +176,6 @@ static int macronix_write(struct spi_flash *flash,
" 0x%lx\n", len, (unsigned long)(offset - len));
#endif
spi_release_bus(flash->spi);
return ret;
}

View file

@ -140,7 +140,7 @@ static int spansion_write(struct spi_flash *flash,
unsigned long page_size;
size_t chunk_len;
size_t actual;
int ret;
int ret = 0;
u8 cmd[4];
page_size = spsn->params->page_size;
@ -148,13 +148,7 @@ static int spansion_write(struct spi_flash *flash,
byte_addr = offset % page_size;
flash->spi->rw = SPI_WRITE_FLAG;
ret = spi_claim_bus(flash->spi);
if (ret) {
printk(BIOS_WARNING, "SF: Unable to claim SPI bus\n");
return ret;
}
ret = 0;
for (actual = 0; actual < len; actual += chunk_len) {
chunk_len = min(len - actual, page_size - byte_addr);
@ -195,7 +189,6 @@ static int spansion_write(struct spi_flash *flash,
len, offset);
#endif
spi_release_bus(flash->spi);
return ret;
}

View file

@ -46,6 +46,9 @@ static int do_spi_flash_cmd(struct spi_slave *spi, const void *dout,
{
int ret = 1;
if (spi_claim_bus(spi))
return ret;
#if CONFIG_SPI_ATOMIC_SEQUENCING == 1
if (spi_xfer(spi, dout, bytes_out, din, bytes_in) < 0)
goto done;
@ -63,6 +66,7 @@ static int do_spi_flash_cmd(struct spi_slave *spi, const void *dout,
ret = 0;
done:
spi_release_bus(spi);
return ret;
}
@ -111,9 +115,7 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
int ret;
spi->rw = SPI_READ_FLAG;
spi_claim_bus(spi);
ret = spi_flash_cmd_read(spi, cmd, cmd_len, data, data_len);
spi_release_bus(spi);
return ret;
}
@ -191,11 +193,6 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
}
flash->spi->rw = SPI_WRITE_FLAG;
ret = spi_claim_bus(flash->spi);
if (ret) {
printk(BIOS_WARNING, "SF: Unable to claim SPI bus\n");
return ret;
}
cmd[0] = erase_cmd;
start = offset;
@ -225,7 +222,6 @@ int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
printk(BIOS_DEBUG, "SF: Successfully erased %zu bytes @ %#x\n", len, start);
out:
spi_release_bus(flash->spi);
return ret;
}
@ -301,11 +297,6 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs)
}
spi->rw = SPI_READ_FLAG;
ret = spi_claim_bus(spi);
if (ret) {
printk(BIOS_WARNING, "SF: Failed to claim SPI bus: %d\n", ret);
goto err_claim_bus;
}
/* Read the ID codes */
ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode));
@ -354,13 +345,9 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs)
printk(BIOS_INFO, "SF: Detected %s with page size %x, total %x\n",
flash->name, flash->sector_size, flash->size);
spi_release_bus(spi);
return flash;
err_manufacturer_probe:
err_read_id:
spi_release_bus(spi);
err_claim_bus:
return NULL;
}

View file

@ -150,15 +150,10 @@ static int
sst_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf)
{
size_t actual, cmd_len;
int ret;
int ret = 0;
u8 cmd[4];
flash->spi->rw = SPI_WRITE_FLAG;
ret = spi_claim_bus(flash->spi);
if (ret) {
printk(BIOS_WARNING, "SF: Unable to claim SPI bus\n");
return ret;
}
/* If the data is not word aligned, write out leading single byte */
actual = offset % 2;
@ -213,7 +208,6 @@ done:
printk(BIOS_SPEW, "SF: SST: program %s %zu bytes @ 0x%lx\n",
ret ? "failure" : "success", len, (unsigned long)offset - actual);
#endif
spi_release_bus(flash->spi);
return ret;
}

View file

@ -141,7 +141,7 @@ static int stmicro_write(struct spi_flash *flash,
unsigned long page_size;
size_t chunk_len;
size_t actual;
int ret;
int ret = 0;
u8 cmd[4];
page_size = stm->params->page_size;
@ -149,13 +149,7 @@ static int stmicro_write(struct spi_flash *flash,
byte_addr = offset % page_size;
flash->spi->rw = SPI_WRITE_FLAG;
ret = spi_claim_bus(flash->spi);
if (ret) {
printk(BIOS_WARNING, "SF: Unable to claim SPI bus\n");
return ret;
}
ret = 0;
for (actual = 0; actual < len; actual += chunk_len) {
chunk_len = min(len - actual, page_size - byte_addr);
@ -196,7 +190,6 @@ static int stmicro_write(struct spi_flash *flash,
len, offset);
#endif
spi_release_bus(flash->spi);
return ret;
}

View file

@ -127,18 +127,13 @@ static int winbond_write(struct spi_flash *flash,
unsigned long page_size;
size_t chunk_len;
size_t actual;
int ret;
int ret = 0;
u8 cmd[4];
page_size = min(1 << stm->params->l2_page_size, CONTROLLER_PAGE_LIMIT);
byte_addr = offset % page_size;
flash->spi->rw = SPI_WRITE_FLAG;
ret = spi_claim_bus(flash->spi);
if (ret) {
printk(BIOS_WARNING, "SF: Unable to claim SPI bus\n");
return ret;
}
for (actual = 0; actual < len; actual += chunk_len) {
chunk_len = min(len - actual, page_size - byte_addr);
@ -181,7 +176,6 @@ static int winbond_write(struct spi_flash *flash,
ret = 0;
out:
spi_release_bus(flash->spi);
return ret;
}