xref: /linux/include/linux/spi/spi-mem.h (revision a433c2cbd75ab76f277364f44e76f32c7df306e7)
1c36ff266SBoris Brezillon /* SPDX-License-Identifier: GPL-2.0+ */
2c36ff266SBoris Brezillon /*
3c36ff266SBoris Brezillon  * Copyright (C) 2018 Exceet Electronics GmbH
4c36ff266SBoris Brezillon  * Copyright (C) 2018 Bootlin
5c36ff266SBoris Brezillon  *
67529df46SPeter Pan  * Author:
77529df46SPeter Pan  *	Peter Pan <peterpandong@micron.com>
87529df46SPeter Pan  *	Boris Brezillon <boris.brezillon@bootlin.com>
9c36ff266SBoris Brezillon  */
10c36ff266SBoris Brezillon 
11c36ff266SBoris Brezillon #ifndef __LINUX_SPI_MEM_H
12c36ff266SBoris Brezillon #define __LINUX_SPI_MEM_H
13c36ff266SBoris Brezillon 
14c36ff266SBoris Brezillon #include <linux/spi/spi.h>
15c36ff266SBoris Brezillon 
16c36ff266SBoris Brezillon #define SPI_MEM_OP_CMD(__opcode, __buswidth)			\
17c36ff266SBoris Brezillon 	{							\
18c36ff266SBoris Brezillon 		.buswidth = __buswidth,				\
19c36ff266SBoris Brezillon 		.opcode = __opcode,				\
20caf72df4SPratyush Yadav 		.nbytes = 1,					\
21c36ff266SBoris Brezillon 	}
22c36ff266SBoris Brezillon 
23c36ff266SBoris Brezillon #define SPI_MEM_OP_ADDR(__nbytes, __val, __buswidth)		\
24c36ff266SBoris Brezillon 	{							\
25c36ff266SBoris Brezillon 		.nbytes = __nbytes,				\
26c36ff266SBoris Brezillon 		.val = __val,					\
27c36ff266SBoris Brezillon 		.buswidth = __buswidth,				\
28c36ff266SBoris Brezillon 	}
29c36ff266SBoris Brezillon 
30c36ff266SBoris Brezillon #define SPI_MEM_OP_NO_ADDR	{ }
31c36ff266SBoris Brezillon 
32c36ff266SBoris Brezillon #define SPI_MEM_OP_DUMMY(__nbytes, __buswidth)			\
33c36ff266SBoris Brezillon 	{							\
34c36ff266SBoris Brezillon 		.nbytes = __nbytes,				\
35c36ff266SBoris Brezillon 		.buswidth = __buswidth,				\
36c36ff266SBoris Brezillon 	}
37c36ff266SBoris Brezillon 
38c36ff266SBoris Brezillon #define SPI_MEM_OP_NO_DUMMY	{ }
39c36ff266SBoris Brezillon 
40c36ff266SBoris Brezillon #define SPI_MEM_OP_DATA_IN(__nbytes, __buf, __buswidth)		\
41c36ff266SBoris Brezillon 	{							\
42c36ff266SBoris Brezillon 		.dir = SPI_MEM_DATA_IN,				\
43c36ff266SBoris Brezillon 		.nbytes = __nbytes,				\
44c36ff266SBoris Brezillon 		.buf.in = __buf,				\
45c36ff266SBoris Brezillon 		.buswidth = __buswidth,				\
46c36ff266SBoris Brezillon 	}
47c36ff266SBoris Brezillon 
48c36ff266SBoris Brezillon #define SPI_MEM_OP_DATA_OUT(__nbytes, __buf, __buswidth)	\
49c36ff266SBoris Brezillon 	{							\
50c36ff266SBoris Brezillon 		.dir = SPI_MEM_DATA_OUT,			\
51c36ff266SBoris Brezillon 		.nbytes = __nbytes,				\
52c36ff266SBoris Brezillon 		.buf.out = __buf,				\
53c36ff266SBoris Brezillon 		.buswidth = __buswidth,				\
54c36ff266SBoris Brezillon 	}
55c36ff266SBoris Brezillon 
56c36ff266SBoris Brezillon #define SPI_MEM_OP_NO_DATA	{ }
57c36ff266SBoris Brezillon 
58c36ff266SBoris Brezillon /**
59c36ff266SBoris Brezillon  * enum spi_mem_data_dir - describes the direction of a SPI memory data
60c36ff266SBoris Brezillon  *			   transfer from the controller perspective
610ebb261aSBoris Brezillon  * @SPI_MEM_NO_DATA: no data transferred
62c36ff266SBoris Brezillon  * @SPI_MEM_DATA_IN: data coming from the SPI memory
636afe76a6SBoris Brezillon  * @SPI_MEM_DATA_OUT: data sent to the SPI memory
64c36ff266SBoris Brezillon  */
65c36ff266SBoris Brezillon enum spi_mem_data_dir {
660ebb261aSBoris Brezillon 	SPI_MEM_NO_DATA,
67c36ff266SBoris Brezillon 	SPI_MEM_DATA_IN,
68c36ff266SBoris Brezillon 	SPI_MEM_DATA_OUT,
69c36ff266SBoris Brezillon };
70c36ff266SBoris Brezillon 
71c36ff266SBoris Brezillon /**
72c36ff266SBoris Brezillon  * struct spi_mem_op - describes a SPI memory operation
73caf72df4SPratyush Yadav  * @cmd.nbytes: number of opcode bytes (only 1 or 2 are valid). The opcode is
74caf72df4SPratyush Yadav  *		sent MSB-first.
75c36ff266SBoris Brezillon  * @cmd.buswidth: number of IO lines used to transmit the command
76c36ff266SBoris Brezillon  * @cmd.opcode: operation opcode
774c5e2bbaSPratyush Yadav  * @cmd.dtr: whether the command opcode should be sent in DTR mode or not
78c36ff266SBoris Brezillon  * @addr.nbytes: number of address bytes to send. Can be zero if the operation
79c36ff266SBoris Brezillon  *		 does not need to send an address
80c36ff266SBoris Brezillon  * @addr.buswidth: number of IO lines used to transmit the address cycles
814c5e2bbaSPratyush Yadav  * @addr.dtr: whether the address should be sent in DTR mode or not
82c36ff266SBoris Brezillon  * @addr.val: address value. This value is always sent MSB first on the bus.
83c36ff266SBoris Brezillon  *	      Note that only @addr.nbytes are taken into account in this
84c36ff266SBoris Brezillon  *	      address value, so users should make sure the value fits in the
85c36ff266SBoris Brezillon  *	      assigned number of bytes.
86c36ff266SBoris Brezillon  * @dummy.nbytes: number of dummy bytes to send after an opcode or address. Can
87c36ff266SBoris Brezillon  *		  be zero if the operation does not require dummy bytes
88c36ff266SBoris Brezillon  * @dummy.buswidth: number of IO lanes used to transmit the dummy bytes
894c5e2bbaSPratyush Yadav  * @dummy.dtr: whether the dummy bytes should be sent in DTR mode or not
90c36ff266SBoris Brezillon  * @data.buswidth: number of IO lanes used to send/receive the data
914c5e2bbaSPratyush Yadav  * @data.dtr: whether the data should be sent in DTR mode or not
92*a433c2cbSMiquel Raynal  * @data.ecc: whether error correction is required or not
93c36ff266SBoris Brezillon  * @data.dir: direction of the transfer
9460489f08SBoris Brezillon  * @data.nbytes: number of data bytes to send/receive. Can be zero if the
9560489f08SBoris Brezillon  *		 operation does not involve transferring data
96c949a8e8SBoris Brezillon  * @data.buf.in: input buffer (must be DMA-able)
97c949a8e8SBoris Brezillon  * @data.buf.out: output buffer (must be DMA-able)
98c36ff266SBoris Brezillon  */
99c36ff266SBoris Brezillon struct spi_mem_op {
100c36ff266SBoris Brezillon 	struct {
101caf72df4SPratyush Yadav 		u8 nbytes;
102c36ff266SBoris Brezillon 		u8 buswidth;
1034c5e2bbaSPratyush Yadav 		u8 dtr : 1;
104caf72df4SPratyush Yadav 		u16 opcode;
105c36ff266SBoris Brezillon 	} cmd;
106c36ff266SBoris Brezillon 
107c36ff266SBoris Brezillon 	struct {
108c36ff266SBoris Brezillon 		u8 nbytes;
109c36ff266SBoris Brezillon 		u8 buswidth;
1104c5e2bbaSPratyush Yadav 		u8 dtr : 1;
111c36ff266SBoris Brezillon 		u64 val;
112c36ff266SBoris Brezillon 	} addr;
113c36ff266SBoris Brezillon 
114c36ff266SBoris Brezillon 	struct {
115c36ff266SBoris Brezillon 		u8 nbytes;
116c36ff266SBoris Brezillon 		u8 buswidth;
1174c5e2bbaSPratyush Yadav 		u8 dtr : 1;
118c36ff266SBoris Brezillon 	} dummy;
119c36ff266SBoris Brezillon 
120c36ff266SBoris Brezillon 	struct {
121c36ff266SBoris Brezillon 		u8 buswidth;
1224c5e2bbaSPratyush Yadav 		u8 dtr : 1;
123*a433c2cbSMiquel Raynal 		u8 ecc : 1;
124c36ff266SBoris Brezillon 		enum spi_mem_data_dir dir;
125c36ff266SBoris Brezillon 		unsigned int nbytes;
126c36ff266SBoris Brezillon 		union {
127c36ff266SBoris Brezillon 			void *in;
128c36ff266SBoris Brezillon 			const void *out;
129c36ff266SBoris Brezillon 		} buf;
130c36ff266SBoris Brezillon 	} data;
131c36ff266SBoris Brezillon };
132c36ff266SBoris Brezillon 
133c36ff266SBoris Brezillon #define SPI_MEM_OP(__cmd, __addr, __dummy, __data)		\
134c36ff266SBoris Brezillon 	{							\
135c36ff266SBoris Brezillon 		.cmd = __cmd,					\
136c36ff266SBoris Brezillon 		.addr = __addr,					\
137c36ff266SBoris Brezillon 		.dummy = __dummy,				\
138c36ff266SBoris Brezillon 		.data = __data,					\
139c36ff266SBoris Brezillon 	}
140c36ff266SBoris Brezillon 
141c36ff266SBoris Brezillon /**
142aa167f3fSBoris Brezillon  * struct spi_mem_dirmap_info - Direct mapping information
143aa167f3fSBoris Brezillon  * @op_tmpl: operation template that should be used by the direct mapping when
144aa167f3fSBoris Brezillon  *	     the memory device is accessed
145aa167f3fSBoris Brezillon  * @offset: absolute offset this direct mapping is pointing to
146aa167f3fSBoris Brezillon  * @length: length in byte of this direct mapping
147aa167f3fSBoris Brezillon  *
148aa167f3fSBoris Brezillon  * These information are used by the controller specific implementation to know
149aa167f3fSBoris Brezillon  * the portion of memory that is directly mapped and the spi_mem_op that should
150aa167f3fSBoris Brezillon  * be used to access the device.
151aa167f3fSBoris Brezillon  * A direct mapping is only valid for one direction (read or write) and this
152aa167f3fSBoris Brezillon  * direction is directly encoded in the ->op_tmpl.data.dir field.
153aa167f3fSBoris Brezillon  */
154aa167f3fSBoris Brezillon struct spi_mem_dirmap_info {
155aa167f3fSBoris Brezillon 	struct spi_mem_op op_tmpl;
156aa167f3fSBoris Brezillon 	u64 offset;
157aa167f3fSBoris Brezillon 	u64 length;
158aa167f3fSBoris Brezillon };
159aa167f3fSBoris Brezillon 
160aa167f3fSBoris Brezillon /**
161aa167f3fSBoris Brezillon  * struct spi_mem_dirmap_desc - Direct mapping descriptor
162aa167f3fSBoris Brezillon  * @mem: the SPI memory device this direct mapping is attached to
163aa167f3fSBoris Brezillon  * @info: information passed at direct mapping creation time
164aa167f3fSBoris Brezillon  * @nodirmap: set to 1 if the SPI controller does not implement
165aa167f3fSBoris Brezillon  *	      ->mem_ops->dirmap_create() or when this function returned an
166aa167f3fSBoris Brezillon  *	      error. If @nodirmap is true, all spi_mem_dirmap_{read,write}()
167aa167f3fSBoris Brezillon  *	      calls will use spi_mem_exec_op() to access the memory. This is a
168aa167f3fSBoris Brezillon  *	      degraded mode that allows spi_mem drivers to use the same code
169aa167f3fSBoris Brezillon  *	      no matter whether the controller supports direct mapping or not
170aa167f3fSBoris Brezillon  * @priv: field pointing to controller specific data
171aa167f3fSBoris Brezillon  *
172aa167f3fSBoris Brezillon  * Common part of a direct mapping descriptor. This object is created by
173aa167f3fSBoris Brezillon  * spi_mem_dirmap_create() and controller implementation of ->create_dirmap()
174aa167f3fSBoris Brezillon  * can create/attach direct mapping resources to the descriptor in the ->priv
175aa167f3fSBoris Brezillon  * field.
176aa167f3fSBoris Brezillon  */
177aa167f3fSBoris Brezillon struct spi_mem_dirmap_desc {
178aa167f3fSBoris Brezillon 	struct spi_mem *mem;
179aa167f3fSBoris Brezillon 	struct spi_mem_dirmap_info info;
180aa167f3fSBoris Brezillon 	unsigned int nodirmap;
181aa167f3fSBoris Brezillon 	void *priv;
182aa167f3fSBoris Brezillon };
183aa167f3fSBoris Brezillon 
184aa167f3fSBoris Brezillon /**
185c36ff266SBoris Brezillon  * struct spi_mem - describes a SPI memory device
186c36ff266SBoris Brezillon  * @spi: the underlying SPI device
18706bcb516SFrieder Schrempf  * @drvpriv: spi_mem_driver private data
1885d27a9c8SFrieder Schrempf  * @name: name of the SPI memory device
189c36ff266SBoris Brezillon  *
190c36ff266SBoris Brezillon  * Extra information that describe the SPI memory device and may be needed by
191c36ff266SBoris Brezillon  * the controller to properly handle this device should be placed here.
192c36ff266SBoris Brezillon  *
193c36ff266SBoris Brezillon  * One example would be the device size since some controller expose their SPI
194c36ff266SBoris Brezillon  * mem devices through a io-mapped region.
195c36ff266SBoris Brezillon  */
196c36ff266SBoris Brezillon struct spi_mem {
197c36ff266SBoris Brezillon 	struct spi_device *spi;
198c36ff266SBoris Brezillon 	void *drvpriv;
199401c0d77SBoris Brezillon 	const char *name;
200c36ff266SBoris Brezillon };
201c36ff266SBoris Brezillon 
202c36ff266SBoris Brezillon /**
203c36ff266SBoris Brezillon  * struct spi_mem_set_drvdata() - attach driver private data to a SPI mem
204c36ff266SBoris Brezillon  *				  device
205c36ff266SBoris Brezillon  * @mem: memory device
206c36ff266SBoris Brezillon  * @data: data to attach to the memory device
207c36ff266SBoris Brezillon  */
208c36ff266SBoris Brezillon static inline void spi_mem_set_drvdata(struct spi_mem *mem, void *data)
209c36ff266SBoris Brezillon {
210c36ff266SBoris Brezillon 	mem->drvpriv = data;
211c36ff266SBoris Brezillon }
212c36ff266SBoris Brezillon 
213c36ff266SBoris Brezillon /**
214c36ff266SBoris Brezillon  * struct spi_mem_get_drvdata() - get driver private data attached to a SPI mem
215c36ff266SBoris Brezillon  *				  device
216c36ff266SBoris Brezillon  * @mem: memory device
217c36ff266SBoris Brezillon  *
218c36ff266SBoris Brezillon  * Return: the data attached to the mem device.
219c36ff266SBoris Brezillon  */
220c36ff266SBoris Brezillon static inline void *spi_mem_get_drvdata(struct spi_mem *mem)
221c36ff266SBoris Brezillon {
222c36ff266SBoris Brezillon 	return mem->drvpriv;
223c36ff266SBoris Brezillon }
224c36ff266SBoris Brezillon 
225c36ff266SBoris Brezillon /**
226c36ff266SBoris Brezillon  * struct spi_controller_mem_ops - SPI memory operations
227c36ff266SBoris Brezillon  * @adjust_op_size: shrink the data xfer of an operation to match controller's
228c36ff266SBoris Brezillon  *		    limitations (can be alignment of max RX/TX size
229c36ff266SBoris Brezillon  *		    limitations)
230c36ff266SBoris Brezillon  * @supports_op: check if an operation is supported by the controller
231c36ff266SBoris Brezillon  * @exec_op: execute a SPI memory operation
2325d27a9c8SFrieder Schrempf  * @get_name: get a custom name for the SPI mem device from the controller.
2335d27a9c8SFrieder Schrempf  *	      This might be needed if the controller driver has been ported
2345d27a9c8SFrieder Schrempf  *	      to use the SPI mem layer and a custom name is used to keep
2355d27a9c8SFrieder Schrempf  *	      mtdparts compatible.
2365d27a9c8SFrieder Schrempf  *	      Note that if the implementation of this function allocates memory
2375d27a9c8SFrieder Schrempf  *	      dynamically, then it should do so with devm_xxx(), as we don't
2385d27a9c8SFrieder Schrempf  *	      have a ->free_name() function.
239aa167f3fSBoris Brezillon  * @dirmap_create: create a direct mapping descriptor that can later be used to
240aa167f3fSBoris Brezillon  *		   access the memory device. This method is optional
241aa167f3fSBoris Brezillon  * @dirmap_destroy: destroy a memory descriptor previous created by
242aa167f3fSBoris Brezillon  *		    ->dirmap_create()
243aa167f3fSBoris Brezillon  * @dirmap_read: read data from the memory device using the direct mapping
244aa167f3fSBoris Brezillon  *		 created by ->dirmap_create(). The function can return less
245aa167f3fSBoris Brezillon  *		 data than requested (for example when the request is crossing
246aa167f3fSBoris Brezillon  *		 the currently mapped area), and the caller of
247aa167f3fSBoris Brezillon  *		 spi_mem_dirmap_read() is responsible for calling it again in
248aa167f3fSBoris Brezillon  *		 this case.
249aa167f3fSBoris Brezillon  * @dirmap_write: write data to the memory device using the direct mapping
250aa167f3fSBoris Brezillon  *		  created by ->dirmap_create(). The function can return less
251aa167f3fSBoris Brezillon  *		  data than requested (for example when the request is crossing
252aa167f3fSBoris Brezillon  *		  the currently mapped area), and the caller of
253aa167f3fSBoris Brezillon  *		  spi_mem_dirmap_write() is responsible for calling it again in
254aa167f3fSBoris Brezillon  *		  this case.
255c955a0ccSPatrice Chotard  * @poll_status: poll memory device status until (status & mask) == match or
256c955a0ccSPatrice Chotard  *               when the timeout has expired. It fills the data buffer with
257c955a0ccSPatrice Chotard  *               the last status value.
258c36ff266SBoris Brezillon  *
259c36ff266SBoris Brezillon  * This interface should be implemented by SPI controllers providing an
260c36ff266SBoris Brezillon  * high-level interface to execute SPI memory operation, which is usually the
261c36ff266SBoris Brezillon  * case for QSPI controllers.
262aa167f3fSBoris Brezillon  *
263aa167f3fSBoris Brezillon  * Note on ->dirmap_{read,write}(): drivers should avoid accessing the direct
264aa167f3fSBoris Brezillon  * mapping from the CPU because doing that can stall the CPU waiting for the
265aa167f3fSBoris Brezillon  * SPI mem transaction to finish, and this will make real-time maintainers
266aa167f3fSBoris Brezillon  * unhappy and might make your system less reactive. Instead, drivers should
267aa167f3fSBoris Brezillon  * use DMA to access this direct mapping.
268c36ff266SBoris Brezillon  */
269c36ff266SBoris Brezillon struct spi_controller_mem_ops {
270c36ff266SBoris Brezillon 	int (*adjust_op_size)(struct spi_mem *mem, struct spi_mem_op *op);
271c36ff266SBoris Brezillon 	bool (*supports_op)(struct spi_mem *mem,
272c36ff266SBoris Brezillon 			    const struct spi_mem_op *op);
273c36ff266SBoris Brezillon 	int (*exec_op)(struct spi_mem *mem,
274c36ff266SBoris Brezillon 		       const struct spi_mem_op *op);
2755d27a9c8SFrieder Schrempf 	const char *(*get_name)(struct spi_mem *mem);
276aa167f3fSBoris Brezillon 	int (*dirmap_create)(struct spi_mem_dirmap_desc *desc);
277aa167f3fSBoris Brezillon 	void (*dirmap_destroy)(struct spi_mem_dirmap_desc *desc);
278aa167f3fSBoris Brezillon 	ssize_t (*dirmap_read)(struct spi_mem_dirmap_desc *desc,
279aa167f3fSBoris Brezillon 			       u64 offs, size_t len, void *buf);
280aa167f3fSBoris Brezillon 	ssize_t (*dirmap_write)(struct spi_mem_dirmap_desc *desc,
281aa167f3fSBoris Brezillon 				u64 offs, size_t len, const void *buf);
282c955a0ccSPatrice Chotard 	int (*poll_status)(struct spi_mem *mem,
283c955a0ccSPatrice Chotard 			   const struct spi_mem_op *op,
284c955a0ccSPatrice Chotard 			   u16 mask, u16 match,
285c955a0ccSPatrice Chotard 			   unsigned long initial_delay_us,
286c955a0ccSPatrice Chotard 			   unsigned long polling_rate_us,
287c955a0ccSPatrice Chotard 			   unsigned long timeout_ms);
288c36ff266SBoris Brezillon };
289c36ff266SBoris Brezillon 
290c36ff266SBoris Brezillon /**
2914a3cc7fbSMiquel Raynal  * struct spi_controller_mem_caps - SPI memory controller capabilities
2924a3cc7fbSMiquel Raynal  * @dtr: Supports DTR operations
293*a433c2cbSMiquel Raynal  * @ecc: Supports operations with error correction
2944a3cc7fbSMiquel Raynal  */
2954a3cc7fbSMiquel Raynal struct spi_controller_mem_caps {
2964a3cc7fbSMiquel Raynal 	bool dtr;
297*a433c2cbSMiquel Raynal 	bool ecc;
2984a3cc7fbSMiquel Raynal };
2994a3cc7fbSMiquel Raynal 
3004a3cc7fbSMiquel Raynal #define spi_mem_controller_is_capable(ctlr, cap)	\
3014a3cc7fbSMiquel Raynal 	((ctlr)->mem_caps && (ctlr)->mem_caps->cap)
3024a3cc7fbSMiquel Raynal 
3034a3cc7fbSMiquel Raynal /**
304c36ff266SBoris Brezillon  * struct spi_mem_driver - SPI memory driver
305c36ff266SBoris Brezillon  * @spidrv: inherit from a SPI driver
306c36ff266SBoris Brezillon  * @probe: probe a SPI memory. Usually where detection/initialization takes
307c36ff266SBoris Brezillon  *	   place
308c36ff266SBoris Brezillon  * @remove: remove a SPI memory
309c36ff266SBoris Brezillon  * @shutdown: take appropriate action when the system is shutdown
310c36ff266SBoris Brezillon  *
311c36ff266SBoris Brezillon  * This is just a thin wrapper around a spi_driver. The core takes care of
312c36ff266SBoris Brezillon  * allocating the spi_mem object and forwarding the probe/remove/shutdown
313c36ff266SBoris Brezillon  * request to the spi_mem_driver. The reason we use this wrapper is because
314c36ff266SBoris Brezillon  * we might have to stuff more information into the spi_mem struct to let
315c36ff266SBoris Brezillon  * SPI controllers know more about the SPI memory they interact with, and
316c36ff266SBoris Brezillon  * having this intermediate layer allows us to do that without adding more
317c36ff266SBoris Brezillon  * useless fields to the spi_device object.
318c36ff266SBoris Brezillon  */
319c36ff266SBoris Brezillon struct spi_mem_driver {
320c36ff266SBoris Brezillon 	struct spi_driver spidrv;
321c36ff266SBoris Brezillon 	int (*probe)(struct spi_mem *mem);
322c36ff266SBoris Brezillon 	int (*remove)(struct spi_mem *mem);
323c36ff266SBoris Brezillon 	void (*shutdown)(struct spi_mem *mem);
324c36ff266SBoris Brezillon };
325c36ff266SBoris Brezillon 
326c36ff266SBoris Brezillon #if IS_ENABLED(CONFIG_SPI_MEM)
327c36ff266SBoris Brezillon int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
328c36ff266SBoris Brezillon 				       const struct spi_mem_op *op,
329c36ff266SBoris Brezillon 				       struct sg_table *sg);
330c36ff266SBoris Brezillon 
331c36ff266SBoris Brezillon void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,
332c36ff266SBoris Brezillon 					  const struct spi_mem_op *op,
333c36ff266SBoris Brezillon 					  struct sg_table *sg);
33472e68416SYueHaibing 
33572e68416SYueHaibing bool spi_mem_default_supports_op(struct spi_mem *mem,
33672e68416SYueHaibing 				 const struct spi_mem_op *op);
337c36ff266SBoris Brezillon #else
338c36ff266SBoris Brezillon static inline int
339c36ff266SBoris Brezillon spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
340c36ff266SBoris Brezillon 				   const struct spi_mem_op *op,
341c36ff266SBoris Brezillon 				   struct sg_table *sg)
342c36ff266SBoris Brezillon {
343c36ff266SBoris Brezillon 	return -ENOTSUPP;
344c36ff266SBoris Brezillon }
345c36ff266SBoris Brezillon 
346c36ff266SBoris Brezillon static inline void
347c36ff266SBoris Brezillon spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,
348c36ff266SBoris Brezillon 				     const struct spi_mem_op *op,
349c36ff266SBoris Brezillon 				     struct sg_table *sg)
350c36ff266SBoris Brezillon {
351c36ff266SBoris Brezillon }
35272e68416SYueHaibing 
353b5881b15SYueHaibing static inline
35472e68416SYueHaibing bool spi_mem_default_supports_op(struct spi_mem *mem,
35572e68416SYueHaibing 				 const struct spi_mem_op *op)
35672e68416SYueHaibing {
35772e68416SYueHaibing 	return false;
35872e68416SYueHaibing }
359c36ff266SBoris Brezillon #endif /* CONFIG_SPI_MEM */
360c36ff266SBoris Brezillon 
361c36ff266SBoris Brezillon int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op);
362c36ff266SBoris Brezillon 
363c36ff266SBoris Brezillon bool spi_mem_supports_op(struct spi_mem *mem,
364c36ff266SBoris Brezillon 			 const struct spi_mem_op *op);
365c36ff266SBoris Brezillon 
366c36ff266SBoris Brezillon int spi_mem_exec_op(struct spi_mem *mem,
367c36ff266SBoris Brezillon 		    const struct spi_mem_op *op);
368c36ff266SBoris Brezillon 
3695d27a9c8SFrieder Schrempf const char *spi_mem_get_name(struct spi_mem *mem);
3705d27a9c8SFrieder Schrempf 
371aa167f3fSBoris Brezillon struct spi_mem_dirmap_desc *
372aa167f3fSBoris Brezillon spi_mem_dirmap_create(struct spi_mem *mem,
373aa167f3fSBoris Brezillon 		      const struct spi_mem_dirmap_info *info);
374aa167f3fSBoris Brezillon void spi_mem_dirmap_destroy(struct spi_mem_dirmap_desc *desc);
375aa167f3fSBoris Brezillon ssize_t spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc,
376aa167f3fSBoris Brezillon 			    u64 offs, size_t len, void *buf);
377aa167f3fSBoris Brezillon ssize_t spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc,
378aa167f3fSBoris Brezillon 			     u64 offs, size_t len, const void *buf);
3791fc1b636SBoris Brezillon struct spi_mem_dirmap_desc *
3801fc1b636SBoris Brezillon devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem,
3811fc1b636SBoris Brezillon 			   const struct spi_mem_dirmap_info *info);
3821fc1b636SBoris Brezillon void devm_spi_mem_dirmap_destroy(struct device *dev,
3831fc1b636SBoris Brezillon 				 struct spi_mem_dirmap_desc *desc);
384aa167f3fSBoris Brezillon 
385c955a0ccSPatrice Chotard int spi_mem_poll_status(struct spi_mem *mem,
386c955a0ccSPatrice Chotard 			const struct spi_mem_op *op,
387c955a0ccSPatrice Chotard 			u16 mask, u16 match,
388c955a0ccSPatrice Chotard 			unsigned long initial_delay_us,
389c955a0ccSPatrice Chotard 			unsigned long polling_delay_us,
390c955a0ccSPatrice Chotard 			u16 timeout_ms);
391c955a0ccSPatrice Chotard 
392c36ff266SBoris Brezillon int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv,
393c36ff266SBoris Brezillon 				       struct module *owner);
394c36ff266SBoris Brezillon 
395c36ff266SBoris Brezillon void spi_mem_driver_unregister(struct spi_mem_driver *drv);
396c36ff266SBoris Brezillon 
397c36ff266SBoris Brezillon #define spi_mem_driver_register(__drv)                                  \
398c36ff266SBoris Brezillon 	spi_mem_driver_register_with_owner(__drv, THIS_MODULE)
399c36ff266SBoris Brezillon 
400c36ff266SBoris Brezillon #define module_spi_mem_driver(__drv)                                    \
401c36ff266SBoris Brezillon 	module_driver(__drv, spi_mem_driver_register,                   \
402c36ff266SBoris Brezillon 		      spi_mem_driver_unregister)
403c36ff266SBoris Brezillon 
404c36ff266SBoris Brezillon #endif /* __LINUX_SPI_MEM_H */
405