This source file includes following definitions.
- fifo_icap_fifo_write
- fifo_icap_fifo_read
- fifo_icap_set_read_size
- fifo_icap_start_config
- fifo_icap_start_readback
- fifo_icap_get_status
- fifo_icap_busy
- fifo_icap_write_fifo_vacancy
- fifo_icap_read_fifo_occupancy
- fifo_icap_set_configuration
- fifo_icap_get_configuration
- fifo_icap_reset
- fifo_icap_flush_fifo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include "fifo_icap.h"
34
35
36 #define XHI_GIER_OFFSET 0x1C
37 #define XHI_IPISR_OFFSET 0x20
38 #define XHI_IPIER_OFFSET 0x28
39 #define XHI_WF_OFFSET 0x100
40 #define XHI_RF_OFFSET 0x104
41 #define XHI_SZ_OFFSET 0x108
42 #define XHI_CR_OFFSET 0x10C
43 #define XHI_SR_OFFSET 0x110
44 #define XHI_WFV_OFFSET 0x114
45 #define XHI_RFO_OFFSET 0x118
46
47
48
49 #define XHI_GIER_GIE_MASK 0x80000000
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 #define XHI_IPIXR_RFULL_MASK 0x00000008
67 #define XHI_IPIXR_WEMPTY_MASK 0x00000004
68 #define XHI_IPIXR_RDP_MASK 0x00000002
69 #define XHI_IPIXR_WRP_MASK 0x00000001
70 #define XHI_IPIXR_ALL_MASK 0x0000000F
71
72
73 #define XHI_CR_SW_RESET_MASK 0x00000008
74 #define XHI_CR_FIFO_CLR_MASK 0x00000004
75 #define XHI_CR_READ_MASK 0x00000002
76 #define XHI_CR_WRITE_MASK 0x00000001
77
78
79 #define XHI_WFO_MAX_VACANCY 1024
80 #define XHI_RFO_MAX_OCCUPANCY 256
81
82
83 #define XHI_MAX_READ_TRANSACTION_WORDS 0xFFF
84
85
86
87
88
89
90
91
92
93 static inline void fifo_icap_fifo_write(struct hwicap_drvdata *drvdata,
94 u32 data)
95 {
96 dev_dbg(drvdata->dev, "fifo_write: %x\n", data);
97 out_be32(drvdata->base_address + XHI_WF_OFFSET, data);
98 }
99
100
101
102
103
104
105
106 static inline u32 fifo_icap_fifo_read(struct hwicap_drvdata *drvdata)
107 {
108 u32 data = in_be32(drvdata->base_address + XHI_RF_OFFSET);
109 dev_dbg(drvdata->dev, "fifo_read: %x\n", data);
110 return data;
111 }
112
113
114
115
116
117
118 static inline void fifo_icap_set_read_size(struct hwicap_drvdata *drvdata,
119 u32 data)
120 {
121 out_be32(drvdata->base_address + XHI_SZ_OFFSET, data);
122 }
123
124
125
126
127
128 static inline void fifo_icap_start_config(struct hwicap_drvdata *drvdata)
129 {
130 out_be32(drvdata->base_address + XHI_CR_OFFSET, XHI_CR_WRITE_MASK);
131 dev_dbg(drvdata->dev, "configuration started\n");
132 }
133
134
135
136
137
138 static inline void fifo_icap_start_readback(struct hwicap_drvdata *drvdata)
139 {
140 out_be32(drvdata->base_address + XHI_CR_OFFSET, XHI_CR_READ_MASK);
141 dev_dbg(drvdata->dev, "readback started\n");
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 u32 fifo_icap_get_status(struct hwicap_drvdata *drvdata)
161 {
162 u32 status = in_be32(drvdata->base_address + XHI_SR_OFFSET);
163 dev_dbg(drvdata->dev, "Getting status = %x\n", status);
164 return status;
165 }
166
167
168
169
170
171 static inline u32 fifo_icap_busy(struct hwicap_drvdata *drvdata)
172 {
173 u32 status = in_be32(drvdata->base_address + XHI_SR_OFFSET);
174 return (status & XHI_SR_DONE_MASK) ? 0 : 1;
175 }
176
177
178
179
180
181
182
183 static inline u32 fifo_icap_write_fifo_vacancy(
184 struct hwicap_drvdata *drvdata)
185 {
186 return in_be32(drvdata->base_address + XHI_WFV_OFFSET);
187 }
188
189
190
191
192
193
194
195 static inline u32 fifo_icap_read_fifo_occupancy(
196 struct hwicap_drvdata *drvdata)
197 {
198 return in_be32(drvdata->base_address + XHI_RFO_OFFSET);
199 }
200
201
202
203
204
205
206
207
208
209
210
211
212
213 int fifo_icap_set_configuration(struct hwicap_drvdata *drvdata,
214 u32 *frame_buffer, u32 num_words)
215 {
216
217 u32 write_fifo_vacancy = 0;
218 u32 retries = 0;
219 u32 remaining_words;
220
221 dev_dbg(drvdata->dev, "fifo_set_configuration\n");
222
223
224
225
226 if (fifo_icap_busy(drvdata))
227 return -EBUSY;
228
229
230
231
232 remaining_words = num_words;
233
234 while (remaining_words > 0) {
235
236
237
238 while (write_fifo_vacancy == 0) {
239 write_fifo_vacancy =
240 fifo_icap_write_fifo_vacancy(drvdata);
241 retries++;
242 if (retries > XHI_MAX_RETRIES)
243 return -EIO;
244 }
245
246
247
248
249 while ((write_fifo_vacancy != 0) &&
250 (remaining_words > 0)) {
251 fifo_icap_fifo_write(drvdata, *frame_buffer);
252
253 remaining_words--;
254 write_fifo_vacancy--;
255 frame_buffer++;
256 }
257
258 fifo_icap_start_config(drvdata);
259 }
260
261
262 while (fifo_icap_busy(drvdata)) {
263 retries++;
264 if (retries > XHI_MAX_RETRIES)
265 break;
266 }
267
268 dev_dbg(drvdata->dev, "done fifo_set_configuration\n");
269
270
271
272
273
274 if (remaining_words != 0)
275 return -EIO;
276
277 return 0;
278 }
279
280
281
282
283
284
285
286
287
288
289 int fifo_icap_get_configuration(struct hwicap_drvdata *drvdata,
290 u32 *frame_buffer, u32 num_words)
291 {
292
293 u32 read_fifo_occupancy = 0;
294 u32 retries = 0;
295 u32 *data = frame_buffer;
296 u32 remaining_words;
297 u32 words_to_read;
298
299 dev_dbg(drvdata->dev, "fifo_get_configuration\n");
300
301
302
303
304 if (fifo_icap_busy(drvdata))
305 return -EBUSY;
306
307 remaining_words = num_words;
308
309 while (remaining_words > 0) {
310 words_to_read = remaining_words;
311
312
313 if (words_to_read > XHI_MAX_READ_TRANSACTION_WORDS)
314 words_to_read = XHI_MAX_READ_TRANSACTION_WORDS;
315
316 remaining_words -= words_to_read;
317
318 fifo_icap_set_read_size(drvdata, words_to_read);
319 fifo_icap_start_readback(drvdata);
320
321 while (words_to_read > 0) {
322
323 while (read_fifo_occupancy == 0) {
324 read_fifo_occupancy =
325 fifo_icap_read_fifo_occupancy(drvdata);
326 retries++;
327 if (retries > XHI_MAX_RETRIES)
328 return -EIO;
329 }
330
331 if (read_fifo_occupancy > words_to_read)
332 read_fifo_occupancy = words_to_read;
333
334 words_to_read -= read_fifo_occupancy;
335
336
337 while (read_fifo_occupancy != 0) {
338 *data++ = fifo_icap_fifo_read(drvdata);
339 read_fifo_occupancy--;
340 }
341 }
342 }
343
344 dev_dbg(drvdata->dev, "done fifo_get_configuration\n");
345
346 return 0;
347 }
348
349
350
351
352
353
354
355
356
357 void fifo_icap_reset(struct hwicap_drvdata *drvdata)
358 {
359 u32 reg_data;
360
361
362
363
364 reg_data = in_be32(drvdata->base_address + XHI_CR_OFFSET);
365
366 out_be32(drvdata->base_address + XHI_CR_OFFSET,
367 reg_data | XHI_CR_SW_RESET_MASK);
368
369 out_be32(drvdata->base_address + XHI_CR_OFFSET,
370 reg_data & (~XHI_CR_SW_RESET_MASK));
371
372 }
373
374
375
376
377
378 void fifo_icap_flush_fifo(struct hwicap_drvdata *drvdata)
379 {
380 u32 reg_data;
381
382
383
384
385 reg_data = in_be32(drvdata->base_address + XHI_CR_OFFSET);
386
387 out_be32(drvdata->base_address + XHI_CR_OFFSET,
388 reg_data | XHI_CR_FIFO_CLR_MASK);
389
390 out_be32(drvdata->base_address + XHI_CR_OFFSET,
391 reg_data & (~XHI_CR_FIFO_CLR_MASK));
392 }
393