20e7bac6514c4c1fe6963023e52ac8ef312344d2
[openwrt/staging/svanheule.git] /
1 From c9cae7e1e5c87d0aa76b7bededa5191a0c8cf25a Mon Sep 17 00:00:00 2001
2 From: Miquel Raynal <miquel.raynal@bootlin.com>
3 Date: Thu, 27 Jan 2022 10:17:57 +0100
4 Subject: [PATCH 05/15] spi: spi-mem: Check the controller extra capabilities
5
6 Controllers can now provide a spi-mem capabilities structure. Let's make
7 use of it in spi_mem_controller_default_supports_op(). As we want to
8 check for DTR operations as well as normal operations in a single
9 helper, let's pull the necessary checks from spi_mem_dtr_supports_op()
10 for now.
11
12 However, because no controller provide these extra capabilities, this
13 change has no effect so far.
14
15 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
16 Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
17 Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
18 Reviewed-by: Tudor Ambarus <tudor.ambarus@microchip.com>
19 Link: https://lore.kernel.org/linux-mtd/20220127091808.1043392-3-miquel.raynal@bootlin.com
20 (cherry picked from commit cb7e96ee81edaa48c67d84c14df2cbe464391c37)
21 ---
22 drivers/spi/spi-mem.c | 17 +++++++++++++----
23 1 file changed, 13 insertions(+), 4 deletions(-)
24
25 diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
26 index 37f4443ce9a0..86e6597bc3dc 100644
27 --- a/drivers/spi/spi-mem.c
28 +++ b/drivers/spi/spi-mem.c
29 @@ -173,11 +173,20 @@ EXPORT_SYMBOL_GPL(spi_mem_dtr_supports_op);
30 bool spi_mem_default_supports_op(struct spi_mem *mem,
31 const struct spi_mem_op *op)
32 {
33 - if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
34 - return false;
35 + struct spi_controller *ctlr = mem->spi->controller;
36 + bool op_is_dtr =
37 + op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr;
38
39 - if (op->cmd.nbytes != 1)
40 - return false;
41 + if (op_is_dtr) {
42 + if (!spi_mem_controller_is_capable(ctlr, dtr))
43 + return false;
44 +
45 + if (op->cmd.nbytes != 2)
46 + return false;
47 + } else {
48 + if (op->cmd.nbytes != 1)
49 + return false;
50 + }
51
52 return spi_mem_check_buswidth(mem, op);
53 }
54 --
55 2.35.1
56