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#include <common.h>
32#include <virtex2.h>
33
34#if 0
35#define FPGA_DEBUG
36#endif
37
38#ifdef FPGA_DEBUG
39#define PRINTF(fmt,args...) printf (fmt ,##args)
40#else
41#define PRINTF(fmt,args...)
42#endif
43
44
45
46
47
48
49
50#ifndef CONFIG_SYS_FPGA_CHECK_BUSY
51#undef CONFIG_SYS_FPGA_CHECK_BUSY
52#endif
53
54#ifndef CONFIG_FPGA_DELAY
55#define CONFIG_FPGA_DELAY()
56#endif
57
58#ifndef CONFIG_SYS_FPGA_PROG_FEEDBACK
59#define CONFIG_SYS_FPGA_PROG_FEEDBACK
60#endif
61
62
63
64
65#ifndef CONFIG_SYS_FPGA_CHECK_CTRLC
66#undef CONFIG_SYS_FPGA_CHECK_CTRLC
67#endif
68
69
70
71
72#ifndef CONFIG_SYS_FPGA_CHECK_ERROR
73#define CONFIG_SYS_FPGA_CHECK_ERROR
74#endif
75
76
77
78
79
80
81
82
83
84#ifndef CONFIG_SYS_FPGA_WAIT_INIT
85#define CONFIG_SYS_FPGA_WAIT_INIT CONFIG_SYS_HZ/2
86#endif
87
88
89
90
91
92
93#ifndef CONFIG_SYS_FPGA_WAIT_BUSY
94#define CONFIG_SYS_FPGA_WAIT_BUSY CONFIG_SYS_HZ/200
95#endif
96
97
98
99
100#ifndef CONFIG_SYS_FPGA_WAIT_CONFIG
101#define CONFIG_SYS_FPGA_WAIT_CONFIG CONFIG_SYS_HZ/5
102#endif
103
104static int Virtex2_ssm_load(Xilinx_desc *desc, const void *buf, size_t bsize);
105static int Virtex2_ssm_dump(Xilinx_desc *desc, const void *buf, size_t bsize);
106
107static int Virtex2_ss_load(Xilinx_desc *desc, const void *buf, size_t bsize);
108static int Virtex2_ss_dump(Xilinx_desc *desc, const void *buf, size_t bsize);
109
110int Virtex2_load(Xilinx_desc *desc, const void *buf, size_t bsize)
111{
112 int ret_val = FPGA_FAIL;
113
114 switch (desc->iface) {
115 case slave_serial:
116 PRINTF ("%s: Launching Slave Serial Load\n", __FUNCTION__);
117 ret_val = Virtex2_ss_load (desc, buf, bsize);
118 break;
119
120 case slave_selectmap:
121 PRINTF ("%s: Launching Slave Parallel Load\n", __FUNCTION__);
122 ret_val = Virtex2_ssm_load (desc, buf, bsize);
123 break;
124
125 default:
126 printf ("%s: Unsupported interface type, %d\n",
127 __FUNCTION__, desc->iface);
128 }
129 return ret_val;
130}
131
132int Virtex2_dump(Xilinx_desc *desc, const void *buf, size_t bsize)
133{
134 int ret_val = FPGA_FAIL;
135
136 switch (desc->iface) {
137 case slave_serial:
138 PRINTF ("%s: Launching Slave Serial Dump\n", __FUNCTION__);
139 ret_val = Virtex2_ss_dump (desc, buf, bsize);
140 break;
141
142 case slave_parallel:
143 PRINTF ("%s: Launching Slave Parallel Dump\n", __FUNCTION__);
144 ret_val = Virtex2_ssm_dump (desc, buf, bsize);
145 break;
146
147 default:
148 printf ("%s: Unsupported interface type, %d\n",
149 __FUNCTION__, desc->iface);
150 }
151 return ret_val;
152}
153
154int Virtex2_info (Xilinx_desc * desc)
155{
156 return FPGA_SUCCESS;
157}
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173static int Virtex2_ssm_load(Xilinx_desc *desc, const void *buf, size_t bsize)
174{
175 int ret_val = FPGA_FAIL;
176 Xilinx_Virtex2_Slave_SelectMap_fns *fn = desc->iface_fns;
177
178 PRINTF ("%s:%d: Start with interface functions @ 0x%p\n",
179 __FUNCTION__, __LINE__, fn);
180
181 if (fn) {
182 size_t bytecount = 0;
183 unsigned char *data = (unsigned char *) buf;
184 int cookie = desc->cookie;
185 unsigned long ts;
186
187
188 PRINTF ("%s:%d: Function Table:\n"
189 " base 0x%p\n"
190 " struct 0x%p\n"
191 " pre 0x%p\n"
192 " prog 0x%p\n"
193 " init 0x%p\n"
194 " error 0x%p\n",
195 __FUNCTION__, __LINE__,
196 &fn, fn, fn->pre, fn->pgm, fn->init, fn->err);
197 PRINTF (" clock 0x%p\n"
198 " cs 0x%p\n"
199 " write 0x%p\n"
200 " rdata 0x%p\n"
201 " wdata 0x%p\n"
202 " busy 0x%p\n"
203 " abort 0x%p\n"
204 " post 0x%p\n\n",
205 fn->clk, fn->cs, fn->wr, fn->rdata, fn->wdata,
206 fn->busy, fn->abort, fn->post);
207
208#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
209 printf ("Initializing FPGA Device %d...\n", cookie);
210#endif
211
212
213
214 if (*fn->pre) {
215 (*fn->pre) (cookie);
216 }
217
218
219
220
221
222
223
224 (*fn->pgm) (TRUE, TRUE, cookie);
225 udelay (10);
226 ts = get_timer (0);
227 do {
228 if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT_INIT) {
229 printf ("%s:%d: ** Timeout after %d ticks waiting for INIT"
230 " to assert.\n", __FUNCTION__, __LINE__,
231 CONFIG_SYS_FPGA_WAIT_INIT);
232 (*fn->abort) (cookie);
233 return FPGA_FAIL;
234 }
235 } while (!(*fn->init) (cookie));
236
237 (*fn->pgm) (FALSE, TRUE, cookie);
238 CONFIG_FPGA_DELAY ();
239 (*fn->clk) (TRUE, TRUE, cookie);
240
241
242
243
244 ts = get_timer (0);
245 do {
246 CONFIG_FPGA_DELAY ();
247 if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT_INIT) {
248 printf ("%s:%d: ** Timeout after %d ticks waiting for INIT"
249 " to deassert.\n", __FUNCTION__, __LINE__,
250 CONFIG_SYS_FPGA_WAIT_INIT);
251 (*fn->abort) (cookie);
252 return FPGA_FAIL;
253 }
254 } while ((*fn->init) (cookie) && (*fn->busy) (cookie));
255
256 (*fn->wr) (TRUE, TRUE, cookie);
257 (*fn->cs) (TRUE, TRUE, cookie);
258
259 udelay (10000);
260
261
262
263
264 while (bytecount < bsize) {
265#ifdef CONFIG_SYS_FPGA_CHECK_CTRLC
266 if (ctrlc ()) {
267 (*fn->abort) (cookie);
268 return FPGA_FAIL;
269 }
270#endif
271
272 if ((*fn->done) (cookie) == FPGA_SUCCESS) {
273 PRINTF ("%s:%d:done went active early, bytecount = %d\n",
274 __FUNCTION__, __LINE__, bytecount);
275 break;
276 }
277
278#ifdef CONFIG_SYS_FPGA_CHECK_ERROR
279 if ((*fn->init) (cookie)) {
280 printf ("\n%s:%d: ** Error: INIT asserted during"
281 " configuration\n", __FUNCTION__, __LINE__);
282 printf ("%d = buffer offset, %d = buffer size\n",
283 bytecount, bsize);
284 (*fn->abort) (cookie);
285 return FPGA_FAIL;
286 }
287#endif
288
289 (*fn->wdata) (data[bytecount++], TRUE, cookie);
290 CONFIG_FPGA_DELAY ();
291
292
293
294
295 (*fn->clk) (FALSE, TRUE, cookie);
296 CONFIG_FPGA_DELAY ();
297 (*fn->clk) (TRUE, TRUE, cookie);
298
299#ifdef CONFIG_SYS_FPGA_CHECK_BUSY
300 ts = get_timer (0);
301 while ((*fn->busy) (cookie)) {
302 if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT_BUSY) {
303 printf ("%s:%d: ** Timeout after %d ticks waiting for"
304 " BUSY to deassert\n",
305 __FUNCTION__, __LINE__, CONFIG_SYS_FPGA_WAIT_BUSY);
306 (*fn->abort) (cookie);
307 return FPGA_FAIL;
308 }
309 }
310#endif
311
312#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
313 if (bytecount % (bsize / 40) == 0)
314 putc ('.');
315#endif
316 }
317
318
319
320
321 CONFIG_FPGA_DELAY ();
322 (*fn->cs) (FALSE, TRUE, cookie);
323 (*fn->wr) (FALSE, TRUE, cookie);
324
325#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
326 putc ('\n');
327#endif
328
329
330
331
332
333 ts = get_timer (0);
334 ret_val = FPGA_SUCCESS;
335 while (((*fn->done) (cookie) == FPGA_FAIL) || (*fn->init) (cookie)) {
336 if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT_CONFIG) {
337 printf ("%s:%d: ** Timeout after %d ticks waiting for DONE to"
338 "assert and INIT to deassert\n",
339 __FUNCTION__, __LINE__, CONFIG_SYS_FPGA_WAIT_CONFIG);
340 (*fn->abort) (cookie);
341 ret_val = FPGA_FAIL;
342 break;
343 }
344 }
345
346 if (ret_val == FPGA_SUCCESS) {
347#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
348 printf ("Initialization of FPGA device %d complete\n", cookie);
349#endif
350
351
352
353 if (*fn->post) {
354 (*fn->post) (cookie);
355 }
356 } else {
357#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
358 printf ("** Initialization of FPGA device %d FAILED\n",
359 cookie);
360#endif
361 }
362 } else {
363 printf ("%s:%d: NULL Interface function table!\n",
364 __FUNCTION__, __LINE__);
365 }
366 return ret_val;
367}
368
369
370
371
372static int Virtex2_ssm_dump(Xilinx_desc *desc, const void *buf, size_t bsize)
373{
374 int ret_val = FPGA_FAIL;
375 Xilinx_Virtex2_Slave_SelectMap_fns *fn = desc->iface_fns;
376
377 if (fn) {
378 unsigned char *data = (unsigned char *) buf;
379 size_t bytecount = 0;
380 int cookie = desc->cookie;
381
382 printf ("Starting Dump of FPGA Device %d...\n", cookie);
383
384 (*fn->cs) (TRUE, TRUE, cookie);
385 (*fn->clk) (TRUE, TRUE, cookie);
386
387 while (bytecount < bsize) {
388#ifdef CONFIG_SYS_FPGA_CHECK_CTRLC
389 if (ctrlc ()) {
390 (*fn->abort) (cookie);
391 return FPGA_FAIL;
392 }
393#endif
394
395
396
397 (*fn->clk) (FALSE, TRUE, cookie);
398 (*fn->clk) (TRUE, TRUE, cookie);
399 (*fn->rdata) (&(data[bytecount++]), cookie);
400#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
401 if (bytecount % (bsize / 40) == 0)
402 putc ('.');
403#endif
404 }
405
406
407
408
409 (*fn->cs) (FALSE, FALSE, cookie);
410 (*fn->clk) (FALSE, TRUE, cookie);
411 (*fn->clk) (TRUE, TRUE, cookie);
412
413#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
414 putc ('\n');
415#endif
416 puts ("Done.\n");
417 } else {
418 printf ("%s:%d: NULL Interface function table!\n",
419 __FUNCTION__, __LINE__);
420 }
421 return ret_val;
422}
423
424static int Virtex2_ss_load(Xilinx_desc *desc, const void *buf, size_t bsize)
425{
426 printf ("%s: Slave Serial Loading is unsupported\n", __FUNCTION__);
427 return FPGA_FAIL;
428}
429
430static int Virtex2_ss_dump(Xilinx_desc *desc, const void *buf, size_t bsize)
431{
432 printf ("%s: Slave Serial Dumping is unsupported\n", __FUNCTION__);
433 return FPGA_FAIL;
434}
435
436
437