From 1fcc9f3125f88595a89392e9736ebb01e7788842 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Mon, 29 Jan 2018 11:30:17 -0700 Subject: drivers/spi: support cmd opcode deduction for spi_crop_chunk() spi_crop_chunk() currently supports deducting the command length when determining maximum payload size in a transaction. Add support for deducting just the opcode part of the command by replacing deduct_cmd_len field to generic flags field. The two enums supported drive the logic within spi_crop_chunk(): SPI_CNTRLR_DEDUCT_CMD_LEN SPI_CNTRLR_DEDUCT_OPCODE_LEN All existing users of deduct_cmd_len were converted to using the flags field. BUG=b:65485690 Change-Id: I771fba684f0ed76ffdc8573aa10f775070edc691 Signed-off-by: Aaron Durbin Reviewed-on: https://review.coreboot.org/23491 Reviewed-by: Furquan Shaikh Reviewed-by: Justin TerAvest Tested-by: build bot (Jenkins) --- src/drivers/spi/spi-generic.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/drivers') diff --git a/src/drivers/spi/spi-generic.c b/src/drivers/spi/spi-generic.c index 31a6bc3155..1fcc05d4f3 100644 --- a/src/drivers/spi/spi-generic.c +++ b/src/drivers/spi/spi-generic.c @@ -93,15 +93,24 @@ unsigned int spi_crop_chunk(const struct spi_slave *slave, unsigned int cmd_len, { const struct spi_ctrlr *ctrlr = slave->ctrlr; unsigned int ctrlr_max; + bool deduct_cmd_len; + bool deduct_opcode_len; if (!ctrlr) return 0; + deduct_cmd_len = !!(ctrlr->flags & SPI_CNTRLR_DEDUCT_CMD_LEN); + deduct_opcode_len = !!(ctrlr->flags & SPI_CNTRLR_DEDUCT_OPCODE_LEN); ctrlr_max = ctrlr->max_xfer_size; assert (ctrlr_max != 0); - if (ctrlr->deduct_cmd_len && (ctrlr_max > cmd_len)) + /* Assume opcode is always one byte and deduct it from the cmd_len + as the hardware has a separate register for the opcode. */ + if (deduct_opcode_len) + cmd_len--; + + if (deduct_cmd_len && (ctrlr_max > cmd_len)) ctrlr_max -= cmd_len; return min(ctrlr_max, buf_len); -- cgit v1.2.3