wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
| 4 | * Keith Outwater, keith_outwater@mvis.com |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Configuration support for Xilinx Virtex2 devices. Based |
| 11 | * on spartan2.c (Rich Ireland, rireland@enterasys.com). |
| 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 15 | #include <console.h> |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 16 | #include <virtex2.h> |
| 17 | |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 18 | #if 0 |
| 19 | #define FPGA_DEBUG |
Wolfgang Denk | 0cbaf64 | 2005-09-25 00:53:22 +0200 | [diff] [blame] | 20 | #endif |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 21 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 22 | #ifdef FPGA_DEBUG |
| 23 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 24 | #else |
| 25 | #define PRINTF(fmt,args...) |
| 26 | #endif |
| 27 | |
| 28 | /* |
| 29 | * If the SelectMap interface can be overrun by the processor, define |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 30 | * CONFIG_SYS_FPGA_CHECK_BUSY and/or CONFIG_FPGA_DELAY in the board configuration |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 31 | * file and add board-specific support for checking BUSY status. By default, |
| 32 | * assume that the SelectMap interface cannot be overrun. |
| 33 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 34 | #ifndef CONFIG_SYS_FPGA_CHECK_BUSY |
| 35 | #undef CONFIG_SYS_FPGA_CHECK_BUSY |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 36 | #endif |
| 37 | |
| 38 | #ifndef CONFIG_FPGA_DELAY |
| 39 | #define CONFIG_FPGA_DELAY() |
| 40 | #endif |
| 41 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | #ifndef CONFIG_SYS_FPGA_PROG_FEEDBACK |
| 43 | #define CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 44 | #endif |
| 45 | |
| 46 | /* |
| 47 | * Don't allow config cycle to be interrupted |
| 48 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | #ifndef CONFIG_SYS_FPGA_CHECK_CTRLC |
| 50 | #undef CONFIG_SYS_FPGA_CHECK_CTRLC |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | /* |
| 54 | * Check for errors during configuration by default |
| 55 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 56 | #ifndef CONFIG_SYS_FPGA_CHECK_ERROR |
| 57 | #define CONFIG_SYS_FPGA_CHECK_ERROR |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
| 60 | /* |
| 61 | * The default timeout in mS for INIT_B to deassert after PROG_B has |
| 62 | * been deasserted. Per the latest Virtex II Handbook (page 347), the |
| 63 | * max time from PORG_B deassertion to INIT_B deassertion is 4uS per |
| 64 | * data frame for the XC2V8000. The XC2V8000 has 2860 data frames |
| 65 | * which yields 11.44 mS. So let's make it bigger in order to handle |
| 66 | * an XC2V1000, if anyone can ever get ahold of one. |
| 67 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 68 | #ifndef CONFIG_SYS_FPGA_WAIT_INIT |
| 69 | #define CONFIG_SYS_FPGA_WAIT_INIT CONFIG_SYS_HZ/2 /* 500 ms */ |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | /* |
| 73 | * The default timeout for waiting for BUSY to deassert during configuration. |
| 74 | * This is normally not necessary since for most reasonable configuration |
| 75 | * clock frequencies (i.e. 66 MHz or less), BUSY monitoring is unnecessary. |
| 76 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 77 | #ifndef CONFIG_SYS_FPGA_WAIT_BUSY |
| 78 | #define CONFIG_SYS_FPGA_WAIT_BUSY CONFIG_SYS_HZ/200 /* 5 ms*/ |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 79 | #endif |
| 80 | |
| 81 | /* Default timeout for waiting for FPGA to enter operational mode after |
| 82 | * configuration data has been written. |
| 83 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 84 | #ifndef CONFIG_SYS_FPGA_WAIT_CONFIG |
| 85 | #define CONFIG_SYS_FPGA_WAIT_CONFIG CONFIG_SYS_HZ/5 /* 200 ms */ |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 86 | #endif |
| 87 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 88 | static int virtex2_ssm_load(xilinx_desc *desc, const void *buf, size_t bsize); |
| 89 | static int virtex2_ssm_dump(xilinx_desc *desc, const void *buf, size_t bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 90 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 91 | static int virtex2_ss_load(xilinx_desc *desc, const void *buf, size_t bsize); |
| 92 | static int virtex2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 93 | |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 94 | static int virtex2_load(xilinx_desc *desc, const void *buf, size_t bsize, |
| 95 | bitstream_type bstype) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 96 | { |
| 97 | int ret_val = FPGA_FAIL; |
| 98 | |
| 99 | switch (desc->iface) { |
| 100 | case slave_serial: |
| 101 | PRINTF ("%s: Launching Slave Serial Load\n", __FUNCTION__); |
Michal Simek | 9025888 | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 102 | ret_val = virtex2_ss_load(desc, buf, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 103 | break; |
| 104 | |
| 105 | case slave_selectmap: |
| 106 | PRINTF ("%s: Launching Slave Parallel Load\n", __FUNCTION__); |
Michal Simek | 9025888 | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 107 | ret_val = virtex2_ssm_load(desc, buf, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 108 | break; |
| 109 | |
| 110 | default: |
| 111 | printf ("%s: Unsupported interface type, %d\n", |
| 112 | __FUNCTION__, desc->iface); |
| 113 | } |
| 114 | return ret_val; |
| 115 | } |
| 116 | |
Michal Simek | 75fafac | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 117 | static int virtex2_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 118 | { |
| 119 | int ret_val = FPGA_FAIL; |
| 120 | |
| 121 | switch (desc->iface) { |
| 122 | case slave_serial: |
| 123 | PRINTF ("%s: Launching Slave Serial Dump\n", __FUNCTION__); |
Michal Simek | 9025888 | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 124 | ret_val = virtex2_ss_dump(desc, buf, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 125 | break; |
| 126 | |
| 127 | case slave_parallel: |
| 128 | PRINTF ("%s: Launching Slave Parallel Dump\n", __FUNCTION__); |
Michal Simek | 9025888 | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 129 | ret_val = virtex2_ssm_dump(desc, buf, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 130 | break; |
| 131 | |
| 132 | default: |
| 133 | printf ("%s: Unsupported interface type, %d\n", |
| 134 | __FUNCTION__, desc->iface); |
| 135 | } |
| 136 | return ret_val; |
| 137 | } |
| 138 | |
Michal Simek | 75fafac | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 139 | static int virtex2_info(xilinx_desc *desc) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 140 | { |
| 141 | return FPGA_SUCCESS; |
| 142 | } |
| 143 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 144 | /* |
| 145 | * Virtex-II Slave SelectMap configuration loader. Configuration via |
| 146 | * SelectMap is as follows: |
| 147 | * 1. Set the FPGA's PROG_B line low. |
| 148 | * 2. Set the FPGA's PROG_B line high. Wait for INIT_B to go high. |
| 149 | * 3. Write data to the SelectMap port. If INIT_B goes low at any time |
| 150 | * this process, a configuration error (most likely CRC failure) has |
| 151 | * ocurred. At this point a status word may be read from the |
| 152 | * SelectMap interface to determine the source of the problem (You |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 153 | * could, for instance, put this in your 'abort' function handler). |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 154 | * 4. After all data has been written, test the state of the FPGA |
| 155 | * INIT_B and DONE lines. If both are high, configuration has |
| 156 | * succeeded. Congratulations! |
| 157 | */ |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 158 | static int virtex2_ssm_load(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 159 | { |
| 160 | int ret_val = FPGA_FAIL; |
Michal Simek | 9025888 | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 161 | xilinx_virtex2_slave_selectmap_fns *fn = desc->iface_fns; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 162 | |
| 163 | PRINTF ("%s:%d: Start with interface functions @ 0x%p\n", |
| 164 | __FUNCTION__, __LINE__, fn); |
| 165 | |
| 166 | if (fn) { |
| 167 | size_t bytecount = 0; |
| 168 | unsigned char *data = (unsigned char *) buf; |
| 169 | int cookie = desc->cookie; |
| 170 | unsigned long ts; |
| 171 | |
| 172 | /* Gotta split this one up (so the stack won't blow??) */ |
| 173 | PRINTF ("%s:%d: Function Table:\n" |
| 174 | " base 0x%p\n" |
| 175 | " struct 0x%p\n" |
| 176 | " pre 0x%p\n" |
| 177 | " prog 0x%p\n" |
| 178 | " init 0x%p\n" |
| 179 | " error 0x%p\n", |
| 180 | __FUNCTION__, __LINE__, |
| 181 | &fn, fn, fn->pre, fn->pgm, fn->init, fn->err); |
| 182 | PRINTF (" clock 0x%p\n" |
| 183 | " cs 0x%p\n" |
| 184 | " write 0x%p\n" |
| 185 | " rdata 0x%p\n" |
| 186 | " wdata 0x%p\n" |
| 187 | " busy 0x%p\n" |
| 188 | " abort 0x%p\n" |
| 189 | " post 0x%p\n\n", |
| 190 | fn->clk, fn->cs, fn->wr, fn->rdata, fn->wdata, |
| 191 | fn->busy, fn->abort, fn->post); |
| 192 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 193 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 194 | printf ("Initializing FPGA Device %d...\n", cookie); |
| 195 | #endif |
| 196 | /* |
| 197 | * Run the pre configuration function if there is one. |
| 198 | */ |
| 199 | if (*fn->pre) { |
| 200 | (*fn->pre) (cookie); |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * Assert the program line. The minimum pulse width for |
| 205 | * Virtex II devices is 300 nS (Tprogram parameter in datasheet). |
| 206 | * There is no maximum value for the pulse width. Check to make |
| 207 | * sure that INIT_B goes low after assertion of PROG_B |
| 208 | */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 209 | (*fn->pgm) (true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 210 | udelay (10); |
| 211 | ts = get_timer (0); |
| 212 | do { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 213 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT_INIT) { |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 214 | printf ("%s:%d: ** Timeout after %d ticks waiting for INIT" |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 215 | " to assert.\n", __FUNCTION__, __LINE__, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 216 | CONFIG_SYS_FPGA_WAIT_INIT); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 217 | (*fn->abort) (cookie); |
| 218 | return FPGA_FAIL; |
| 219 | } |
| 220 | } while (!(*fn->init) (cookie)); |
| 221 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 222 | (*fn->pgm) (false, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 223 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 224 | (*fn->clk) (true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * Start a timer and wait for INIT_B to go high |
| 228 | */ |
| 229 | ts = get_timer (0); |
| 230 | do { |
| 231 | CONFIG_FPGA_DELAY (); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 232 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT_INIT) { |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 233 | printf ("%s:%d: ** Timeout after %d ticks waiting for INIT" |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 234 | " to deassert.\n", __FUNCTION__, __LINE__, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 235 | CONFIG_SYS_FPGA_WAIT_INIT); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 236 | (*fn->abort) (cookie); |
| 237 | return FPGA_FAIL; |
| 238 | } |
| 239 | } while ((*fn->init) (cookie) && (*fn->busy) (cookie)); |
| 240 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 241 | (*fn->wr) (true, true, cookie); |
| 242 | (*fn->cs) (true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 243 | |
| 244 | udelay (10000); |
| 245 | |
| 246 | /* |
| 247 | * Load the data byte by byte |
| 248 | */ |
| 249 | while (bytecount < bsize) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 250 | #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 251 | if (ctrlc ()) { |
| 252 | (*fn->abort) (cookie); |
| 253 | return FPGA_FAIL; |
| 254 | } |
| 255 | #endif |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 256 | |
| 257 | if ((*fn->done) (cookie) == FPGA_SUCCESS) { |
| 258 | PRINTF ("%s:%d:done went active early, bytecount = %d\n", |
| 259 | __FUNCTION__, __LINE__, bytecount); |
| 260 | break; |
| 261 | } |
| 262 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 263 | #ifdef CONFIG_SYS_FPGA_CHECK_ERROR |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 264 | if ((*fn->init) (cookie)) { |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 265 | printf ("\n%s:%d: ** Error: INIT asserted during" |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 266 | " configuration\n", __FUNCTION__, __LINE__); |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 267 | printf ("%d = buffer offset, %d = buffer size\n", |
| 268 | bytecount, bsize); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 269 | (*fn->abort) (cookie); |
| 270 | return FPGA_FAIL; |
| 271 | } |
| 272 | #endif |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 273 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 274 | (*fn->wdata) (data[bytecount++], true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 275 | CONFIG_FPGA_DELAY (); |
| 276 | |
| 277 | /* |
| 278 | * Cycle the clock pin |
| 279 | */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 280 | (*fn->clk) (false, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 281 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 282 | (*fn->clk) (true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 283 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 284 | #ifdef CONFIG_SYS_FPGA_CHECK_BUSY |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 285 | ts = get_timer (0); |
| 286 | while ((*fn->busy) (cookie)) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 287 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT_BUSY) { |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 288 | printf ("%s:%d: ** Timeout after %d ticks waiting for" |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 289 | " BUSY to deassert\n", |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 290 | __FUNCTION__, __LINE__, CONFIG_SYS_FPGA_WAIT_BUSY); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 291 | (*fn->abort) (cookie); |
| 292 | return FPGA_FAIL; |
| 293 | } |
| 294 | } |
| 295 | #endif |
| 296 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 297 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 298 | if (bytecount % (bsize / 40) == 0) |
| 299 | putc ('.'); |
| 300 | #endif |
| 301 | } |
| 302 | |
| 303 | /* |
| 304 | * Finished writing the data; deassert FPGA CS_B and WRITE_B signals. |
| 305 | */ |
| 306 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 307 | (*fn->cs) (false, true, cookie); |
| 308 | (*fn->wr) (false, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 309 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 310 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 311 | putc ('\n'); |
| 312 | #endif |
| 313 | |
| 314 | /* |
| 315 | * Check for successful configuration. FPGA INIT_B and DONE should |
| 316 | * both be high upon successful configuration. |
| 317 | */ |
| 318 | ts = get_timer (0); |
| 319 | ret_val = FPGA_SUCCESS; |
| 320 | while (((*fn->done) (cookie) == FPGA_FAIL) || (*fn->init) (cookie)) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 321 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT_CONFIG) { |
Wolfgang Denk | ffb7756 | 2005-09-24 23:41:00 +0200 | [diff] [blame] | 322 | printf ("%s:%d: ** Timeout after %d ticks waiting for DONE to" |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 323 | "assert and INIT to deassert\n", |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 324 | __FUNCTION__, __LINE__, CONFIG_SYS_FPGA_WAIT_CONFIG); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 325 | (*fn->abort) (cookie); |
| 326 | ret_val = FPGA_FAIL; |
| 327 | break; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | if (ret_val == FPGA_SUCCESS) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 332 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 333 | printf ("Initialization of FPGA device %d complete\n", cookie); |
| 334 | #endif |
| 335 | /* |
| 336 | * Run the post configuration function if there is one. |
| 337 | */ |
| 338 | if (*fn->post) { |
| 339 | (*fn->post) (cookie); |
| 340 | } |
| 341 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 342 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 343 | printf ("** Initialization of FPGA device %d FAILED\n", |
| 344 | cookie); |
| 345 | #endif |
| 346 | } |
| 347 | } else { |
| 348 | printf ("%s:%d: NULL Interface function table!\n", |
| 349 | __FUNCTION__, __LINE__); |
| 350 | } |
| 351 | return ret_val; |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | * Read the FPGA configuration data |
| 356 | */ |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 357 | static int virtex2_ssm_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 358 | { |
| 359 | int ret_val = FPGA_FAIL; |
Michal Simek | 9025888 | 2014-03-13 11:33:36 +0100 | [diff] [blame] | 360 | xilinx_virtex2_slave_selectmap_fns *fn = desc->iface_fns; |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 361 | |
| 362 | if (fn) { |
| 363 | unsigned char *data = (unsigned char *) buf; |
| 364 | size_t bytecount = 0; |
| 365 | int cookie = desc->cookie; |
| 366 | |
| 367 | printf ("Starting Dump of FPGA Device %d...\n", cookie); |
| 368 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 369 | (*fn->cs) (true, true, cookie); |
| 370 | (*fn->clk) (true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 371 | |
| 372 | while (bytecount < bsize) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 373 | #ifdef CONFIG_SYS_FPGA_CHECK_CTRLC |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 374 | if (ctrlc ()) { |
| 375 | (*fn->abort) (cookie); |
| 376 | return FPGA_FAIL; |
| 377 | } |
| 378 | #endif |
| 379 | /* |
| 380 | * Cycle the clock and read the data |
| 381 | */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 382 | (*fn->clk) (false, true, cookie); |
| 383 | (*fn->clk) (true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 384 | (*fn->rdata) (&(data[bytecount++]), cookie); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 385 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 386 | if (bytecount % (bsize / 40) == 0) |
| 387 | putc ('.'); |
| 388 | #endif |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | * Deassert CS_B and cycle the clock to deselect the device. |
| 393 | */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 394 | (*fn->cs) (false, false, cookie); |
| 395 | (*fn->clk) (false, true, cookie); |
| 396 | (*fn->clk) (true, true, cookie); |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 397 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 398 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 399 | putc ('\n'); |
| 400 | #endif |
| 401 | puts ("Done.\n"); |
| 402 | } else { |
| 403 | printf ("%s:%d: NULL Interface function table!\n", |
| 404 | __FUNCTION__, __LINE__); |
| 405 | } |
| 406 | return ret_val; |
| 407 | } |
| 408 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 409 | static int virtex2_ss_load(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 410 | { |
| 411 | printf ("%s: Slave Serial Loading is unsupported\n", __FUNCTION__); |
| 412 | return FPGA_FAIL; |
| 413 | } |
| 414 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 415 | static int virtex2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 416 | { |
| 417 | printf ("%s: Slave Serial Dumping is unsupported\n", __FUNCTION__); |
| 418 | return FPGA_FAIL; |
| 419 | } |
| 420 | |
wdenk | 5d3207d | 2002-08-21 22:08:56 +0000 | [diff] [blame] | 421 | /* vim: set ts=4 tw=78: */ |
Michal Simek | 75fafac | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 422 | |
| 423 | struct xilinx_fpga_op virtex2_op = { |
| 424 | .load = virtex2_load, |
| 425 | .dump = virtex2_dump, |
| 426 | .info = virtex2_info, |
| 427 | }; |