1
2
3
4
5
6
7
8
9
10
11#ifndef __UBOOT_SPI_MEM_H
12#define __UBOOT_SPI_MEM_H
13
14struct udevice;
15
16#define SPI_MEM_OP_CMD(__opcode, __buswidth) \
17 { \
18 .buswidth = __buswidth, \
19 .opcode = __opcode, \
20 .nbytes = 1, \
21 }
22
23#define SPI_MEM_OP_ADDR(__nbytes, __val, __buswidth) \
24 { \
25 .nbytes = __nbytes, \
26 .val = __val, \
27 .buswidth = __buswidth, \
28 }
29
30#define SPI_MEM_OP_NO_ADDR { }
31
32#define SPI_MEM_OP_DUMMY(__nbytes, __buswidth) \
33 { \
34 .nbytes = __nbytes, \
35 .buswidth = __buswidth, \
36 }
37
38#define SPI_MEM_OP_NO_DUMMY { }
39
40#define SPI_MEM_OP_DATA_IN(__nbytes, __buf, __buswidth) \
41 { \
42 .dir = SPI_MEM_DATA_IN, \
43 .nbytes = __nbytes, \
44 .buf.in = __buf, \
45 .buswidth = __buswidth, \
46 }
47
48#define SPI_MEM_OP_DATA_OUT(__nbytes, __buf, __buswidth) \
49 { \
50 .dir = SPI_MEM_DATA_OUT, \
51 .nbytes = __nbytes, \
52 .buf.out = __buf, \
53 .buswidth = __buswidth, \
54 }
55
56#define SPI_MEM_OP_NO_DATA { }
57
58
59
60
61
62
63
64
65enum spi_mem_data_dir {
66 SPI_MEM_NO_DATA,
67 SPI_MEM_DATA_IN,
68 SPI_MEM_DATA_OUT,
69};
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96struct spi_mem_op {
97 struct {
98 u8 nbytes;
99 u8 buswidth;
100 u8 dtr : 1;
101 u16 opcode;
102 } cmd;
103
104 struct {
105 u8 nbytes;
106 u8 buswidth;
107 u8 dtr : 1;
108 u64 val;
109 } addr;
110
111 struct {
112 u8 nbytes;
113 u8 buswidth;
114 u8 dtr : 1;
115 } dummy;
116
117 struct {
118 u8 buswidth;
119 u8 dtr : 1;
120 enum spi_mem_data_dir dir;
121 unsigned int nbytes;
122
123 union {
124 void *in;
125 const void *out;
126 } buf;
127 } data;
128};
129
130#define SPI_MEM_OP(__cmd, __addr, __dummy, __data) \
131 { \
132 .cmd = __cmd, \
133 .addr = __addr, \
134 .dummy = __dummy, \
135 .data = __data, \
136 }
137
138#ifndef __UBOOT__
139
140
141
142
143
144
145
146
147
148
149
150struct spi_mem {
151 struct udevice *dev;
152 void *drvpriv;
153};
154
155
156
157
158
159
160
161static inline void spi_mem_set_drvdata(struct spi_mem *mem, void *data)
162{
163 mem->drvpriv = data;
164}
165
166
167
168
169
170
171
172
173static inline void *spi_mem_get_drvdata(struct spi_mem *mem)
174{
175 return mem->drvpriv;
176}
177#endif
178
179
180
181
182
183
184
185
186
187
188
189
190
191struct spi_controller_mem_ops {
192 int (*adjust_op_size)(struct spi_slave *slave, struct spi_mem_op *op);
193 bool (*supports_op)(struct spi_slave *slave,
194 const struct spi_mem_op *op);
195 int (*exec_op)(struct spi_slave *slave,
196 const struct spi_mem_op *op);
197};
198
199#ifndef __UBOOT__
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216struct spi_mem_driver {
217 struct spi_driver spidrv;
218 int (*probe)(struct spi_mem *mem);
219 int (*remove)(struct spi_mem *mem);
220 void (*shutdown)(struct spi_mem *mem);
221};
222
223#if IS_ENABLED(CONFIG_SPI_MEM)
224int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
225 const struct spi_mem_op *op,
226 struct sg_table *sg);
227
228void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,
229 const struct spi_mem_op *op,
230 struct sg_table *sg);
231#else
232static inline int
233spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
234 const struct spi_mem_op *op,
235 struct sg_table *sg)
236{
237 return -ENOSYS;
238}
239
240static inline void
241spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,
242 const struct spi_mem_op *op,
243 struct sg_table *sg)
244{
245}
246#endif
247#endif
248
249int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op);
250
251bool spi_mem_supports_op(struct spi_slave *slave, const struct spi_mem_op *op);
252bool spi_mem_dtr_supports_op(struct spi_slave *slave,
253 const struct spi_mem_op *op);
254
255bool spi_mem_default_supports_op(struct spi_slave *slave,
256 const struct spi_mem_op *op);
257
258int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op);
259
260bool spi_mem_default_supports_op(struct spi_slave *mem,
261 const struct spi_mem_op *op);
262
263#ifndef __UBOOT__
264int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv,
265 struct module *owner);
266
267void spi_mem_driver_unregister(struct spi_mem_driver *drv);
268
269#define spi_mem_driver_register(__drv) \
270 spi_mem_driver_register_with_owner(__drv, THIS_MODULE)
271
272#define module_spi_mem_driver(__drv) \
273 module_driver(__drv, spi_mem_driver_register, \
274 spi_mem_driver_unregister)
275#endif
276
277#endif
278