summaryrefslogtreecommitdiff
path: root/src/drivers/spi/spi_flash.c
diff options
context:
space:
mode:
authorDavid Hendricks <dhendrix@chromium.org>2014-04-11 19:48:55 -0700
committerMarc Jones <marc.jones@se-eng.com>2014-12-17 04:51:28 +0100
commit032c84381751bab0fe1da2e963af41cbe52c303d (patch)
treed41094b25b849379980b81cbb526fce23620501c /src/drivers/spi/spi_flash.c
parentf101bbe4f07b154cb58212a2913112e6ffbce4d0 (diff)
downloadcoreboot-032c84381751bab0fe1da2e963af41cbe52c303d.tar.xz
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> Original-Change-Id: I3257e2f6a2820834f4c9018069f90fcf2bab05f6 Original-Reviewed-on: https://chromium-review.googlesource.com/194510 Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Original-Commit-Queue: David Hendricks <dhendrix@chromium.org> Original-Tested-by: David Hendricks <dhendrix@chromium.org> (cherry picked from commit d3394d34fb49e9e252f67371674d5b3aa220bc9e) Signed-off-by: Marc Jones <marc.jones@se-eng.com> Change-Id: Ieb62309b18090d8f974f91a6e448af3d65dd3d1d Reviewed-on: http://review.coreboot.org/7829 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'src/drivers/spi/spi_flash.c')
-rw-r--r--src/drivers/spi/spi_flash.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index 0d67c43385..d737ee9e61 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -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;
}
@@ -188,11 +190,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;
@@ -222,7 +219,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;
}
@@ -307,11 +303,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;
- }
if (spi->force_programmer_specific && spi->programmer_specific_probe) {
flash = spi->programmer_specific_probe (spi);
@@ -375,13 +366,9 @@ flash_detected:
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;
}