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