drivers/spi: Re-factor spi_crop_chunk
spi_crop_chunk is a property of the SPI controller since it depends
upon the maximum transfer size that is supported by the
controller. Also, it is possible to implement this within spi-generic
layer by obtaining following parameters from the controller:
1. max_xfer_size: Maximum transfer size supported by the controller
(Size of 0 indicates invalid size, and unlimited transfer size is
indicated by UINT32_MAX.)
2. deduct_cmd_len: Whether cmd_len needs to be deducted from the
max_xfer_size to determine max data size that can be
transferred. (This is used by the amd boards.)
Change-Id: I81c199413f879c664682088e93bfa3f91c6a46e5
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://review.coreboot.org/19386
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Tested-by: coreboot org <coreboot.org@gmail.com>
diff --git a/src/drivers/spi/adesto.c b/src/drivers/spi/adesto.c
index d286bd6..1091d9a 100644
--- a/src/drivers/spi/adesto.c
+++ b/src/drivers/spi/adesto.c
@@ -97,7 +97,7 @@
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 42f7cfa..2ee5d69 100644
--- a/src/drivers/spi/amic.c
+++ b/src/drivers/spi/amic.c
@@ -79,7 +79,7 @@
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 39cc95e..4fe679d 100644
--- a/src/drivers/spi/atmel.c
+++ b/src/drivers/spi/atmel.c
@@ -125,7 +125,7 @@
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 eb71c62..9c1665d 100644
--- a/src/drivers/spi/eon.c
+++ b/src/drivers/spi/eon.c
@@ -95,7 +95,7 @@
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 ed3d8bf..cbc9744 100644
--- a/src/drivers/spi/gigadevice.c
+++ b/src/drivers/spi/gigadevice.c
@@ -136,7 +136,7 @@
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 6d143ef..07d1e56 100644
--- a/src/drivers/spi/macronix.c
+++ b/src/drivers/spi/macronix.c
@@ -164,7 +164,7 @@
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 7f57d21..139e823 100644
--- a/src/drivers/spi/spansion.c
+++ b/src/drivers/spi/spansion.c
@@ -217,7 +217,7 @@
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 805e17a..579ceb1 100644
--- a/src/drivers/spi/spi-generic.c
+++ b/src/drivers/spi/spi-generic.c
@@ -88,6 +88,25 @@
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 41846b7..ef99024 100644
--- a/src/drivers/spi/spiconsole.c
+++ b/src/drivers/spi/spiconsole.c
@@ -46,7 +46,7 @@
};
/* 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 @@
/* 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 e571454..c9762ac 100644
--- a/src/drivers/spi/sst.c
+++ b/src/drivers/spi/sst.c
@@ -194,7 +194,7 @@
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 79782e4..06004f1 100644
--- a/src/drivers/spi/stmicro.c
+++ b/src/drivers/spi/stmicro.c
@@ -193,7 +193,7 @@
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 d071b9f..25a7b5b 100644
--- a/src/drivers/spi/winbond.c
+++ b/src/drivers/spi/winbond.c
@@ -155,7 +155,7 @@
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 7d957a0..56353bb 100644
--- a/src/include/spi-generic.h
+++ b/src/include/spi-generic.h
@@ -87,14 +87,27 @@
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.
+ * 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
+ *
*/
struct spi_ctrlr {
int (*claim_bus)(const struct spi_slave *slave);
@@ -104,6 +117,8 @@
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_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 f03d453..fde21ba 100644
--- a/src/soc/broadcom/cygnus/spi.c
+++ b/src/soc/broadcom/cygnus/spi.c
@@ -280,6 +280,7 @@
.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 @@
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 2b706f0..30e14fa 100644
--- a/src/soc/imgtec/pistachio/spi.c
+++ b/src/soc/imgtec/pistachio/spi.c
@@ -538,6 +538,7 @@
.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 @@
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 639954b..36b542f 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 @@
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 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 5121be0..12bf7d5 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 @@
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 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 aaf3b85..40969bc 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 @@
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 @@
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 27a4bb7..d56b33f 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 @@
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 51e8ef5..8e527ed 100644
--- a/src/soc/intel/common/block/gspi/gspi.c
+++ b/src/soc/intel/common/block/gspi/gspi.c
@@ -611,4 +611,5 @@
.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 409e796..236ff74 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 @@
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 @@
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 a6b6f35..01cb281 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 @@
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 @@
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 25480e4..47631f4 100644
--- a/src/soc/marvell/armada38x/spi.c
+++ b/src/soc/marvell/armada38x/spi.c
@@ -454,11 +454,6 @@
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 @@
.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 f9faf95..188a6bd 100644
--- a/src/soc/marvell/bg4cd/spi.c
+++ b/src/soc/marvell/bg4cd/spi.c
@@ -19,8 +19,3 @@
{
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 f6f6e2a..09df1a4 100644
--- a/src/soc/mediatek/mt8173/flash_controller.c
+++ b/src/soc/mediatek/mt8173/flash_controller.c
@@ -108,11 +108,6 @@
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 415764a..188bdc28 100644
--- a/src/soc/mediatek/mt8173/spi.c
+++ b/src/soc/mediatek/mt8173/spi.c
@@ -294,6 +294,7 @@
.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 5d8084f..4ecd67a 100644
--- a/src/soc/nvidia/tegra124/spi.c
+++ b/src/soc/nvidia/tegra124/spi.c
@@ -714,11 +714,6 @@
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 @@
.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 2921355..0987ddb 100644
--- a/src/soc/nvidia/tegra210/spi.c
+++ b/src/soc/nvidia/tegra210/spi.c
@@ -750,11 +750,6 @@
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 @@
.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 68c2dd0..b5c1f66 100644
--- a/src/soc/qualcomm/ipq40xx/spi.c
+++ b/src/soc/qualcomm/ipq40xx/spi.c
@@ -410,11 +410,6 @@
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 @@
.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 e907729..9a34f7a 100644
--- a/src/soc/qualcomm/ipq806x/spi.c
+++ b/src/soc/qualcomm/ipq806x/spi.c
@@ -683,11 +683,6 @@
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 @@
.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 16143b5..0e73769 100644
--- a/src/soc/rockchip/common/spi.c
+++ b/src/soc/rockchip/common/spi.c
@@ -251,11 +251,6 @@
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 @@
.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 f17566e..c2a5828 100644
--- a/src/soc/samsung/exynos5420/spi.c
+++ b/src/soc/samsung/exynos5420/spi.c
@@ -212,6 +212,7 @@
.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 00f6b29..1afe3e0 100644
--- a/src/southbridge/amd/agesa/hudson/spi.c
+++ b/src/southbridge/amd/agesa/hudson/spi.c
@@ -85,11 +85,6 @@
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 @@
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 1e84743..a664925 100644
--- a/src/southbridge/amd/cimx/sb800/spi.c
+++ b/src/southbridge/amd/cimx/sb800/spi.c
@@ -54,11 +54,6 @@
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 @@
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 5d56415..9731896 100644
--- a/src/southbridge/amd/sb700/spi.c
+++ b/src/southbridge/amd/sb700/spi.c
@@ -40,11 +40,6 @@
/* 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 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 ee94937..11318f7 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 @@
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 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 0bffeb5..ee60f75 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 @@
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 @@
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)