[coreboot-gerrit] Change in coreboot[master]: drivers/spi: Re-factor spi_crop_chunk
Furquan Shaikh (Code Review)
gerrit at coreboot.org
Thu Apr 20 04:40:27 CEST 2017
Furquan Shaikh has uploaded a new change for review. ( https://review.coreboot.org/19386 )
Change subject: drivers/spi: Re-factor spi_crop_chunk
......................................................................
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 any transfer size is fine)
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 at chromium.org>
---
M src/drivers/spi/adesto.c
M src/drivers/spi/amic.c
M src/drivers/spi/atmel.c
M src/drivers/spi/eon.c
M src/drivers/spi/gigadevice.c
M src/drivers/spi/macronix.c
M src/drivers/spi/spansion.c
M src/drivers/spi/spi-generic.c
M src/drivers/spi/spiconsole.c
M src/drivers/spi/sst.c
M src/drivers/spi/stmicro.c
M src/drivers/spi/winbond.c
M src/include/spi-generic.h
M src/soc/broadcom/cygnus/spi.c
M src/soc/imgtec/pistachio/spi.c
M src/soc/intel/apollolake/flash_ctrlr.c
M src/soc/intel/apollolake/spi.c
M src/soc/intel/baytrail/spi.c
M src/soc/intel/braswell/spi.c
M src/soc/intel/broadwell/spi.c
M src/soc/intel/fsp_baytrail/spi.c
M src/soc/intel/fsp_broadwell_de/spi.c
M src/soc/intel/skylake/flash_controller.c
M src/soc/intel/skylake/spi.c
M src/soc/marvell/armada38x/spi.c
M src/soc/marvell/bg4cd/spi.c
M src/soc/mediatek/mt8173/flash_controller.c
M src/soc/mediatek/mt8173/spi.c
M src/soc/nvidia/tegra124/spi.c
M src/soc/nvidia/tegra210/spi.c
M src/soc/qualcomm/ipq40xx/spi.c
M src/soc/qualcomm/ipq806x/spi.c
M src/soc/rockchip/common/spi.c
M src/southbridge/amd/agesa/hudson/spi.c
M src/southbridge/amd/cimx/sb800/spi.c
M src/southbridge/amd/sb700/spi.c
M src/southbridge/intel/common/spi.c
M src/southbridge/intel/fsp_rangeley/spi.c
38 files changed, 77 insertions(+), 128 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/86/19386/1
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..7c69c6f 100644
--- a/src/drivers/spi/spi-generic.c
+++ b/src/drivers/spi/spi-generic.c
@@ -88,6 +88,26 @@
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;
+
+ if (!ctrlr_max)
+ return buf_len;
+
+ 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..1acfcc7 100644
--- a/src/include/spi-generic.h
+++ b/src/include/spi-generic.h
@@ -90,11 +90,16 @@
/*-----------------------------------------------------------------------
* Representation of a SPI contoller.
*
- * 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 = No limit)
+ * 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 +109,8 @@
size_t bytesout, void *din, size_t bytesin);
int (*xfer_vector)(const struct spi_slave *slave,
struct spi_op vectors[], size_t count);
+ unsigned int max_xfer_size;
+ bool deduct_cmd_len;
};
/*-----------------------------------------------------------------------
@@ -212,7 +219,9 @@
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);
+
+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)
@@ -317,9 +318,4 @@
(priv->spi_mode & 3)); /* mode: CPOL / CPHA */
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. */
@@ -584,9 +585,4 @@
img_slave->initialised = IMG_FALSE;
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/apollolake/flash_ctrlr.c b/src/soc/intel/apollolake/flash_ctrlr.c
index 95f540c..f18ebfe 100644
--- a/src/soc/intel/apollolake/flash_ctrlr.c
+++ b/src/soc/intel/apollolake/flash_ctrlr.c
@@ -183,11 +183,6 @@
return ret;
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return MIN(buf_len, SPIBAR_FDATA_FIFO_SIZE);
-}
-
/*
* Write-protection status for BIOS region (BIOS_CONTROL register):
* EISS/WPD bits 00 01 10 11
diff --git a/src/soc/intel/apollolake/spi.c b/src/soc/intel/apollolake/spi.c
index 87d4d01..78b8096 100644
--- a/src/soc/intel/apollolake/spi.c
+++ b/src/soc/intel/apollolake/spi.c
@@ -15,6 +15,7 @@
*/
#include <console/console.h>
+#include <soc/flash_ctrlr.h>
#include <spi-generic.h>
/* SPI controller managing the fast SPI. */
@@ -33,6 +34,7 @@
static const struct spi_ctrlr fast_spi_ctrlr = {
.setup = fast_spi_ctrlr_setup,
+ .max_xfer_size = SPIBAR_FDATA_FIFO_SIZE,
};
const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
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..119c9a5 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/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/intel/skylake/flash_controller.c b/src/soc/intel/skylake/flash_controller.c
index ac6758e..782783e 100644
--- a/src/soc/intel/skylake/flash_controller.c
+++ b/src/soc/intel/skylake/flash_controller.c
@@ -122,11 +122,6 @@
return wait_for_completion(regs, timeout_ms, size);
}
-unsigned int spi_crop_chunk(unsigned int cmd_len, unsigned int buf_len)
-{
- return min(SPI_FDATA_BYTES, buf_len);
-}
-
static size_t spi_get_flash_size(pch_spi_flash_regs *spi_bar)
{
uint32_t flcomp;
diff --git a/src/soc/intel/skylake/spi.c b/src/soc/intel/skylake/spi.c
index e11e13f..ec5debc 100644
--- a/src/soc/intel/skylake/spi.c
+++ b/src/soc/intel/skylake/spi.c
@@ -21,6 +21,7 @@
#include <device/pci_ids.h>
#include <device/spi.h>
#include <intelblocks/gspi.h>
+#include <soc/flash_controller.h>
#include <soc/ramstage.h>
#include <spi-generic.h>
@@ -38,6 +39,7 @@
static const struct spi_ctrlr flash_spi_ctrlr = {
.setup = flash_spi_ctrlr_setup,
+ .max_xfer_size = SPI_FDATA_BYTES,
};
const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
diff --git a/src/soc/marvell/armada38x/spi.c b/src/soc/marvell/armada38x/spi.c
index 25480e4..bb18471 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,
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..188bdc2 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..2b4e075 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)
{
diff --git a/src/soc/nvidia/tegra210/spi.c b/src/soc/nvidia/tegra210/spi.c
index 2921355..fc54627 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)
{
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/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)
--
To view, visit https://review.coreboot.org/19386
To unsubscribe, visit https://review.coreboot.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I81c199413f879c664682088e93bfa3f91c6a46e5
Gerrit-PatchSet: 1
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Owner: Furquan Shaikh <furquan at google.com>
More information about the coreboot-gerrit
mailing list