Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 |
| 4 | * Rich Ireland, Enterasys Networks, rireland@enterasys.com. |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> /* core U-Boot definitions */ |
| 8 | #include <spartan2.h> /* Spartan-II device family */ |
| 9 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 10 | /* Define FPGA_DEBUG to get debug printf's */ |
| 11 | #ifdef FPGA_DEBUG |
| 12 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 13 | #else |
| 14 | #define PRINTF(fmt,args...) |
| 15 | #endif |
| 16 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 17 | #undef CONFIG_SYS_FPGA_CHECK_BUSY |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 18 | |
| 19 | /* Note: The assumption is that we cannot possibly run fast enough to |
| 20 | * overrun the device (the Slave Parallel mode can free run at 50MHz). |
| 21 | * If there is a need to operate slower, define CONFIG_FPGA_DELAY in |
| 22 | * the board config file to slow things down. |
| 23 | */ |
| 24 | #ifndef CONFIG_FPGA_DELAY |
| 25 | #define CONFIG_FPGA_DELAY() |
| 26 | #endif |
| 27 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 28 | #ifndef CONFIG_SYS_FPGA_WAIT |
| 29 | #define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/100 /* 10 ms */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 30 | #endif |
| 31 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 32 | static int spartan2_sp_load(xilinx_desc *desc, const void *buf, size_t bsize); |
| 33 | static int spartan2_sp_dump(xilinx_desc *desc, const void *buf, size_t bsize); |
| 34 | /* static int spartan2_sp_info(xilinx_desc *desc ); */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 35 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 36 | static int spartan2_ss_load(xilinx_desc *desc, const void *buf, size_t bsize); |
| 37 | static int spartan2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize); |
| 38 | /* static int spartan2_ss_info(xilinx_desc *desc ); */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 39 | |
| 40 | /* ------------------------------------------------------------------------- */ |
| 41 | /* Spartan-II Generic Implementation */ |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 42 | static int spartan2_load(xilinx_desc *desc, const void *buf, size_t bsize, |
Oleksandr Suvorov | c0806cc | 2022-07-22 17:16:10 +0300 | [diff] [blame] | 43 | bitstream_type bstype, int flags) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 44 | { |
| 45 | int ret_val = FPGA_FAIL; |
| 46 | |
| 47 | switch (desc->iface) { |
| 48 | case slave_serial: |
| 49 | PRINTF ("%s: Launching Slave Serial Load\n", __FUNCTION__); |
Michal Simek | 5206cca | 2014-03-13 11:23:43 +0100 | [diff] [blame] | 50 | ret_val = spartan2_ss_load(desc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 51 | break; |
| 52 | |
| 53 | case slave_parallel: |
| 54 | PRINTF ("%s: Launching Slave Parallel Load\n", __FUNCTION__); |
Michal Simek | 5206cca | 2014-03-13 11:23:43 +0100 | [diff] [blame] | 55 | ret_val = spartan2_sp_load(desc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 56 | break; |
| 57 | |
| 58 | default: |
| 59 | printf ("%s: Unsupported interface type, %d\n", |
| 60 | __FUNCTION__, desc->iface); |
| 61 | } |
| 62 | |
| 63 | return ret_val; |
| 64 | } |
| 65 | |
Michal Simek | 75fafac | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 66 | static int spartan2_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 67 | { |
| 68 | int ret_val = FPGA_FAIL; |
| 69 | |
| 70 | switch (desc->iface) { |
| 71 | case slave_serial: |
| 72 | PRINTF ("%s: Launching Slave Serial Dump\n", __FUNCTION__); |
Michal Simek | 5206cca | 2014-03-13 11:23:43 +0100 | [diff] [blame] | 73 | ret_val = spartan2_ss_dump(desc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 74 | break; |
| 75 | |
| 76 | case slave_parallel: |
| 77 | PRINTF ("%s: Launching Slave Parallel Dump\n", __FUNCTION__); |
Michal Simek | 5206cca | 2014-03-13 11:23:43 +0100 | [diff] [blame] | 78 | ret_val = spartan2_sp_dump(desc, buf, bsize); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 79 | break; |
| 80 | |
| 81 | default: |
| 82 | printf ("%s: Unsupported interface type, %d\n", |
| 83 | __FUNCTION__, desc->iface); |
| 84 | } |
| 85 | |
| 86 | return ret_val; |
| 87 | } |
| 88 | |
Michal Simek | 75fafac | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 89 | static int spartan2_info(xilinx_desc *desc) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 90 | { |
| 91 | return FPGA_SUCCESS; |
| 92 | } |
| 93 | |
| 94 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 95 | /* ------------------------------------------------------------------------- */ |
| 96 | /* Spartan-II Slave Parallel Generic Implementation */ |
| 97 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 98 | static int spartan2_sp_load(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 99 | { |
| 100 | int ret_val = FPGA_FAIL; /* assume the worst */ |
Michal Simek | 5206cca | 2014-03-13 11:23:43 +0100 | [diff] [blame] | 101 | xilinx_spartan2_slave_parallel_fns *fn = desc->iface_fns; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 102 | |
| 103 | PRINTF ("%s: start with interface functions @ 0x%p\n", |
| 104 | __FUNCTION__, fn); |
| 105 | |
| 106 | if (fn) { |
| 107 | size_t bytecount = 0; |
| 108 | unsigned char *data = (unsigned char *) buf; |
| 109 | int cookie = desc->cookie; /* make a local copy */ |
| 110 | unsigned long ts; /* timestamp */ |
| 111 | |
| 112 | PRINTF ("%s: Function Table:\n" |
| 113 | "ptr:\t0x%p\n" |
| 114 | "struct: 0x%p\n" |
| 115 | "pre: 0x%p\n" |
| 116 | "pgm:\t0x%p\n" |
| 117 | "init:\t0x%p\n" |
| 118 | "err:\t0x%p\n" |
| 119 | "clk:\t0x%p\n" |
| 120 | "cs:\t0x%p\n" |
| 121 | "wr:\t0x%p\n" |
| 122 | "read data:\t0x%p\n" |
| 123 | "write data:\t0x%p\n" |
| 124 | "busy:\t0x%p\n" |
| 125 | "abort:\t0x%p\n", |
| 126 | "post:\t0x%p\n\n", |
| 127 | __FUNCTION__, &fn, fn, fn->pre, fn->pgm, fn->init, fn->err, |
| 128 | fn->clk, fn->cs, fn->wr, fn->rdata, fn->wdata, fn->busy, |
| 129 | fn->abort, fn->post); |
| 130 | |
| 131 | /* |
| 132 | * This code is designed to emulate the "Express Style" |
| 133 | * Continuous Data Loading in Slave Parallel Mode for |
| 134 | * the Spartan-II Family. |
| 135 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 136 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 137 | printf ("Loading FPGA Device %d...\n", cookie); |
| 138 | #endif |
| 139 | /* |
| 140 | * Run the pre configuration function if there is one. |
| 141 | */ |
| 142 | if (*fn->pre) { |
| 143 | (*fn->pre) (cookie); |
| 144 | } |
| 145 | |
| 146 | /* Establish the initial state */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 147 | (*fn->pgm) (true, true, cookie); /* Assert the program, commit */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 148 | |
| 149 | /* Get ready for the burn */ |
| 150 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 151 | (*fn->pgm) (false, true, cookie); /* Deassert the program, commit */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 152 | |
| 153 | ts = get_timer (0); /* get current time */ |
| 154 | /* Now wait for INIT and BUSY to go high */ |
| 155 | do { |
| 156 | CONFIG_FPGA_DELAY (); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 157 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) { /* check the time */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 158 | puts ("** Timeout waiting for INIT to clear.\n"); |
| 159 | (*fn->abort) (cookie); /* abort the burn */ |
| 160 | return FPGA_FAIL; |
| 161 | } |
| 162 | } while ((*fn->init) (cookie) && (*fn->busy) (cookie)); |
| 163 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 164 | (*fn->wr) (true, true, cookie); /* Assert write, commit */ |
| 165 | (*fn->cs) (true, true, cookie); /* Assert chip select, commit */ |
| 166 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 167 | |
| 168 | /* Load the data */ |
| 169 | while (bytecount < bsize) { |
| 170 | /* XXX - do we check for an Ctrl-C press in here ??? */ |
| 171 | /* XXX - Check the error bit? */ |
| 172 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 173 | (*fn->wdata) (data[bytecount++], true, cookie); /* write the data */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 174 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 175 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 176 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 177 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 178 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 179 | #ifdef CONFIG_SYS_FPGA_CHECK_BUSY |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 180 | ts = get_timer (0); /* get current time */ |
| 181 | while ((*fn->busy) (cookie)) { |
| 182 | /* XXX - we should have a check in here somewhere to |
| 183 | * make sure we aren't busy forever... */ |
| 184 | |
| 185 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 186 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 187 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 188 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 189 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 190 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) { /* check the time */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 191 | puts ("** Timeout waiting for BUSY to clear.\n"); |
| 192 | (*fn->abort) (cookie); /* abort the burn */ |
| 193 | return FPGA_FAIL; |
| 194 | } |
| 195 | } |
| 196 | #endif |
| 197 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 198 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 199 | if (bytecount % (bsize / 40) == 0) |
| 200 | putc ('.'); /* let them know we are alive */ |
| 201 | #endif |
| 202 | } |
| 203 | |
| 204 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 205 | (*fn->cs) (false, true, cookie); /* Deassert the chip select */ |
| 206 | (*fn->wr) (false, true, cookie); /* Deassert the write pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 207 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 208 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 209 | putc ('\n'); /* terminate the dotted line */ |
| 210 | #endif |
| 211 | |
| 212 | /* now check for done signal */ |
| 213 | ts = get_timer (0); /* get current time */ |
| 214 | ret_val = FPGA_SUCCESS; |
| 215 | while ((*fn->done) (cookie) == FPGA_FAIL) { |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 216 | |
| 217 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 218 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 219 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 220 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 221 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 222 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) { /* check the time */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 223 | puts ("** Timeout waiting for DONE to clear.\n"); |
| 224 | (*fn->abort) (cookie); /* abort the burn */ |
| 225 | ret_val = FPGA_FAIL; |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 230 | /* |
| 231 | * Run the post configuration function if there is one. |
| 232 | */ |
Matthias Fuchs | f73e0ed | 2009-02-15 22:28:36 +0100 | [diff] [blame] | 233 | if (*fn->post) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 234 | (*fn->post) (cookie); |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 235 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 236 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Matthias Fuchs | f73e0ed | 2009-02-15 22:28:36 +0100 | [diff] [blame] | 237 | if (ret_val == FPGA_SUCCESS) |
| 238 | puts ("Done.\n"); |
| 239 | else |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 240 | puts ("Fail.\n"); |
| 241 | #endif |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 242 | |
| 243 | } else { |
| 244 | printf ("%s: NULL Interface function table!\n", __FUNCTION__); |
| 245 | } |
| 246 | |
| 247 | return ret_val; |
| 248 | } |
| 249 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 250 | static int spartan2_sp_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 251 | { |
| 252 | int ret_val = FPGA_FAIL; /* assume the worst */ |
Michal Simek | 5206cca | 2014-03-13 11:23:43 +0100 | [diff] [blame] | 253 | xilinx_spartan2_slave_parallel_fns *fn = desc->iface_fns; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 254 | |
| 255 | if (fn) { |
| 256 | unsigned char *data = (unsigned char *) buf; |
| 257 | size_t bytecount = 0; |
| 258 | int cookie = desc->cookie; /* make a local copy */ |
| 259 | |
| 260 | printf ("Starting Dump of FPGA Device %d...\n", cookie); |
| 261 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 262 | (*fn->cs) (true, true, cookie); /* Assert chip select, commit */ |
| 263 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 264 | |
| 265 | /* dump the data */ |
| 266 | while (bytecount < bsize) { |
| 267 | /* XXX - do we check for an Ctrl-C press in here ??? */ |
| 268 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 269 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
| 270 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 271 | (*fn->rdata) (&(data[bytecount++]), cookie); /* read the data */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 272 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 273 | if (bytecount % (bsize / 40) == 0) |
| 274 | putc ('.'); /* let them know we are alive */ |
| 275 | #endif |
| 276 | } |
| 277 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 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 */ |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 281 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 282 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 283 | putc ('\n'); /* terminate the dotted line */ |
| 284 | #endif |
| 285 | puts ("Done.\n"); |
| 286 | |
| 287 | /* XXX - checksum the data? */ |
| 288 | } else { |
| 289 | printf ("%s: NULL Interface function table!\n", __FUNCTION__); |
| 290 | } |
| 291 | |
| 292 | return ret_val; |
| 293 | } |
| 294 | |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 295 | |
| 296 | /* ------------------------------------------------------------------------- */ |
| 297 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 298 | static int spartan2_ss_load(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 299 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 300 | int ret_val = FPGA_FAIL; /* assume the worst */ |
Michal Simek | 5206cca | 2014-03-13 11:23:43 +0100 | [diff] [blame] | 301 | xilinx_spartan2_slave_serial_fns *fn = desc->iface_fns; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 302 | int i; |
Matthias Fuchs | b845b1e | 2007-12-27 17:13:05 +0100 | [diff] [blame] | 303 | unsigned char val; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 304 | |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 305 | PRINTF ("%s: start with interface functions @ 0x%p\n", |
| 306 | __FUNCTION__, fn); |
| 307 | |
| 308 | if (fn) { |
| 309 | size_t bytecount = 0; |
| 310 | unsigned char *data = (unsigned char *) buf; |
| 311 | int cookie = desc->cookie; /* make a local copy */ |
| 312 | unsigned long ts; /* timestamp */ |
| 313 | |
| 314 | PRINTF ("%s: Function Table:\n" |
| 315 | "ptr:\t0x%p\n" |
| 316 | "struct: 0x%p\n" |
| 317 | "pgm:\t0x%p\n" |
| 318 | "init:\t0x%p\n" |
| 319 | "clk:\t0x%p\n" |
| 320 | "wr:\t0x%p\n" |
| 321 | "done:\t0x%p\n\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 322 | __FUNCTION__, &fn, fn, fn->pgm, fn->init, |
| 323 | fn->clk, fn->wr, fn->done); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 324 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 325 | printf ("Loading FPGA Device %d...\n", cookie); |
| 326 | #endif |
| 327 | |
| 328 | /* |
| 329 | * Run the pre configuration function if there is one. |
| 330 | */ |
| 331 | if (*fn->pre) { |
| 332 | (*fn->pre) (cookie); |
| 333 | } |
| 334 | |
| 335 | /* Establish the initial state */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 336 | (*fn->pgm) (true, true, cookie); /* Assert the program, commit */ |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 337 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 338 | /* Wait for INIT state (init low) */ |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 339 | ts = get_timer (0); /* get current time */ |
| 340 | do { |
| 341 | CONFIG_FPGA_DELAY (); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 342 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) { /* check the time */ |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 343 | puts ("** Timeout waiting for INIT to start.\n"); |
| 344 | return FPGA_FAIL; |
| 345 | } |
| 346 | } while (!(*fn->init) (cookie)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 347 | |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 348 | /* Get ready for the burn */ |
| 349 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 350 | (*fn->pgm) (false, true, cookie); /* Deassert the program, commit */ |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 351 | |
| 352 | ts = get_timer (0); /* get current time */ |
| 353 | /* Now wait for INIT to go high */ |
| 354 | do { |
| 355 | CONFIG_FPGA_DELAY (); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 356 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) { /* check the time */ |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 357 | puts ("** Timeout waiting for INIT to clear.\n"); |
| 358 | return FPGA_FAIL; |
| 359 | } |
| 360 | } while ((*fn->init) (cookie)); |
| 361 | |
| 362 | /* Load the data */ |
| 363 | while (bytecount < bsize) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 364 | |
| 365 | /* Xilinx detects an error if INIT goes low (active) |
| 366 | while DONE is low (inactive) */ |
| 367 | if ((*fn->done) (cookie) == 0 && (*fn->init) (cookie)) { |
| 368 | puts ("** CRC error during FPGA load.\n"); |
| 369 | return (FPGA_FAIL); |
| 370 | } |
| 371 | val = data [bytecount ++]; |
| 372 | i = 8; |
| 373 | do { |
| 374 | /* Deassert the clock */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 375 | (*fn->clk) (false, true, cookie); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 376 | CONFIG_FPGA_DELAY (); |
| 377 | /* Write data */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 378 | (*fn->wr) ((val & 0x80), true, cookie); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 379 | CONFIG_FPGA_DELAY (); |
| 380 | /* Assert the clock */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 381 | (*fn->clk) (true, true, cookie); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 382 | CONFIG_FPGA_DELAY (); |
| 383 | val <<= 1; |
| 384 | i --; |
| 385 | } while (i > 0); |
| 386 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 387 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 388 | if (bytecount % (bsize / 40) == 0) |
| 389 | putc ('.'); /* let them know we are alive */ |
| 390 | #endif |
| 391 | } |
| 392 | |
| 393 | CONFIG_FPGA_DELAY (); |
| 394 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 395 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 396 | putc ('\n'); /* terminate the dotted line */ |
| 397 | #endif |
| 398 | |
| 399 | /* now check for done signal */ |
| 400 | ts = get_timer (0); /* get current time */ |
| 401 | ret_val = FPGA_SUCCESS; |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 402 | (*fn->wr) (true, true, cookie); |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 403 | |
| 404 | while (! (*fn->done) (cookie)) { |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 405 | |
| 406 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 407 | (*fn->clk) (false, true, cookie); /* Deassert the clock pin */ |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 408 | CONFIG_FPGA_DELAY (); |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 409 | (*fn->clk) (true, true, cookie); /* Assert the clock pin */ |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 410 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 411 | putc ('*'); |
| 412 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 413 | if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) { /* check the time */ |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 414 | puts ("** Timeout waiting for DONE to clear.\n"); |
| 415 | ret_val = FPGA_FAIL; |
| 416 | break; |
| 417 | } |
| 418 | } |
| 419 | putc ('\n'); /* terminate the dotted line */ |
| 420 | |
Matthias Fuchs | 518e2e14 | 2007-12-27 17:12:43 +0100 | [diff] [blame] | 421 | /* |
| 422 | * Run the post configuration function if there is one. |
| 423 | */ |
Matthias Fuchs | f73e0ed | 2009-02-15 22:28:36 +0100 | [diff] [blame] | 424 | if (*fn->post) |
Matthias Fuchs | 518e2e14 | 2007-12-27 17:12:43 +0100 | [diff] [blame] | 425 | (*fn->post) (cookie); |
Matthias Fuchs | 518e2e14 | 2007-12-27 17:12:43 +0100 | [diff] [blame] | 426 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 427 | #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK |
Matthias Fuchs | f73e0ed | 2009-02-15 22:28:36 +0100 | [diff] [blame] | 428 | if (ret_val == FPGA_SUCCESS) |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 429 | puts ("Done.\n"); |
Matthias Fuchs | f73e0ed | 2009-02-15 22:28:36 +0100 | [diff] [blame] | 430 | else |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 431 | puts ("Fail.\n"); |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 432 | #endif |
| 433 | |
| 434 | } else { |
| 435 | printf ("%s: NULL Interface function table!\n", __FUNCTION__); |
| 436 | } |
| 437 | |
| 438 | return ret_val; |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Michal Simek | 25e1e2e | 2014-03-13 12:49:21 +0100 | [diff] [blame] | 441 | static int spartan2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize) |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 442 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 443 | /* Readback is only available through the Slave Parallel and */ |
| 444 | /* boundary-scan interfaces. */ |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 445 | printf ("%s: Slave Serial Dumping is unavailable\n", |
wdenk | e221174 | 2002-11-02 23:30:20 +0000 | [diff] [blame] | 446 | __FUNCTION__); |
| 447 | return FPGA_FAIL; |
| 448 | } |
Michal Simek | 75fafac | 2014-03-13 13:07:57 +0100 | [diff] [blame] | 449 | |
| 450 | struct xilinx_fpga_op spartan2_op = { |
| 451 | .load = spartan2_load, |
| 452 | .dump = spartan2_dump, |
| 453 | .info = spartan2_info, |
| 454 | }; |