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