aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/spi/spi_flash.c
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2019-06-06 17:03:44 -0700
committerJulius Werner <jwerner@chromium.org>2019-06-10 18:02:33 +0000
commit99e45ceb35ff9a4c48e516e6d005ebfae54b6591 (patch)
tree8f42f859485f2dd4a0c101e613fd607b3000f219 /src/drivers/spi/spi_flash.c
parent1b7f99bd6b52e3fd03653dca80af3faf6e7e8852 (diff)
spi_flash: Add Dual SPI support
This patch adds support to read SPI flash in Dual SPI mode, where both MISO and MOSI lines are used for output mode (specifically Fast Read Dual Output (0x3b) where the command is still sent normally, not Fast Read Dual I/O (0xbb) whose additional benefit should be extremely marginal for our use cases but which would be more complicated to implement). This feature needs to be supported by both the flash chip and the controller, so we add a new dual_spi flag (and a new flags field to hold it) to the spi_flash structure and a new optional xfer_dual() function pointer to the spi_ctrlr structure. When both are provided, Dual SPI mode is used automatically, otherwise things work as before. This patch only adds the dual_spi flag exemplary to all Winbond and Gigadevice chips, other vendors need to be added as needed. Change-Id: Ic6808224c99af32b6c5c43054135c8f4c03c1feb Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/33283 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'src/drivers/spi/spi_flash.c')
-rw-r--r--src/drivers/spi/spi_flash.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index 5e42a375f6..a81306e386 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -59,6 +59,34 @@ static int do_spi_flash_cmd(const struct spi_slave *spi, const void *dout,
return ret;
}
+static int do_dual_read_cmd(const struct spi_slave *spi, const void *dout,
+ size_t bytes_out, void *din, size_t bytes_in)
+{
+ int ret;
+
+ /*
+ * spi_xfer_vector() will automatically fall back to .xfer() if
+ * .xfer_vector() is unimplemented. So using vector API here is more
+ * flexible, even though a controller that implements .xfer_vector()
+ * and (the non-vector based) .xfer_dual() but not .xfer() would be
+ * pretty odd.
+ */
+ struct spi_op vector = { .dout = dout, .bytesout = bytes_out,
+ .din = NULL, .bytesin = 0 };
+
+ ret = spi_claim_bus(spi);
+ if (ret)
+ return ret;
+
+ ret = spi_xfer_vector(spi, &vector, 1);
+
+ if (!ret)
+ ret = spi->ctrlr->xfer_dual(spi, NULL, 0, din, bytes_in);
+
+ spi_release_bus(spi);
+ return ret;
+}
+
int spi_flash_cmd(const struct spi_slave *spi, u8 cmd, void *response, size_t len)
{
int ret = do_spi_flash_cmd(spi, &cmd, sizeof(cmd), response, len);
@@ -105,6 +133,11 @@ static int spi_flash_read_chunked(const struct spi_flash *flash, u32 offset,
cmd_len = 4;
cmd[0] = CMD_READ_ARRAY_SLOW;
do_cmd = do_spi_flash_cmd;
+ } else if (flash->flags.dual_spi && flash->spi.ctrlr->xfer_dual) {
+ cmd_len = 5;
+ cmd[0] = CMD_READ_FAST_DUAL_OUTPUT;
+ cmd[4] = 0;
+ do_cmd = do_dual_read_cmd;
} else {
cmd_len = 5;
cmd[0] = CMD_READ_ARRAY_FAST;
@@ -347,8 +380,12 @@ int spi_flash_probe(unsigned int bus, unsigned int cs, struct spi_flash *flash)
return -1;
}
- printk(BIOS_INFO, "SF: Detected %s with sector size 0x%x, total 0x%x\n",
- flash->name, flash->sector_size, flash->size);
+ const char *mode_string = "";
+ if (flash->flags.dual_spi && spi.ctrlr->xfer_dual)
+ mode_string = " (Dual SPI mode)";
+ printk(BIOS_INFO,
+ "SF: Detected %s with sector size 0x%x, total 0x%x%s\n",
+ flash->name, flash->sector_size, flash->size, mode_string);
if (bus == CONFIG_BOOT_DEVICE_SPI_FLASH_BUS
&& flash->size != CONFIG_ROM_SIZE) {
printk(BIOS_ERR, "SF size 0x%x does not correspond to"