mediatek: v5.15: backport spi-mem ecc support
[openwrt/staging/mkresin.git] / target / linux / mediatek / patches-5.15 / 120-04-v5.18-spi-spi-mem-Introduce-a-capability-structure.patch
1 From 3e45577e70cbf8fdc5c13033114989794a3797d5 Mon Sep 17 00:00:00 2001
2 From: Miquel Raynal <miquel.raynal@bootlin.com>
3 Date: Thu, 27 Jan 2022 10:17:56 +0100
4 Subject: [PATCH 04/15] spi: spi-mem: Introduce a capability structure
5
6 Create a spi_controller_mem_caps structure and put it within the
7 spi_controller structure close to the spi_controller_mem_ops
8 strucure. So far the only field in this structure is the support for dtr
9 operations, but soon we will add another parameter.
10
11 Also create a helper to parse the capabilities and check if the
12 requested capability has been set or not.
13
14 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
15 Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
16 Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
17 Reviewed-by: Tudor Ambarus <tudor.ambarus@microchip.com>
18 Reviewed-by: Mark Brown <broonie@kernel.org>
19 Link: https://lore.kernel.org/linux-mtd/20220127091808.1043392-2-miquel.raynal@bootlin.com
20 (cherry picked from commit 4a3cc7fb6e63bcfdedec25364738f1493345bd20)
21 ---
22 include/linux/spi/spi-mem.h | 11 +++++++++++
23 include/linux/spi/spi.h | 3 +++
24 2 files changed, 14 insertions(+)
25
26 diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h
27 index 85e2ff7b840d..38e5d45c9842 100644
28 --- a/include/linux/spi/spi-mem.h
29 +++ b/include/linux/spi/spi-mem.h
30 @@ -285,6 +285,17 @@ struct spi_controller_mem_ops {
31 unsigned long timeout_ms);
32 };
33
34 +/**
35 + * struct spi_controller_mem_caps - SPI memory controller capabilities
36 + * @dtr: Supports DTR operations
37 + */
38 +struct spi_controller_mem_caps {
39 + bool dtr;
40 +};
41 +
42 +#define spi_mem_controller_is_capable(ctlr, cap) \
43 + ((ctlr)->mem_caps && (ctlr)->mem_caps->cap)
44 +
45 /**
46 * struct spi_mem_driver - SPI memory driver
47 * @spidrv: inherit from a SPI driver
48 diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
49 index 6b0b686f6f90..8ac58b1a2a9f 100644
50 --- a/include/linux/spi/spi.h
51 +++ b/include/linux/spi/spi.h
52 @@ -23,6 +23,7 @@ struct software_node;
53 struct spi_controller;
54 struct spi_transfer;
55 struct spi_controller_mem_ops;
56 +struct spi_controller_mem_caps;
57
58 /*
59 * INTERFACES between SPI master-side drivers and SPI slave protocol handlers,
60 @@ -419,6 +420,7 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch
61 * @mem_ops: optimized/dedicated operations for interactions with SPI memory.
62 * This field is optional and should only be implemented if the
63 * controller has native support for memory like operations.
64 + * @mem_caps: controller capabilities for the handling of memory operations.
65 * @unprepare_message: undo any work done by prepare_message().
66 * @slave_abort: abort the ongoing transfer request on an SPI slave controller
67 * @cs_gpios: LEGACY: array of GPIO descs to use as chip select lines; one per
68 @@ -643,6 +645,7 @@ struct spi_controller {
69
70 /* Optimized handlers for SPI memory-like operations. */
71 const struct spi_controller_mem_ops *mem_ops;
72 + const struct spi_controller_mem_caps *mem_caps;
73
74 /* gpio chip select */
75 int *cs_gpios;
76 --
77 2.35.1
78