3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * Configuration support for Xilinx Spartan3 devices. Based
27 * on spartan2.c (Rich Ireland, rireland@enterasys.com).
30 #include <common.h> /* core U-Boot definitions */
31 #include <spartan3.h> /* Spartan-II device family */
33 /* Define FPGA_DEBUG to get debug printf's */
35 #define PRINTF(fmt,args...) printf (fmt ,##args)
37 #define PRINTF(fmt,args...)
40 #undef CONFIG_SYS_FPGA_CHECK_BUSY
42 /* Note: The assumption is that we cannot possibly run fast enough to
43 * overrun the device (the Slave Parallel mode can free run at 50MHz).
44 * If there is a need to operate slower, define CONFIG_FPGA_DELAY in
45 * the board config file to slow things down.
47 #ifndef CONFIG_FPGA_DELAY
48 #define CONFIG_FPGA_DELAY()
51 #ifndef CONFIG_SYS_FPGA_WAIT
52 #define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/100 /* 10 ms */
55 static int Spartan3_sp_load(Xilinx_desc
*desc
, const void *buf
, size_t bsize
);
56 static int Spartan3_sp_dump(Xilinx_desc
*desc
, const void *buf
, size_t bsize
);
57 /* static int Spartan3_sp_info(Xilinx_desc *desc ); */
59 static int Spartan3_ss_load(Xilinx_desc
*desc
, const void *buf
, size_t bsize
);
60 static int Spartan3_ss_dump(Xilinx_desc
*desc
, const void *buf
, size_t bsize
);
61 /* static int Spartan3_ss_info(Xilinx_desc *desc); */
63 /* ------------------------------------------------------------------------- */
64 /* Spartan-II Generic Implementation */
65 int Spartan3_load(Xilinx_desc
*desc
, const void *buf
, size_t bsize
)
67 int ret_val
= FPGA_FAIL
;
69 switch (desc
->iface
) {
71 PRINTF ("%s: Launching Slave Serial Load\n", __FUNCTION__
);
72 ret_val
= Spartan3_ss_load (desc
, buf
, bsize
);
76 PRINTF ("%s: Launching Slave Parallel Load\n", __FUNCTION__
);
77 ret_val
= Spartan3_sp_load (desc
, buf
, bsize
);
81 printf ("%s: Unsupported interface type, %d\n",
82 __FUNCTION__
, desc
->iface
);
88 int Spartan3_dump(Xilinx_desc
*desc
, const void *buf
, size_t bsize
)
90 int ret_val
= FPGA_FAIL
;
92 switch (desc
->iface
) {
94 PRINTF ("%s: Launching Slave Serial Dump\n", __FUNCTION__
);
95 ret_val
= Spartan3_ss_dump (desc
, buf
, bsize
);
99 PRINTF ("%s: Launching Slave Parallel Dump\n", __FUNCTION__
);
100 ret_val
= Spartan3_sp_dump (desc
, buf
, bsize
);
104 printf ("%s: Unsupported interface type, %d\n",
105 __FUNCTION__
, desc
->iface
);
111 int Spartan3_info( Xilinx_desc
*desc
)
117 /* ------------------------------------------------------------------------- */
118 /* Spartan-II Slave Parallel Generic Implementation */
120 static int Spartan3_sp_load(Xilinx_desc
*desc
, const void *buf
, size_t bsize
)
122 int ret_val
= FPGA_FAIL
; /* assume the worst */
123 Xilinx_Spartan3_Slave_Parallel_fns
*fn
= desc
->iface_fns
;
125 PRINTF ("%s: start with interface functions @ 0x%p\n",
129 size_t bytecount
= 0;
130 unsigned char *data
= (unsigned char *) buf
;
131 int cookie
= desc
->cookie
; /* make a local copy */
132 unsigned long ts
; /* timestamp */
134 PRINTF ("%s: Function Table:\n"
145 "write data:\t0x%p\n"
149 __FUNCTION__
, &fn
, fn
, fn
->pre
, fn
->pgm
, fn
->init
, fn
->err
,
150 fn
->clk
, fn
->cs
, fn
->wr
, fn
->rdata
, fn
->wdata
, fn
->busy
,
151 fn
->abort
, fn
->post
);
154 * This code is designed to emulate the "Express Style"
155 * Continuous Data Loading in Slave Parallel Mode for
156 * the Spartan-II Family.
158 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
159 printf ("Loading FPGA Device %d...\n", cookie
);
162 * Run the pre configuration function if there is one.
168 /* Establish the initial state */
169 (*fn
->pgm
) (true, true, cookie
); /* Assert the program, commit */
171 /* Get ready for the burn */
172 CONFIG_FPGA_DELAY ();
173 (*fn
->pgm
) (false, true, cookie
); /* Deassert the program, commit */
175 ts
= get_timer (0); /* get current time */
176 /* Now wait for INIT and BUSY to go high */
178 CONFIG_FPGA_DELAY ();
179 if (get_timer (ts
) > CONFIG_SYS_FPGA_WAIT
) { /* check the time */
180 puts ("** Timeout waiting for INIT to clear.\n");
181 (*fn
->abort
) (cookie
); /* abort the burn */
184 } while ((*fn
->init
) (cookie
) && (*fn
->busy
) (cookie
));
186 (*fn
->wr
) (true, true, cookie
); /* Assert write, commit */
187 (*fn
->cs
) (true, true, cookie
); /* Assert chip select, commit */
188 (*fn
->clk
) (true, true, cookie
); /* Assert the clock pin */
191 while (bytecount
< bsize
) {
192 /* XXX - do we check for an Ctrl-C press in here ??? */
193 /* XXX - Check the error bit? */
195 (*fn
->wdata
) (data
[bytecount
++], true, cookie
); /* write the data */
196 CONFIG_FPGA_DELAY ();
197 (*fn
->clk
) (false, true, cookie
); /* Deassert the clock pin */
198 CONFIG_FPGA_DELAY ();
199 (*fn
->clk
) (true, true, cookie
); /* Assert the clock pin */
201 #ifdef CONFIG_SYS_FPGA_CHECK_BUSY
202 ts
= get_timer (0); /* get current time */
203 while ((*fn
->busy
) (cookie
)) {
204 /* XXX - we should have a check in here somewhere to
205 * make sure we aren't busy forever... */
207 CONFIG_FPGA_DELAY ();
208 (*fn
->clk
) (false, true, cookie
); /* Deassert the clock pin */
209 CONFIG_FPGA_DELAY ();
210 (*fn
->clk
) (true, true, cookie
); /* Assert the clock pin */
212 if (get_timer (ts
) > CONFIG_SYS_FPGA_WAIT
) { /* check the time */
213 puts ("** Timeout waiting for BUSY to clear.\n");
214 (*fn
->abort
) (cookie
); /* abort the burn */
220 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
221 if (bytecount
% (bsize
/ 40) == 0)
222 putc ('.'); /* let them know we are alive */
226 CONFIG_FPGA_DELAY ();
227 (*fn
->cs
) (false, true, cookie
); /* Deassert the chip select */
228 (*fn
->wr
) (false, true, cookie
); /* Deassert the write pin */
230 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
231 putc ('\n'); /* terminate the dotted line */
234 /* now check for done signal */
235 ts
= get_timer (0); /* get current time */
236 ret_val
= FPGA_SUCCESS
;
237 while ((*fn
->done
) (cookie
) == FPGA_FAIL
) {
238 /* XXX - we should have a check in here somewhere to
239 * make sure we aren't busy forever... */
241 CONFIG_FPGA_DELAY ();
242 (*fn
->clk
) (false, true, cookie
); /* Deassert the clock pin */
243 CONFIG_FPGA_DELAY ();
244 (*fn
->clk
) (true, true, cookie
); /* Assert the clock pin */
246 if (get_timer (ts
) > CONFIG_SYS_FPGA_WAIT
) { /* check the time */
247 puts ("** Timeout waiting for DONE to clear.\n");
248 (*fn
->abort
) (cookie
); /* abort the burn */
255 * Run the post configuration function if there is one.
258 (*fn
->post
) (cookie
);
260 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
261 if (ret_val
== FPGA_SUCCESS
)
268 printf ("%s: NULL Interface function table!\n", __FUNCTION__
);
274 static int Spartan3_sp_dump(Xilinx_desc
*desc
, const void *buf
, size_t bsize
)
276 int ret_val
= FPGA_FAIL
; /* assume the worst */
277 Xilinx_Spartan3_Slave_Parallel_fns
*fn
= desc
->iface_fns
;
280 unsigned char *data
= (unsigned char *) buf
;
281 size_t bytecount
= 0;
282 int cookie
= desc
->cookie
; /* make a local copy */
284 printf ("Starting Dump of FPGA Device %d...\n", cookie
);
286 (*fn
->cs
) (true, true, cookie
); /* Assert chip select, commit */
287 (*fn
->clk
) (true, true, cookie
); /* Assert the clock pin */
290 while (bytecount
< bsize
) {
291 /* XXX - do we check for an Ctrl-C press in here ??? */
293 (*fn
->clk
) (false, true, cookie
); /* Deassert the clock pin */
294 (*fn
->clk
) (true, true, cookie
); /* Assert the clock pin */
295 (*fn
->rdata
) (&(data
[bytecount
++]), cookie
); /* read the data */
296 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
297 if (bytecount
% (bsize
/ 40) == 0)
298 putc ('.'); /* let them know we are alive */
302 (*fn
->cs
) (false, false, cookie
); /* Deassert the chip select */
303 (*fn
->clk
) (false, true, cookie
); /* Deassert the clock pin */
304 (*fn
->clk
) (true, true, cookie
); /* Assert the clock pin */
306 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
307 putc ('\n'); /* terminate the dotted line */
311 /* XXX - checksum the data? */
313 printf ("%s: NULL Interface function table!\n", __FUNCTION__
);
320 /* ------------------------------------------------------------------------- */
322 static int Spartan3_ss_load(Xilinx_desc
*desc
, const void *buf
, size_t bsize
)
324 int ret_val
= FPGA_FAIL
; /* assume the worst */
325 Xilinx_Spartan3_Slave_Serial_fns
*fn
= desc
->iface_fns
;
329 PRINTF ("%s: start with interface functions @ 0x%p\n",
333 size_t bytecount
= 0;
334 unsigned char *data
= (unsigned char *) buf
;
335 int cookie
= desc
->cookie
; /* make a local copy */
336 unsigned long ts
; /* timestamp */
338 PRINTF ("%s: Function Table:\n"
346 __FUNCTION__
, &fn
, fn
, fn
->pgm
, fn
->init
,
347 fn
->clk
, fn
->wr
, fn
->done
);
348 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
349 printf ("Loading FPGA Device %d...\n", cookie
);
353 * Run the pre configuration function if there is one.
359 /* Establish the initial state */
360 (*fn
->pgm
) (true, true, cookie
); /* Assert the program, commit */
362 /* Wait for INIT state (init low) */
363 ts
= get_timer (0); /* get current time */
365 CONFIG_FPGA_DELAY ();
366 if (get_timer (ts
) > CONFIG_SYS_FPGA_WAIT
) { /* check the time */
367 puts ("** Timeout waiting for INIT to start.\n");
369 (*fn
->abort
) (cookie
);
372 } while (!(*fn
->init
) (cookie
));
374 /* Get ready for the burn */
375 CONFIG_FPGA_DELAY ();
376 (*fn
->pgm
) (false, true, cookie
); /* Deassert the program, commit */
378 ts
= get_timer (0); /* get current time */
379 /* Now wait for INIT to go high */
381 CONFIG_FPGA_DELAY ();
382 if (get_timer (ts
) > CONFIG_SYS_FPGA_WAIT
) { /* check the time */
383 puts ("** Timeout waiting for INIT to clear.\n");
385 (*fn
->abort
) (cookie
);
388 } while ((*fn
->init
) (cookie
));
392 (*fn
->bwr
) (data
, bsize
, true, cookie
);
394 while (bytecount
< bsize
) {
396 /* Xilinx detects an error if INIT goes low (active)
397 while DONE is low (inactive) */
398 if ((*fn
->done
) (cookie
) == 0 && (*fn
->init
) (cookie
)) {
399 puts ("** CRC error during FPGA load.\n");
401 (*fn
->abort
) (cookie
);
404 val
= data
[bytecount
++];
407 /* Deassert the clock */
408 (*fn
->clk
) (false, true, cookie
);
409 CONFIG_FPGA_DELAY ();
411 (*fn
->wr
) ((val
& 0x80), true, cookie
);
412 CONFIG_FPGA_DELAY ();
413 /* Assert the clock */
414 (*fn
->clk
) (true, true, cookie
);
415 CONFIG_FPGA_DELAY ();
420 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
421 if (bytecount
% (bsize
/ 40) == 0)
422 putc ('.'); /* let them know we are alive */
427 CONFIG_FPGA_DELAY ();
429 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
430 putc ('\n'); /* terminate the dotted line */
433 /* now check for done signal */
434 ts
= get_timer (0); /* get current time */
435 ret_val
= FPGA_SUCCESS
;
436 (*fn
->wr
) (true, true, cookie
);
438 while (! (*fn
->done
) (cookie
)) {
439 /* XXX - we should have a check in here somewhere to
440 * make sure we aren't busy forever... */
442 CONFIG_FPGA_DELAY ();
443 (*fn
->clk
) (false, true, cookie
); /* Deassert the clock pin */
444 CONFIG_FPGA_DELAY ();
445 (*fn
->clk
) (true, true, cookie
); /* Assert the clock pin */
449 if (get_timer (ts
) > CONFIG_SYS_FPGA_WAIT
) { /* check the time */
450 puts ("** Timeout waiting for DONE to clear.\n");
455 putc ('\n'); /* terminate the dotted line */
458 * Run the post configuration function if there is one.
461 (*fn
->post
) (cookie
);
463 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
464 if (ret_val
== FPGA_SUCCESS
)
471 printf ("%s: NULL Interface function table!\n", __FUNCTION__
);
477 static int Spartan3_ss_dump(Xilinx_desc
*desc
, const void *buf
, size_t bsize
)
479 /* Readback is only available through the Slave Parallel and */
480 /* boundary-scan interfaces. */
481 printf ("%s: Slave Serial Dumping is unavailable\n",