From de705fa1f470683b9ea4ad91c1a9ae5a98942612 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Wed, 19 Apr 2017 19:27:28 -0700 Subject: 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 Reviewed-on: https://review.coreboot.org/19386 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) Tested-by: coreboot org --- src/drivers/spi/spi-generic.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/drivers/spi/spi-generic.c') 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. */ -- cgit v1.2.3