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