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