summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2020-01-11 11:44:47 -0700
committerAaron Durbin <adurbin@chromium.org>2020-01-16 15:20:49 +0000
commitcb01aa586f45277043d36500d9694d750ed33190 (patch)
treef7dcf8fad5f2f747131fdb66ba734336e84f5ad2 /src/drivers
parent56258ff92bcd0e930c62b6ae47567ed9b3b7efaf (diff)
drivers/spi/spi_flash: assume spi_flash read callback exists
spi_flash_erase() and spi_flash_write() already assume their respective callbacks are supplied in the spi_flash_ops object. Make the same assumption in spi_flash_read(). In order to do this the spi_flash_ops objects from the drivers need to reference the the previously used fallback read command, spi_flash_read_chunked(). This function is made global and renamed to spi_flash_cmd_read() for consistency. By doing this further dead code elimination can be achieved when the spi flash drivers aren't included in the build. A Hatch Chrome OS build achieves a further text segment reduction of 0.5KiB in verstage, romstage, and ramstage. Change-Id: I7fee55e6ffc1983657c3adde025a0e8c9d12ca23 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/38366 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/spi/adesto.c1
-rw-r--r--src/drivers/spi/amic.c1
-rw-r--r--src/drivers/spi/atmel.c1
-rw-r--r--src/drivers/spi/eon.c1
-rw-r--r--src/drivers/spi/gigadevice.c1
-rw-r--r--src/drivers/spi/macronix.c1
-rw-r--r--src/drivers/spi/spansion.c1
-rw-r--r--src/drivers/spi/spi_flash.c7
-rw-r--r--src/drivers/spi/spi_flash_internal.h3
-rw-r--r--src/drivers/spi/sst.c2
-rw-r--r--src/drivers/spi/stmicro.c1
-rw-r--r--src/drivers/spi/winbond.c1
12 files changed, 16 insertions, 5 deletions
diff --git a/src/drivers/spi/adesto.c b/src/drivers/spi/adesto.c
index 5f467417fd..1339ed2f27 100644
--- a/src/drivers/spi/adesto.c
+++ b/src/drivers/spi/adesto.c
@@ -149,6 +149,7 @@ static const struct adesto_spi_flash_params adesto_spi_flash_table[] = {
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
};
diff --git a/src/drivers/spi/amic.c b/src/drivers/spi/amic.c
index 54c03c05ac..fdaf1ba569 100644
--- a/src/drivers/spi/amic.c
+++ b/src/drivers/spi/amic.c
@@ -120,6 +120,7 @@ static const struct amic_spi_flash_params amic_spi_flash_table[] = {
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
};
diff --git a/src/drivers/spi/atmel.c b/src/drivers/spi/atmel.c
index 5e22eb68c1..64bc9f86f3 100644
--- a/src/drivers/spi/atmel.c
+++ b/src/drivers/spi/atmel.c
@@ -104,6 +104,7 @@ static const struct atmel_spi_flash_params atmel_spi_flash_table[] = {
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
};
diff --git a/src/drivers/spi/eon.c b/src/drivers/spi/eon.c
index 1f3cbf3c78..b2c7ddcff1 100644
--- a/src/drivers/spi/eon.c
+++ b/src/drivers/spi/eon.c
@@ -236,6 +236,7 @@ static const struct eon_spi_flash_params eon_spi_flash_table[] = {
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/gigadevice.c b/src/drivers/spi/gigadevice.c
index 1f478a867a..b78b83048e 100644
--- a/src/drivers/spi/gigadevice.c
+++ b/src/drivers/spi/gigadevice.c
@@ -165,6 +165,7 @@ static const struct gigadevice_spi_flash_params gigadevice_spi_flash_table[] = {
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/macronix.c b/src/drivers/spi/macronix.c
index adf4f23737..334404dee9 100644
--- a/src/drivers/spi/macronix.c
+++ b/src/drivers/spi/macronix.c
@@ -201,6 +201,7 @@ static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/spansion.c b/src/drivers/spi/spansion.c
index 01911a0696..3d2f39d6df 100644
--- a/src/drivers/spi/spansion.c
+++ b/src/drivers/spi/spansion.c
@@ -219,6 +219,7 @@ static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index 4a86146503..8f3a829e15 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -127,7 +127,7 @@ int spi_flash_cmd_write(const struct spi_slave *spi, const u8 *cmd,
/* Perform the read operation honoring spi controller fifo size, reissuing
* the read command until the full request completed. */
-static int spi_flash_read_chunked(const struct spi_flash *flash, u32 offset,
+int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset,
size_t len, void *buf)
{
u8 cmd[5];
@@ -465,10 +465,7 @@ int spi_flash_probe(unsigned int bus, unsigned int cs, struct spi_flash *flash)
int spi_flash_read(const struct spi_flash *flash, u32 offset, size_t len,
void *buf)
{
- if (flash->ops->read)
- return flash->ops->read(flash, offset, len, buf);
-
- return spi_flash_read_chunked(flash, offset, len, buf);
+ return flash->ops->read(flash, offset, len, buf);
}
int spi_flash_write(const struct spi_flash *flash, u32 offset, size_t len,
diff --git a/src/drivers/spi/spi_flash_internal.h b/src/drivers/spi/spi_flash_internal.h
index 58172ce929..ef756c78d7 100644
--- a/src/drivers/spi/spi_flash_internal.h
+++ b/src/drivers/spi/spi_flash_internal.h
@@ -66,6 +66,9 @@ int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg);
int spi_flash_cmd_write_page_program(const struct spi_flash *flash, u32 offset,
size_t len, const void *buf);
+/* Read len bytes into buf at offset. */
+int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, size_t len, void *buf);
+
/* Manufacturer-specific probe functions */
int spi_flash_probe_spansion(const struct spi_slave *spi, u8 *idcode,
struct spi_flash *flash);
diff --git a/src/drivers/spi/sst.c b/src/drivers/spi/sst.c
index bcc47700d9..1fb64467a0 100644
--- a/src/drivers/spi/sst.c
+++ b/src/drivers/spi/sst.c
@@ -55,12 +55,14 @@ static int sst_write_ai(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf);
static const struct spi_flash_ops spi_flash_ops_write_ai = {
+ .read = spi_flash_cmd_read,
.write = sst_write_ai,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
};
static const struct spi_flash_ops spi_flash_ops_write_256 = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
diff --git a/src/drivers/spi/stmicro.c b/src/drivers/spi/stmicro.c
index 83d0749311..3f1a78c514 100644
--- a/src/drivers/spi/stmicro.c
+++ b/src/drivers/spi/stmicro.c
@@ -285,6 +285,7 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
};
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
};
diff --git a/src/drivers/spi/winbond.c b/src/drivers/spi/winbond.c
index b6735c0be7..68cf1a3860 100644
--- a/src/drivers/spi/winbond.c
+++ b/src/drivers/spi/winbond.c
@@ -611,6 +611,7 @@ winbond_set_write_protection(const struct spi_flash *flash,
}
static const struct spi_flash_ops spi_flash_ops = {
+ .read = spi_flash_cmd_read,
.write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,