9f01fdb83532ae6993c9c0d54c921d76c6fedd29
[openwrt/staging/blogic.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 --- a/drivers/spi/spi-mem.c
26 +++ b/drivers/spi/spi-mem.c
27 @@ -173,11 +173,20 @@ EXPORT_SYMBOL_GPL(spi_mem_dtr_supports_o
28 bool spi_mem_default_supports_op(struct spi_mem *mem,
29 const struct spi_mem_op *op)
30 {
31 - if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
32 - return false;
33 + struct spi_controller *ctlr = mem->spi->controller;
34 + bool op_is_dtr =
35 + op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr;
36
37 - if (op->cmd.nbytes != 1)
38 - return false;
39 + if (op_is_dtr) {
40 + if (!spi_mem_controller_is_capable(ctlr, dtr))
41 + return false;
42 +
43 + if (op->cmd.nbytes != 2)
44 + return false;
45 + } else {
46 + if (op->cmd.nbytes != 1)
47 + return false;
48 + }
49
50 return spi_mem_check_buswidth(mem, op);
51 }