[PATCH v8 03/14] spi: spi-mem: Check the controller extra capabilities

Miquel Raynal miquel.raynal at bootlin.com
Tue Dec 21 09:48:33 PST 2021


Controllers can now provide a spi-mem capabilities structure. Let's make
use of it in spi_mem_controller_default_supports_op(). As we want to
check for DTR operations as well as normal operations in a single
helper, let's pull the necessary checks from spi_mem_dtr_supports_op()
for now.

However, because no controller provide these extra capabilities, this
change has no effect so far.

Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
---
 drivers/spi/spi-mem.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 1dfd38d82607..83651cbc87f2 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -183,11 +183,32 @@ EXPORT_SYMBOL_GPL(spi_mem_dtr_supports_op);
 bool spi_mem_default_supports_op(struct spi_mem *mem,
 				 const struct spi_mem_op *op)
 {
-	if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
-		return false;
+	struct spi_controller *ctlr = mem->spi->controller;
+	bool op_is_dtr =
+		op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr;
 
-	if (op->cmd.nbytes != 1)
-		return false;
+	if (op_is_dtr) {
+		if (!spi_mem_controller_is_capable(ctlr, dtr))
+			return false;
+
+		if (op->cmd.buswidth == 8 && op->cmd.nbytes % 2)
+			return false;
+
+		if (op->addr.nbytes && op->addr.buswidth == 8 &&
+		    op->addr.nbytes % 2)
+			return false;
+
+		if (op->dummy.nbytes && op->dummy.buswidth == 8 &&
+		    op->dummy.nbytes % 2)
+			return false;
+
+		if (op->data.dir != SPI_MEM_NO_DATA &&
+		    op->dummy.buswidth == 8 && op->data.nbytes % 2)
+			return false;
+	} else {
+		if (op->cmd.nbytes != 1)
+			return false;
+	}
 
 	return spi_mem_check_buswidth(mem, op);
 }
-- 
2.27.0




More information about the linux-mtd mailing list