summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/drivers/spi/adesto.c2
-rw-r--r--src/drivers/spi/amic.c2
-rw-r--r--src/drivers/spi/atmel.c2
-rw-r--r--src/drivers/spi/eon.c2
-rw-r--r--src/drivers/spi/gigadevice.c2
-rw-r--r--src/drivers/spi/macronix.c2
-rw-r--r--src/drivers/spi/spansion.c2
-rw-r--r--src/drivers/spi/spi-generic.c19
-rw-r--r--src/drivers/spi/spiconsole.c4
-rw-r--r--src/drivers/spi/sst.c2
-rw-r--r--src/drivers/spi/stmicro.c2
-rw-r--r--src/drivers/spi/winbond.c2
-rw-r--r--src/include/spi-generic.h36
-rw-r--r--src/soc/broadcom/cygnus/spi.c6
-rw-r--r--src/soc/imgtec/pistachio/spi.c6
-rw-r--r--src/soc/intel/baytrail/spi.c7
-rw-r--r--src/soc/intel/braswell/spi.c7
-rw-r--r--src/soc/intel/broadwell/spi.c7
-rw-r--r--src/soc/intel/common/block/fast_spi/fast_spi_flash.c1
-rw-r--r--src/soc/intel/common/block/gspi/gspi.c1
-rw-r--r--src/soc/intel/fsp_baytrail/spi.c7
-rw-r--r--src/soc/intel/fsp_broadwell_de/spi.c7
-rw-r--r--src/soc/marvell/armada38x/spi.c6
-rw-r--r--src/soc/marvell/bg4cd/spi.c5
-rw-r--r--src/soc/mediatek/mt8173/flash_controller.c5
-rw-r--r--src/soc/mediatek/mt8173/spi.c1
-rw-r--r--src/soc/nvidia/tegra124/spi.c6
-rw-r--r--src/soc/nvidia/tegra210/spi.c6
-rw-r--r--src/soc/qualcomm/ipq40xx/spi.c6
-rw-r--r--src/soc/qualcomm/ipq806x/spi.c6
-rw-r--r--src/soc/rockchip/common/spi.c6
-rw-r--r--src/soc/samsung/exynos5420/spi.c1
-rw-r--r--src/southbridge/amd/agesa/hudson/spi.c7
-rw-r--r--src/southbridge/amd/cimx/sb800/spi.c7
-rw-r--r--src/southbridge/amd/sb700/spi.c7
-rw-r--r--src/southbridge/intel/common/spi.c7
-rw-r--r--src/southbridge/intel/fsp_rangeley/spi.c7
37 files changed, 92 insertions, 119 deletions
diff --git a/src/drivers/spi/adesto.c b/src/drivers/spi/adesto.c
index d286bd66f6..1091d9a4b1 100644
--- a/src/drivers/spi/adesto.c
+++ b/src/drivers/spi/adesto.c
@@ -97,7 +97,7 @@ static int adesto_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_AT25DF_PP;
cmd[1] = (offset >> 16) & 0xff;
diff --git a/src/drivers/spi/amic.c b/src/drivers/spi/amic.c
index 42f7cfa120..2ee5d69790 100644
--- a/src/drivers/spi/amic.c
+++ b/src/drivers/spi/amic.c
@@ -79,7 +79,7 @@ static int amic_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) {
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_A25_PP;
cmd[1] = (offset >> 16) & 0xff;
diff --git a/src/drivers/spi/atmel.c b/src/drivers/spi/atmel.c
index 39cc95e609..4fe679d036 100644
--- a/src/drivers/spi/atmel.c
+++ b/src/drivers/spi/atmel.c
@@ -125,7 +125,7 @@ static int atmel_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_AT25_PP;
cmd[1] = (offset >> 16) & 0xff;
diff --git a/src/drivers/spi/eon.c b/src/drivers/spi/eon.c
index eb71c6216e..9c1665d480 100644
--- a/src/drivers/spi/eon.c
+++ b/src/drivers/spi/eon.c
@@ -95,7 +95,7 @@ static int eon_write(const struct spi_flash *flash,
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
ret = spi_flash_cmd(&flash->spi, CMD_EN25_WREN, NULL, 0);
if (ret < 0) {
diff --git a/src/drivers/spi/gigadevice.c b/src/drivers/spi/gigadevice.c
index ed3d8bf074..cbc9744614 100644
--- a/src/drivers/spi/gigadevice.c
+++ b/src/drivers/spi/gigadevice.c
@@ -136,7 +136,7 @@ static int gigadevice_write(const struct spi_flash *flash, u32 offset,
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
ret = spi_flash_cmd(&flash->spi, CMD_GD25_WREN, NULL, 0);
if (ret < 0) {
diff --git a/src/drivers/spi/macronix.c b/src/drivers/spi/macronix.c
index 6d143efe2d..07d1e5624d 100644
--- a/src/drivers/spi/macronix.c
+++ b/src/drivers/spi/macronix.c
@@ -164,7 +164,7 @@ static int macronix_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_MX25XX_PP;
cmd[1] = (offset >> 16) & 0xff;
diff --git a/src/drivers/spi/spansion.c b/src/drivers/spi/spansion.c
index 7f57d21e14..139e8239a0 100644
--- a/src/drivers/spi/spansion.c
+++ b/src/drivers/spi/spansion.c
@@ -217,7 +217,7 @@ static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_S25FLXX_PP;
cmd[1] = (offset >> 16) & 0xff;
diff --git a/src/drivers/spi/spi-generic.c b/src/drivers/spi/spi-generic.c
index 805e17af5a..579ceb1df7 100644
--- a/src/drivers/spi/spi-generic.c
+++ b/src/drivers/spi/spi-generic.c
@@ -88,6 +88,25 @@ int spi_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout,
return -1;
}
+unsigned int spi_crop_chunk(const struct spi_slave *slave, unsigned int cmd_len,
+ unsigned int buf_len)
+{
+ const struct spi_ctrlr *ctrlr = slave->ctrlr;
+ unsigned int ctrlr_max;
+
+ if (!ctrlr)
+ return 0;
+
+ ctrlr_max = ctrlr->max_xfer_size;
+
+ assert (ctrlr_max != 0);
+
+ if (ctrlr->deduct_cmd_len && (ctrlr_max > cmd_len))
+ ctrlr_max -= cmd_len;
+
+ return min(ctrlr_max, buf_len);
+}
+
void __attribute__((weak)) spi_init(void)
{
/* Default weak implementation - do nothing. */
diff --git a/src/drivers/spi/spiconsole.c b/src/drivers/spi/spiconsole.c
index 41846b7e6a..ef9902475e 100644
--- a/src/drivers/spi/spiconsole.c
+++ b/src/drivers/spi/spiconsole.c
@@ -46,7 +46,7 @@ void spiconsole_tx_byte(unsigned char c) {
};
/* Verify the spi buffer is big enough to send even a single byte */
- if (spi_crop_chunk(0,MAX_MSG_LENGTH) <
+ if (spi_crop_chunk(&slave, 0, MAX_MSG_LENGTH) <
sizeof(struct em100_msg_header) + 1)
return;
@@ -55,7 +55,7 @@ void spiconsole_tx_byte(unsigned char c) {
/* Send the data on newline or when the max spi length is reached */
if (c == '\n' || (sizeof(struct em100_msg_header) +
- msg.header.msg_length == spi_crop_chunk(0,
+ msg.header.msg_length == spi_crop_chunk(&slave, 0,
MAX_MSG_LENGTH))) {
spi_xfer(&slave, &msg, sizeof(struct em100_msg_header) +
msg.header.msg_length, NULL, 0);
diff --git a/src/drivers/spi/sst.c b/src/drivers/spi/sst.c
index e5714540ff..c9762accf5 100644
--- a/src/drivers/spi/sst.c
+++ b/src/drivers/spi/sst.c
@@ -194,7 +194,7 @@ static int sst_write_256(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_SST_BP;
cmd[1] = (offset >> 16) & 0xff;
diff --git a/src/drivers/spi/stmicro.c b/src/drivers/spi/stmicro.c
index 79782e4808..06004f19b2 100644
--- a/src/drivers/spi/stmicro.c
+++ b/src/drivers/spi/stmicro.c
@@ -193,7 +193,7 @@ static int stmicro_write(const struct spi_flash *flash,
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_M25PXX_PP;
cmd[1] = (offset >> 16) & 0xff;
diff --git a/src/drivers/spi/winbond.c b/src/drivers/spi/winbond.c
index d071b9f28d..25a7b5bd32 100644
--- a/src/drivers/spi/winbond.c
+++ b/src/drivers/spi/winbond.c
@@ -155,7 +155,7 @@ static int winbond_write(const struct spi_flash *flash, u32 offset, size_t len,
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
+ chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
cmd[0] = CMD_W25_PP;
cmd[1] = (offset >> 16) & 0xff;
diff --git a/src/include/spi-generic.h b/src/include/spi-generic.h
index 7d957a0d9c..56353bb692 100644
--- a/src/include/spi-generic.h
+++ b/src/include/spi-generic.h
@@ -87,14 +87,27 @@ struct spi_cfg {
unsigned int data_bit_length;
};
+/*
+ * If there is no limit on the maximum transfer size for the controller,
+ * max_xfer_size can be set to SPI_CTRLR_DEFAULT_MAX_XFER_SIZE which is equal to
+ * UINT32_MAX.
+ */
+#define SPI_CTRLR_DEFAULT_MAX_XFER_SIZE (UINT32_MAX)
+
/*-----------------------------------------------------------------------
- * Representation of a SPI contoller.
+ * Representation of a SPI controller.
+ *
+ * claim_bus: Claim SPI bus and prepare for communication.
+ * release_bus: Release SPI bus.
+ * setup: Setup given SPI device bus.
+ * xfer: Perform one SPI transfer operation.
+ * xfer_vector: Vector of SPI transfer operations.
+ * max_xfer_size: Maximum transfer size supported by the controller
+ * (0 = invalid,
+ * SPI_CTRLR_DEFAULT_MAX_XFER_SIZE = unlimited)
+ * deduct_cmd_len: Whether cmd_len should be deducted from max_xfer_size
+ * when calculating max_data_size
*
- * claim_bus: Claim SPI bus and prepare for communication.
- * release_bus: Release SPI bus.
- * setup: Setup given SPI device bus.
- * xfer: Perform one SPI transfer operation.
- * xfer_vector: Vector of SPI transfer operations.
*/
struct spi_ctrlr {
int (*claim_bus)(const struct spi_slave *slave);
@@ -104,6 +117,8 @@ struct spi_ctrlr {
size_t bytesout, void *din, size_t bytesin);
int (*xfer_vector)(const struct spi_slave *slave,
struct spi_op vectors[], size_t count);
+ uint32_t max_xfer_size;
+ bool deduct_cmd_len;
};
/*-----------------------------------------------------------------------
@@ -212,7 +227,14 @@ int spi_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout,
int spi_xfer_vector(const struct spi_slave *slave,
struct spi_op vectors[], size_t count);
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len);
+/*-----------------------------------------------------------------------
+ * Given command length and length of remaining data, return the maximum data
+ * that can be transferred in next spi_xfer.
+ *
+ * Returns: 0 on error, non-zero data size that can be xfered on success.
+ */
+unsigned int spi_crop_chunk(const struct spi_slave *slave, unsigned int cmd_len,
+ unsigned int buf_len);
/*-----------------------------------------------------------------------
* Write 8 bits, then read 8 bits.
diff --git a/src/soc/broadcom/cygnus/spi.c b/src/soc/broadcom/cygnus/spi.c
index f03d453307..fde21ba202 100644
--- a/src/soc/broadcom/cygnus/spi.c
+++ b/src/soc/broadcom/cygnus/spi.c
@@ -280,6 +280,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = 65535,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
@@ -318,8 +319,3 @@ int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
return 0;
}
-
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(65535, buf_len);
-}
diff --git a/src/soc/imgtec/pistachio/spi.c b/src/soc/imgtec/pistachio/spi.c
index 2b706f0980..30e14fab10 100644
--- a/src/soc/imgtec/pistachio/spi.c
+++ b/src/soc/imgtec/pistachio/spi.c
@@ -538,6 +538,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = IMGTEC_SPI_MAX_TRANSFER_SIZE,
};
/* Set up communications parameters for a SPI slave. */
@@ -585,8 +586,3 @@ int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
return 0;
}
-
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(IMGTEC_SPI_MAX_TRANSFER_SIZE, buf_len);
-}
diff --git a/src/soc/intel/baytrail/spi.c b/src/soc/intel/baytrail/spi.c
index 639954bcfe..36b542f181 100644
--- a/src/soc/intel/baytrail/spi.c
+++ b/src/soc/intel/baytrail/spi.c
@@ -19,6 +19,7 @@
#include <bootstate.h>
#include <delay.h>
#include <arch/io.h>
+#include <commonlib/helpers.h>
#include <console/console.h>
#include <device/pci_ids.h>
#include <spi_flash.h>
@@ -457,11 +458,6 @@ static int ich_status_poll(u16 bitmask, int wait_til_set)
return -1;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(cntlr.databytes, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin)
{
@@ -613,6 +609,7 @@ static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = member_size(ich9_spi_regs, fdata),
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/intel/braswell/spi.c b/src/soc/intel/braswell/spi.c
index 5121be016b..12bf7d5c80 100644
--- a/src/soc/intel/braswell/spi.c
+++ b/src/soc/intel/braswell/spi.c
@@ -16,6 +16,7 @@
/* This file is derived from the flashrom project. */
#include <arch/io.h>
#include <bootstate.h>
+#include <commonlib/helpers.h>
#include <console/console.h>
#include <delay.h>
#include <device/pci_ids.h>
@@ -438,11 +439,6 @@ static int ich_status_poll(u16 bitmask, int wait_til_set)
return -1;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(cntlr.databytes, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin)
{
@@ -597,6 +593,7 @@ static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = member_size(ich9_spi_regs, fdata),
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/intel/broadwell/spi.c b/src/soc/intel/broadwell/spi.c
index aaf3b85b5a..40969bc404 100644
--- a/src/soc/intel/broadwell/spi.c
+++ b/src/soc/intel/broadwell/spi.c
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include <string.h>
#include <bootstate.h>
+#include <commonlib/helpers.h>
#include <delay.h>
#include <arch/io.h>
#include <console/console.h>
@@ -454,11 +455,6 @@ static int ich_status_poll(u16 bitmask, int wait_til_set)
return -1;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(cntlr.databytes, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin)
{
@@ -654,6 +650,7 @@ int spi_flash_protect(u32 start, u32 size)
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = member_size(ich9_spi_regs, fdata),
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/intel/common/block/fast_spi/fast_spi_flash.c b/src/soc/intel/common/block/fast_spi/fast_spi_flash.c
index 27a4bb7886..d56b33fa15 100644
--- a/src/soc/intel/common/block/fast_spi/fast_spi_flash.c
+++ b/src/soc/intel/common/block/fast_spi/fast_spi_flash.c
@@ -364,4 +364,5 @@ static int fast_spi_flash_ctrlr_setup(const struct spi_slave *dev)
const struct spi_ctrlr fast_spi_flash_ctrlr = {
.setup = fast_spi_flash_ctrlr_setup,
+ .max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
};
diff --git a/src/soc/intel/common/block/gspi/gspi.c b/src/soc/intel/common/block/gspi/gspi.c
index 51e8ef54e1..8e527ed0b1 100644
--- a/src/soc/intel/common/block/gspi/gspi.c
+++ b/src/soc/intel/common/block/gspi/gspi.c
@@ -611,4 +611,5 @@ const struct spi_ctrlr gspi_ctrlr = {
.release_bus = gspi_cs_deassert,
.setup = gspi_ctrlr_setup,
.xfer = gspi_ctrlr_xfer,
+ .max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
};
diff --git a/src/soc/intel/fsp_baytrail/spi.c b/src/soc/intel/fsp_baytrail/spi.c
index 409e796daf..236ff741fc 100644
--- a/src/soc/intel/fsp_baytrail/spi.c
+++ b/src/soc/intel/fsp_baytrail/spi.c
@@ -18,6 +18,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <commonlib/helpers.h>
#include <delay.h>
#include <arch/io.h>
#include <console/console.h>
@@ -438,11 +439,6 @@ static int ich_status_poll(uint16_t bitmask, int wait_til_set)
return -1;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(cntlr.databytes, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin)
{
@@ -594,6 +590,7 @@ spi_xfer_exit:
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = member_size(ich9_spi_regs, fdata),
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/intel/fsp_broadwell_de/spi.c b/src/soc/intel/fsp_broadwell_de/spi.c
index a6b6f3541a..01cb281fe0 100644
--- a/src/soc/intel/fsp_broadwell_de/spi.c
+++ b/src/soc/intel/fsp_broadwell_de/spi.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include <delay.h>
+#include <commonlib/helpers.h>
#include <arch/io.h>
#include <console/console.h>
#include <device/pci_ids.h>
@@ -452,11 +453,6 @@ static int ich_status_poll(uint16_t bitmask, int wait_til_set)
return -1;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(cntlr.databytes, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin)
{
@@ -610,6 +606,7 @@ spi_xfer_exit:
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = member_size(ich9_spi_regs, fdata),
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/marvell/armada38x/spi.c b/src/soc/marvell/armada38x/spi.c
index 25480e49ff..47631f4c69 100644
--- a/src/soc/marvell/armada38x/spi.c
+++ b/src/soc/marvell/armada38x/spi.c
@@ -454,11 +454,6 @@ static void spi_ctrlr_release_bus(const struct spi_slave *slave)
mv_spi_cs_deassert(slave->bus);
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return buf_len;
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave,
const void *dout,
size_t out_bytes,
@@ -480,6 +475,7 @@ static const spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
+ .max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/marvell/bg4cd/spi.c b/src/soc/marvell/bg4cd/spi.c
index f9faf9504a..188a6bd483 100644
--- a/src/soc/marvell/bg4cd/spi.c
+++ b/src/soc/marvell/bg4cd/spi.c
@@ -19,8 +19,3 @@ int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
{
return -1;
}
-
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return buf_len;
-}
diff --git a/src/soc/mediatek/mt8173/flash_controller.c b/src/soc/mediatek/mt8173/flash_controller.c
index f6f6e2a6c7..09df1a47f7 100644
--- a/src/soc/mediatek/mt8173/flash_controller.c
+++ b/src/soc/mediatek/mt8173/flash_controller.c
@@ -108,11 +108,6 @@ static int sector_erase(int offset)
return 0;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(65535, buf_len);
-}
-
static int dma_read(u32 addr, u8 *buf, u32 len, uintptr_t dma_buf,
size_t dma_buf_len)
{
diff --git a/src/soc/mediatek/mt8173/spi.c b/src/soc/mediatek/mt8173/spi.c
index 415764a1b6..188bdc2881 100644
--- a/src/soc/mediatek/mt8173/spi.c
+++ b/src/soc/mediatek/mt8173/spi.c
@@ -294,6 +294,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = 65535,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/nvidia/tegra124/spi.c b/src/soc/nvidia/tegra124/spi.c
index 5d8084fbdf..4ecd67a8a4 100644
--- a/src/soc/nvidia/tegra124/spi.c
+++ b/src/soc/nvidia/tegra124/spi.c
@@ -714,11 +714,6 @@ static int xfer_finish(struct tegra_spi_channel *spi)
return ret;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return buf_len;
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t out_bytes, void *din, size_t in_bytes)
{
@@ -802,6 +797,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
+ .max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/nvidia/tegra210/spi.c b/src/soc/nvidia/tegra210/spi.c
index 292135542a..0987ddb53a 100644
--- a/src/soc/nvidia/tegra210/spi.c
+++ b/src/soc/nvidia/tegra210/spi.c
@@ -750,11 +750,6 @@ static int xfer_finish(struct tegra_spi_channel *spi)
return ret;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return buf_len;
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t out_bytes, void *din, size_t in_bytes)
{
@@ -838,6 +833,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
+ .max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/qualcomm/ipq40xx/spi.c b/src/soc/qualcomm/ipq40xx/spi.c
index 68c2dd0b72..b5c1f6699a 100644
--- a/src/soc/qualcomm/ipq40xx/spi.c
+++ b/src/soc/qualcomm/ipq40xx/spi.c
@@ -410,11 +410,6 @@ static void enable_io_config(struct ipq_spi_slave *ds,
return;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(MAX_PACKET_COUNT, buf_len);
-}
-
/*
* Function to read bytes number of data from the Input FIFO
*/
@@ -657,6 +652,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = MAX_PACKET_COUNT,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/qualcomm/ipq806x/spi.c b/src/soc/qualcomm/ipq806x/spi.c
index e907729a13..9a34f7a948 100644
--- a/src/soc/qualcomm/ipq806x/spi.c
+++ b/src/soc/qualcomm/ipq806x/spi.c
@@ -683,11 +683,6 @@ static int spi_xfer_rx_packet(struct ipq_spi_slave *ds,
return config_spi_state(ds, SPI_RESET_STATE);
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(MAX_PACKET_COUNT, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t out_bytes, void *din, size_t in_bytes)
{
@@ -761,6 +756,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
+ .max_xfer_size = MAX_PACKET_COUNT,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/rockchip/common/spi.c b/src/soc/rockchip/common/spi.c
index 16143b5ac8..0e7376945b 100644
--- a/src/soc/rockchip/common/spi.c
+++ b/src/soc/rockchip/common/spi.c
@@ -251,11 +251,6 @@ static int do_xfer(struct rockchip_spi *regs, bool use_16bit, const void *dout,
return 0;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(65535, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytes_out, void *din, size_t bytes_in)
{
@@ -332,6 +327,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
+ .max_xfer_size = 65535,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/soc/samsung/exynos5420/spi.c b/src/soc/samsung/exynos5420/spi.c
index f17566e2c5..c2a5828f14 100644
--- a/src/soc/samsung/exynos5420/spi.c
+++ b/src/soc/samsung/exynos5420/spi.c
@@ -212,6 +212,7 @@ static const struct spi_ctrlr spi_ctrlr = {
.claim_bus = spi_ctrlr_claim_bus,
.release_bus = spi_ctrlr_release_bus,
.xfer = spi_ctrlr_xfer,
+ .max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/southbridge/amd/agesa/hudson/spi.c b/src/southbridge/amd/agesa/hudson/spi.c
index 00f6b29303..1afe3e0ded 100644
--- a/src/southbridge/amd/agesa/hudson/spi.c
+++ b/src/southbridge/amd/agesa/hudson/spi.c
@@ -85,11 +85,6 @@ void spi_init(void)
spibar = pci_read_config32(dev, 0xA0) & ~0x1F;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(AMD_SB_SPI_TX_LEN - cmd_len, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin)
{
@@ -168,6 +163,8 @@ int chipset_volatile_group_end(const struct spi_flash *flash)
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = AMD_SB_SPI_TX_LEN,
+ .deduct_cmd_len = true,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/southbridge/amd/cimx/sb800/spi.c b/src/southbridge/amd/cimx/sb800/spi.c
index 1e847439f9..a6649251d1 100644
--- a/src/southbridge/amd/cimx/sb800/spi.c
+++ b/src/southbridge/amd/cimx/sb800/spi.c
@@ -54,11 +54,6 @@ void spi_init()
spibar = pci_read_config32(dev, 0xA0) & ~0x1F;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(AMD_SB_SPI_TX_LEN - cmd_len, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin)
{
@@ -159,6 +154,8 @@ int chipset_volatile_group_end(const struct spi_flash *flash)
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = AMD_SB_SPI_TX_LEN,
+ .deduct_cmd_len = true,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/southbridge/amd/sb700/spi.c b/src/southbridge/amd/sb700/spi.c
index 5d56415b44..9731896803 100644
--- a/src/southbridge/amd/sb700/spi.c
+++ b/src/southbridge/amd/sb700/spi.c
@@ -40,11 +40,6 @@ void spi_init(void)
/* Not needed */
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(AMD_SB_SPI_TX_LEN - cmd_len, buf_len);
-}
-
static void reset_internal_fifo_pointer(void)
{
uint32_t spibar = get_spi_bar();
@@ -121,6 +116,8 @@ static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = AMD_SB_SPI_TX_LEN,
+ .deduct_cmd_len = true,
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/southbridge/intel/common/spi.c b/src/southbridge/intel/common/spi.c
index ee94937291..11318f7ec0 100644
--- a/src/southbridge/intel/common/spi.c
+++ b/src/southbridge/intel/common/spi.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include <bootstate.h>
+#include <commonlib/helpers.h>
#include <delay.h>
#include <arch/io.h>
#include <console/console.h>
@@ -504,11 +505,6 @@ static int spi_is_multichip (void)
return !!((cntlr.flmap0 >> 8) & 3);
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(cntlr.databytes, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin)
{
@@ -660,6 +656,7 @@ static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = member_size(ich9_spi_regs, fdata),
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/southbridge/intel/fsp_rangeley/spi.c b/src/southbridge/intel/fsp_rangeley/spi.c
index 0bffeb5293..ee60f7516c 100644
--- a/src/southbridge/intel/fsp_rangeley/spi.c
+++ b/src/southbridge/intel/fsp_rangeley/spi.c
@@ -17,6 +17,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <commonlib/helpers.h>
#include <delay.h>
#include <arch/io.h>
#include <console/console.h>
@@ -569,11 +570,6 @@ static int ich_status_poll(u16 bitmask, int wait_til_set)
return -1;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(cntlr.databytes, buf_len);
-}
-
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
size_t bytesout, void *din, size_t bytesin)
{
@@ -725,6 +721,7 @@ spi_xfer_exit:
static const struct spi_ctrlr spi_ctrlr = {
.xfer = spi_ctrlr_xfer,
.xfer_vector = spi_xfer_two_vectors,
+ .max_xfer_size = member_size(ich10_spi_regs, fdata),
};
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)