[U-Boot] [PATCH v4 04/20] spi: spi-mem: Extend spi_mem_adjust_op_size() to honor max xfer size

Vignesh R vigneshr at ti.com
Tue Feb 5 05:59:13 UTC 2019


Extend spi_mem_adjust_op_size() to take spi->max_write_size and
spi->max_read_size into account.

Signed-off-by: Vignesh R <vigneshr at ti.com>
Tested-by: Simon Goldschmidt <simon.k.r.goldschmidt at gmail.com>
Tested-by: Stefan Roese <sr at denx.de>
Tested-by: Horatiu Vultur <horatiu.vultur at microchip.com>
Reviewed-by: Jagan Teki <jagan at openedev.com>
Tested-by: Jagan Teki <jagan at amarulasolutions.com> #zynq-microzed
---
 drivers/spi/spi-mem.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 1da20b8de5c4..334af682dc65 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -412,6 +412,25 @@ int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op)
 	if (ops->mem_ops && ops->mem_ops->adjust_op_size)
 		return ops->mem_ops->adjust_op_size(slave, op);
 
+	if (!ops->mem_ops || !ops->mem_ops->exec_op) {
+		unsigned int len;
+
+		len = sizeof(op->cmd.opcode) + op->addr.nbytes +
+			op->dummy.nbytes;
+		if (slave->max_write_size && len > slave->max_write_size)
+			return -EINVAL;
+
+		if (op->data.dir == SPI_MEM_DATA_IN && slave->max_read_size)
+			op->data.nbytes = min(op->data.nbytes,
+					      slave->max_read_size);
+		else if (slave->max_write_size)
+			op->data.nbytes = min(op->data.nbytes,
+					      slave->max_write_size - len);
+
+		if (!op->data.nbytes)
+			return -EINVAL;
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size);
-- 
2.20.1



More information about the U-Boot mailing list