3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
4 * Keith Outwater, keith_outwater@mvis.com
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * Configuration support for Xilinx Virtex2 devices. Based
28 * on spartan2.c (Rich Ireland, rireland@enterasys.com).
39 #define PRINTF(fmt,args...) printf (fmt ,##args)
41 #define PRINTF(fmt,args...)
45 * If the SelectMap interface can be overrun by the processor, define
46 * CONFIG_SYS_FPGA_CHECK_BUSY and/or CONFIG_FPGA_DELAY in the board configuration
47 * file and add board-specific support for checking BUSY status. By default,
48 * assume that the SelectMap interface cannot be overrun.
50 #ifndef CONFIG_SYS_FPGA_CHECK_BUSY
51 #undef CONFIG_SYS_FPGA_CHECK_BUSY
54 #ifndef CONFIG_FPGA_DELAY
55 #define CONFIG_FPGA_DELAY()
58 #ifndef CONFIG_SYS_FPGA_PROG_FEEDBACK
59 #define CONFIG_SYS_FPGA_PROG_FEEDBACK
63 * Don't allow config cycle to be interrupted
65 #ifndef CONFIG_SYS_FPGA_CHECK_CTRLC
66 #undef CONFIG_SYS_FPGA_CHECK_CTRLC
70 * Check for errors during configuration by default
72 #ifndef CONFIG_SYS_FPGA_CHECK_ERROR
73 #define CONFIG_SYS_FPGA_CHECK_ERROR
77 * The default timeout in mS for INIT_B to deassert after PROG_B has
78 * been deasserted. Per the latest Virtex II Handbook (page 347), the
79 * max time from PORG_B deassertion to INIT_B deassertion is 4uS per
80 * data frame for the XC2V8000. The XC2V8000 has 2860 data frames
81 * which yields 11.44 mS. So let's make it bigger in order to handle
82 * an XC2V1000, if anyone can ever get ahold of one.
84 #ifndef CONFIG_SYS_FPGA_WAIT_INIT
85 #define CONFIG_SYS_FPGA_WAIT_INIT CONFIG_SYS_HZ/2 /* 500 ms */
89 * The default timeout for waiting for BUSY to deassert during configuration.
90 * This is normally not necessary since for most reasonable configuration
91 * clock frequencies (i.e. 66 MHz or less), BUSY monitoring is unnecessary.
93 #ifndef CONFIG_SYS_FPGA_WAIT_BUSY
94 #define CONFIG_SYS_FPGA_WAIT_BUSY CONFIG_SYS_HZ/200 /* 5 ms*/
97 /* Default timeout for waiting for FPGA to enter operational mode after
98 * configuration data has been written.
100 #ifndef CONFIG_SYS_FPGA_WAIT_CONFIG
101 #define CONFIG_SYS_FPGA_WAIT_CONFIG CONFIG_SYS_HZ/5 /* 200 ms */
104 static int Virtex2_ssm_load (Xilinx_desc * desc, void *buf, size_t bsize);
105 static int Virtex2_ssm_dump (Xilinx_desc * desc, void *buf, size_t bsize);
107 static int Virtex2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize);
108 static int Virtex2_ss_dump (Xilinx_desc * desc, void *buf, size_t bsize);
110 int Virtex2_load (Xilinx_desc * desc, void *buf, size_t bsize)
112 int ret_val = FPGA_FAIL;
114 switch (desc->iface) {
116 PRINTF ("%s: Launching Slave Serial Load\n", __FUNCTION__);
117 ret_val = Virtex2_ss_load (desc, buf, bsize);
120 case slave_selectmap:
121 PRINTF ("%s: Launching Slave Parallel Load\n", __FUNCTION__);
122 ret_val = Virtex2_ssm_load (desc, buf, bsize);
126 printf ("%s: Unsupported interface type, %d\n",
127 __FUNCTION__, desc->iface);
132 int Virtex2_dump (Xilinx_desc * desc, void *buf, size_t bsize)
134 int ret_val = FPGA_FAIL;
136 switch (desc->iface) {
138 PRINTF ("%s: Launching Slave Serial Dump\n", __FUNCTION__);
139 ret_val = Virtex2_ss_dump (desc, buf, bsize);
143 PRINTF ("%s: Launching Slave Parallel Dump\n", __FUNCTION__);
144 ret_val = Virtex2_ssm_dump (desc, buf, bsize);
148 printf ("%s: Unsupported interface type, %d\n",
149 __FUNCTION__, desc->iface);
154 int Virtex2_info (Xilinx_desc * desc)
160 * Virtex-II Slave SelectMap configuration loader. Configuration via
161 * SelectMap is as follows:
162 * 1. Set the FPGA's PROG_B line low.
163 * 2. Set the FPGA's PROG_B line high. Wait for INIT_B to go high.
164 * 3. Write data to the SelectMap port. If INIT_B goes low at any time
165 * this process, a configuration error (most likely CRC failure) has
166 * ocurred. At this point a status word may be read from the
167 * SelectMap interface to determine the source of the problem (You
168 * could, for instance, put this in your 'abort' function handler).
169 * 4. After all data has been written, test the state of the FPGA
170 * INIT_B and DONE lines. If both are high, configuration has
171 * succeeded. Congratulations!
173 static int Virtex2_ssm_load (Xilinx_desc * desc, void *buf, size_t bsize)
175 int ret_val = FPGA_FAIL;
176 Xilinx_Virtex2_Slave_SelectMap_fns *fn = desc->iface_fns;
178 PRINTF ("%s:%d: Start with interface functions @ 0x%p\n",
179 __FUNCTION__, __LINE__, fn);
182 size_t bytecount = 0;
183 unsigned char *data = (unsigned char *) buf;
184 int cookie = desc->cookie;
187 /* Gotta split this one up (so the stack won't blow??) */
188 PRINTF ("%s:%d: Function Table:\n"
195 __FUNCTION__, __LINE__,
196 &fn, fn, fn->pre, fn->pgm, fn->init, fn->err);
197 PRINTF (" clock 0x%p\n"
205 fn->clk, fn->cs, fn->wr, fn->rdata, fn->wdata,
206 fn->busy, fn->abort, fn->post);
208 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
209 printf ("Initializing FPGA Device %d...\n", cookie);
212 * Run the pre configuration function if there is one.
219 * Assert the program line. The minimum pulse width for
220 * Virtex II devices is 300 nS (Tprogram parameter in datasheet).
221 * There is no maximum value for the pulse width. Check to make
222 * sure that INIT_B goes low after assertion of PROG_B
224 (*fn->pgm) (TRUE, TRUE, cookie);
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);
235 } while (!(*fn->init) (cookie));
237 (*fn->pgm) (FALSE, TRUE, cookie);
238 CONFIG_FPGA_DELAY ();
239 (*fn->clk) (TRUE, TRUE, cookie);
242 * Start a timer and wait for INIT_B to go high
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);
254 } while ((*fn->init) (cookie) && (*fn->busy) (cookie));
256 (*fn->wr) (TRUE, TRUE, cookie);
257 (*fn->cs) (TRUE, TRUE, cookie);
262 * Load the data byte by byte
264 while (bytecount < bsize) {
265 #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC
267 (*fn->abort) (cookie);
272 if ((*fn->done) (cookie) == FPGA_SUCCESS) {
273 PRINTF ("%s:%d:done went active early, bytecount = %d\n",
274 __FUNCTION__, __LINE__, bytecount);
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",
284 (*fn->abort) (cookie);
289 (*fn->wdata) (data[bytecount++], TRUE, cookie);
290 CONFIG_FPGA_DELAY ();
293 * Cycle the clock pin
295 (*fn->clk) (FALSE, TRUE, cookie);
296 CONFIG_FPGA_DELAY ();
297 (*fn->clk) (TRUE, TRUE, cookie);
299 #ifdef CONFIG_SYS_FPGA_CHECK_BUSY
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);
312 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
313 if (bytecount % (bsize / 40) == 0)
319 * Finished writing the data; deassert FPGA CS_B and WRITE_B signals.
321 CONFIG_FPGA_DELAY ();
322 (*fn->cs) (FALSE, TRUE, cookie);
323 (*fn->wr) (FALSE, TRUE, cookie);
325 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
330 * Check for successful configuration. FPGA INIT_B and DONE should
331 * both be high upon successful configuration.
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);
346 if (ret_val == FPGA_SUCCESS) {
347 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
348 printf ("Initialization of FPGA device %d complete\n", cookie);
351 * Run the post configuration function if there is one.
354 (*fn->post) (cookie);
357 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
358 printf ("** Initialization of FPGA device %d FAILED\n",
363 printf ("%s:%d: NULL Interface function table!\n",
364 __FUNCTION__, __LINE__);
370 * Read the FPGA configuration data
372 static int Virtex2_ssm_dump (Xilinx_desc * desc, void *buf, size_t bsize)
374 int ret_val = FPGA_FAIL;
375 Xilinx_Virtex2_Slave_SelectMap_fns *fn = desc->iface_fns;
378 unsigned char *data = (unsigned char *) buf;
379 size_t bytecount = 0;
380 int cookie = desc->cookie;
382 printf ("Starting Dump of FPGA Device %d...\n", cookie);
384 (*fn->cs) (TRUE, TRUE, cookie);
385 (*fn->clk) (TRUE, TRUE, cookie);
387 while (bytecount < bsize) {
388 #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC
390 (*fn->abort) (cookie);
395 * Cycle the clock and read the data
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)
407 * Deassert CS_B and cycle the clock to deselect the device.
409 (*fn->cs) (FALSE, FALSE, cookie);
410 (*fn->clk) (FALSE, TRUE, cookie);
411 (*fn->clk) (TRUE, TRUE, cookie);
413 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
418 printf ("%s:%d: NULL Interface function table!\n",
419 __FUNCTION__, __LINE__);
424 static int Virtex2_ss_load (Xilinx_desc * desc, void *buf, size_t bsize)
426 printf ("%s: Slave Serial Loading is unsupported\n", __FUNCTION__);
430 static int Virtex2_ss_dump (Xilinx_desc * desc, void *buf, size_t bsize)
432 printf ("%s: Slave Serial Dumping is unsupported\n", __FUNCTION__);
436 /* vim: set ts=4 tw=78: */