1 // SPDX-License-Identifier: GPL-2.0+
4 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
8 * Configuration support for Xilinx Spartan3 devices. Based
9 * on spartan2.c (Rich Ireland, rireland@enterasys.com).
12 #define LOG_CATEGORY UCLASS_FPGA
14 #include <common.h> /* core U-Boot definitions */
16 #include <spartan3.h> /* Spartan-II device family */
18 /* Note: The assumption is that we cannot possibly run fast enough to
19 * overrun the device (the Slave Parallel mode can free run at 50MHz).
20 * If there is a need to operate slower, define CFG_FPGA_DELAY in
21 * the board config file to slow things down.
23 #ifndef CFG_FPGA_DELAY
24 #define CFG_FPGA_DELAY()
27 #ifndef CFG_SYS_FPGA_WAIT
28 #define CFG_SYS_FPGA_WAIT CONFIG_SYS_HZ/100 /* 10 ms */
31 static int spartan3_sp_load(xilinx_desc *desc, const void *buf, size_t bsize);
32 static int spartan3_sp_dump(xilinx_desc *desc, const void *buf, size_t bsize);
33 /* static int spartan3_sp_info(xilinx_desc *desc ); */
35 static int spartan3_ss_load(xilinx_desc *desc, const void *buf, size_t bsize);
36 static int spartan3_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize);
37 /* static int spartan3_ss_info(xilinx_desc *desc); */
39 /* ------------------------------------------------------------------------- */
40 /* Spartan-II Generic Implementation */
41 static int spartan3_load(xilinx_desc *desc, const void *buf, size_t bsize,
42 bitstream_type bstype, int flags)
44 int ret_val = FPGA_FAIL;
46 switch (desc->iface) {
48 log_debug("Launching Slave Serial Load\n");
49 ret_val = spartan3_ss_load(desc, buf, bsize);
53 log_debug("Launching Slave Parallel Load\n");
54 ret_val = spartan3_sp_load(desc, buf, bsize);
58 printf ("%s: Unsupported interface type, %d\n",
59 __FUNCTION__, desc->iface);
65 static int spartan3_dump(xilinx_desc *desc, const void *buf, size_t bsize)
67 int ret_val = FPGA_FAIL;
69 switch (desc->iface) {
71 log_debug("Launching Slave Serial Dump\n");
72 ret_val = spartan3_ss_dump(desc, buf, bsize);
76 log_debug("Launching Slave Parallel Dump\n");
77 ret_val = spartan3_sp_dump(desc, buf, bsize);
81 printf ("%s: Unsupported interface type, %d\n",
82 __FUNCTION__, desc->iface);
88 static int spartan3_info(xilinx_desc *desc)
94 /* ------------------------------------------------------------------------- */
95 /* Spartan-II Slave Parallel Generic Implementation */
97 static int spartan3_sp_load(xilinx_desc *desc, const void *buf, size_t bsize)
99 int ret_val = FPGA_FAIL; /* assume the worst */
100 xilinx_spartan3_slave_parallel_fns *fn = desc->iface_fns;
102 log_debug("start with interface functions @ 0x%p\n", fn);
105 size_t bytecount = 0;
106 unsigned char *data = (unsigned char *) buf;
107 int cookie = desc->cookie; /* make a local copy */
108 unsigned long ts; /* timestamp */
110 log_debug("Function Table:\n"
121 "write data:\t0x%p\n"
125 &fn, fn, fn->pre, fn->pgm, fn->init, fn->err,
126 fn->clk, fn->cs, fn->wr, fn->rdata, fn->wdata, fn->busy,
127 fn->abort, fn->post);
130 * This code is designed to emulate the "Express Style"
131 * Continuous Data Loading in Slave Parallel Mode for
132 * the Spartan-II Family.
134 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
135 printf ("Loading FPGA Device %d...\n", cookie);
138 * Run the pre configuration function if there is one.
144 /* Establish the initial state */
145 (*fn->pgm) (true, true, cookie); /* Assert the program, commit */
147 /* Get ready for the burn */
149 (*fn->pgm) (false, true, cookie); /* Deassert the program, commit */
151 ts = get_timer (0); /* get current time */
152 /* Now wait for INIT and BUSY to go high */
155 if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */
156 puts ("** Timeout waiting for INIT to clear.\n");
157 (*fn->abort) (cookie); /* abort the burn */
160 } while ((*fn->init) (cookie) && (*fn->busy) (cookie));
162 (*fn->wr) (true, true, cookie); /* Assert write, commit */
163 (*fn->cs) (true, true, cookie); /* Assert chip select, commit */
164 (*fn->clk) (true, true, cookie); /* Assert the clock pin */
167 while (bytecount < bsize) {
168 /* XXX - do we check for an Ctrl-C press in here ??? */
169 /* XXX - Check the error bit? */
171 (*fn->wdata) (data[bytecount++], true, cookie); /* write the data */
173 (*fn->clk) (false, true, cookie); /* Deassert the clock pin */
175 (*fn->clk) (true, true, cookie); /* Assert the clock pin */
177 #ifdef CONFIG_SYS_FPGA_CHECK_BUSY
178 ts = get_timer (0); /* get current time */
179 while ((*fn->busy) (cookie)) {
180 /* XXX - we should have a check in here somewhere to
181 * make sure we aren't busy forever... */
184 (*fn->clk) (false, true, cookie); /* Deassert the clock pin */
186 (*fn->clk) (true, true, cookie); /* Assert the clock pin */
188 if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */
189 puts ("** Timeout waiting for BUSY to clear.\n");
190 (*fn->abort) (cookie); /* abort the burn */
196 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
197 if (bytecount % (bsize / 40) == 0)
198 putc ('.'); /* let them know we are alive */
203 (*fn->cs) (false, true, cookie); /* Deassert the chip select */
204 (*fn->wr) (false, true, cookie); /* Deassert the write pin */
206 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
207 putc ('\n'); /* terminate the dotted line */
210 /* now check for done signal */
211 ts = get_timer (0); /* get current time */
212 ret_val = FPGA_SUCCESS;
213 while ((*fn->done) (cookie) == FPGA_FAIL) {
214 /* XXX - we should have a check in here somewhere to
215 * make sure we aren't busy forever... */
218 (*fn->clk) (false, true, cookie); /* Deassert the clock pin */
220 (*fn->clk) (true, true, cookie); /* Assert the clock pin */
222 if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */
223 puts ("** Timeout waiting for DONE to clear.\n");
224 (*fn->abort) (cookie); /* abort the burn */
231 * Run the post configuration function if there is one.
234 (*fn->post) (cookie);
236 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
237 if (ret_val == FPGA_SUCCESS)
244 printf ("%s: NULL Interface function table!\n", __FUNCTION__);
250 static int spartan3_sp_dump(xilinx_desc *desc, const void *buf, size_t bsize)
252 int ret_val = FPGA_FAIL; /* assume the worst */
253 xilinx_spartan3_slave_parallel_fns *fn = desc->iface_fns;
256 unsigned char *data = (unsigned char *) buf;
257 size_t bytecount = 0;
258 int cookie = desc->cookie; /* make a local copy */
260 printf ("Starting Dump of FPGA Device %d...\n", cookie);
262 (*fn->cs) (true, true, cookie); /* Assert chip select, commit */
263 (*fn->clk) (true, true, cookie); /* Assert the clock pin */
266 while (bytecount < bsize) {
267 /* XXX - do we check for an Ctrl-C press in here ??? */
269 (*fn->clk) (false, true, cookie); /* Deassert the clock pin */
270 (*fn->clk) (true, true, cookie); /* Assert the clock pin */
271 (*fn->rdata) (&(data[bytecount++]), cookie); /* read the data */
272 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
273 if (bytecount % (bsize / 40) == 0)
274 putc ('.'); /* let them know we are alive */
278 (*fn->cs) (false, false, cookie); /* Deassert the chip select */
279 (*fn->clk) (false, true, cookie); /* Deassert the clock pin */
280 (*fn->clk) (true, true, cookie); /* Assert the clock pin */
282 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
283 putc ('\n'); /* terminate the dotted line */
287 /* XXX - checksum the data? */
289 printf ("%s: NULL Interface function table!\n", __FUNCTION__);
296 /* ------------------------------------------------------------------------- */
298 static int spartan3_ss_load(xilinx_desc *desc, const void *buf, size_t bsize)
300 int ret_val = FPGA_FAIL; /* assume the worst */
301 xilinx_spartan3_slave_serial_fns *fn = desc->iface_fns;
305 log_debug("start with interface functions @ 0x%p\n", fn);
308 size_t bytecount = 0;
309 unsigned char *data = (unsigned char *) buf;
310 int cookie = desc->cookie; /* make a local copy */
311 unsigned long ts; /* timestamp */
313 log_debug("Function Table:\n"
321 &fn, fn, fn->pgm, fn->init,
322 fn->clk, fn->wr, fn->done);
323 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
324 printf ("Loading FPGA Device %d...\n", cookie);
328 * Run the pre configuration function if there is one.
334 /* Establish the initial state */
335 (*fn->pgm) (true, true, cookie); /* Assert the program, commit */
337 /* Wait for INIT state (init low) */
338 ts = get_timer (0); /* get current time */
341 if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */
342 puts ("** Timeout waiting for INIT to start.\n");
344 (*fn->abort) (cookie);
347 } while (!(*fn->init) (cookie));
349 /* Get ready for the burn */
351 (*fn->pgm) (false, true, cookie); /* Deassert the program, commit */
353 ts = get_timer (0); /* get current time */
354 /* Now wait for INIT to go high */
357 if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */
358 puts ("** Timeout waiting for INIT to clear.\n");
360 (*fn->abort) (cookie);
363 } while ((*fn->init) (cookie));
367 (*fn->bwr) (data, bsize, true, cookie);
369 while (bytecount < bsize) {
371 /* Xilinx detects an error if INIT goes low (active)
372 while DONE is low (inactive) */
373 if ((*fn->done) (cookie) == 0 && (*fn->init) (cookie)) {
374 puts ("** CRC error during FPGA load.\n");
376 (*fn->abort) (cookie);
379 val = data [bytecount ++];
382 /* Deassert the clock */
383 (*fn->clk) (false, true, cookie);
386 (*fn->wr) ((val & 0x80), true, cookie);
388 /* Assert the clock */
389 (*fn->clk) (true, true, cookie);
395 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
396 if (bytecount % (bsize / 40) == 0)
397 putc ('.'); /* let them know we are alive */
404 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
405 putc ('\n'); /* terminate the dotted line */
408 /* now check for done signal */
409 ts = get_timer (0); /* get current time */
410 ret_val = FPGA_SUCCESS;
411 (*fn->wr) (true, true, cookie);
413 while (! (*fn->done) (cookie)) {
414 /* XXX - we should have a check in here somewhere to
415 * make sure we aren't busy forever... */
418 (*fn->clk) (false, true, cookie); /* Deassert the clock pin */
420 (*fn->clk) (true, true, cookie); /* Assert the clock pin */
424 if (get_timer (ts) > CFG_SYS_FPGA_WAIT) { /* check the time */
425 puts ("** Timeout waiting for DONE to clear.\n");
430 putc ('\n'); /* terminate the dotted line */
433 * Run the post configuration function if there is one.
436 (*fn->post) (cookie);
438 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
439 if (ret_val == FPGA_SUCCESS)
446 printf ("%s: NULL Interface function table!\n", __FUNCTION__);
452 static int spartan3_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize)
454 /* Readback is only available through the Slave Parallel and */
455 /* boundary-scan interfaces. */
456 printf ("%s: Slave Serial Dumping is unavailable\n",
461 struct xilinx_fpga_op spartan3_op = {
462 .load = spartan3_load,
463 .dump = spartan3_dump,
464 .info = spartan3_info,